diff options
Diffstat (limited to 'assets/js/src/App.js')
-rw-r--r-- | assets/js/src/App.js | 198 |
1 files changed, 84 insertions, 114 deletions
diff --git a/assets/js/src/App.js b/assets/js/src/App.js index 4cc2c32c..62e091fc 100644 --- a/assets/js/src/App.js +++ b/assets/js/src/App.js @@ -1,75 +1,43 @@ -function App() { - this.board = new Board(this); - this.markdown = new Markdown(); - this.search = new Search(this); - this.swimlane = new Swimlane(this); - this.dropdown = new Dropdown(); - this.tooltip = new Tooltip(this); - this.popover = new Popover(this); - this.task = new Task(this); - this.project = new Project(); - this.subtask = new Subtask(this); - this.column = new Column(this); - this.file = new FileUpload(this); - this.accordion = new Accordion(this); - this.keyboardShortcuts(); - this.task.keyboardShortcuts(); - this.chosen(); - this.poll(); - - // Alert box fadeout - $(".alert-fade-out").delay(5000).fadeOut(800, function() { - $(this).remove(); - }); -} - -App.prototype.listen = function() { - this.project.listen(); - this.popover.listen(); - this.markdown.listen(); - this.tooltip.listen(); - this.dropdown.listen(); - this.search.listen(); - this.task.listen(); - this.swimlane.listen(); - this.subtask.listen(); - this.column.listen(); - this.file.listen(); - this.accordion.listen(); - this.search.focus(); - this.autoComplete(); - this.datePicker(); - this.focus(); +Kanboard.App = function() { + this.controllers = {}; }; -App.prototype.refresh = function() { - $(document).off(); - this.listen(); +Kanboard.App.prototype.get = function(controller) { + return this.controllers[controller]; }; -App.prototype.focus = function() { +Kanboard.App.prototype.execute = function() { + for (var className in Kanboard) { + if (className !== "App") { + var controller = new Kanboard[className](this); + this.controllers[className] = controller; - // Autofocus fields (html5 autofocus works only with page onload) - $("[autofocus]").each(function(index, element) { - $(this).focus(); - }) + if (typeof controller.execute === "function") { + controller.execute(); + } - // Auto-select input fields - $(document).on('focus', '.auto-select', function() { - $(this).select(); - }); + if (typeof controller.listen === "function") { + controller.listen(); + } - // Workaround for chrome - $(document).on('mouseup', '.auto-select', function(e) { - e.preventDefault(); - }); -}; + if (typeof controller.focus === "function") { + controller.focus(); + } -App.prototype.poll = function() { - window.setInterval(this.checkSession, 60000); + if (typeof controller.keyboardShortcuts === "function") { + controller.keyboardShortcuts(); + } + } + } + + this.focus(); + this.chosen(); + this.keyboardShortcuts(); + this.datePicker(); + this.autoComplete(); }; -App.prototype.keyboardShortcuts = function() { +Kanboard.App.prototype.keyboardShortcuts = function() { var self = this; // Submit form @@ -85,31 +53,50 @@ App.prototype.keyboardShortcuts = function() { // Close popover and dropdown Mousetrap.bindGlobal("esc", function() { - self.popover.close(); - self.dropdown.close(); + self.get("Popover").close(); + self.get("Dropdown").close(); }); // Show keyboard shortcut Mousetrap.bind("?", function() { - self.popover.open($("body").data("keyboard-shortcut-url")); + self.get("Popover").open($("body").data("keyboard-shortcut-url")); }); }; -App.prototype.checkSession = function() { - if (! $(".form-login").length) { - $.ajax({ - cache: false, - url: $("body").data("status-url"), - statusCode: { - 401: function() { - window.location = $("body").data("login-url"); - } - } +Kanboard.App.prototype.focus = function() { + // Auto-select input fields + $(document).on('focus', '.auto-select', function() { + $(this).select(); + }); + + // Workaround for chrome + $(document).on('mouseup', '.auto-select', function(e) { + e.preventDefault(); + }); +}; + +Kanboard.App.prototype.chosen = function() { + $(".chosen-select").each(function() { + var searchThreshold = $(this).data("search-threshold"); + + if (searchThreshold === undefined) { + searchThreshold = 10; + } + + $(this).chosen({ + width: "180px", + no_results_text: $(this).data("notfound"), + disable_search_threshold: searchThreshold }); - } + }); + + $(".select-auto-redirect").change(function() { + var regex = new RegExp($(this).data('redirect-regex'), 'g'); + window.location = $(this).data('redirect-url').replace(regex, $(this).val()); + }); }; -App.prototype.datePicker = function() { +Kanboard.App.prototype.datePicker = function() { // Datepicker translation $.datepicker.setDefaults($.datepicker.regional[$("body").data("js-lang")]); @@ -131,7 +118,7 @@ App.prototype.datePicker = function() { }); }; -App.prototype.autoComplete = function() { +Kanboard.App.prototype.autoComplete = function() { $(".autocomplete").each(function() { var input = $(this); var field = input.data("dst-field"); @@ -157,36 +144,33 @@ App.prototype.autoComplete = function() { }); }; -App.prototype.chosen = function() { - $(".chosen-select").each(function() { - var searchThreshold = $(this).data("search-threshold"); - - if (searchThreshold === undefined) { - searchThreshold = 10; - } - - $(this).chosen({ - width: "180px", - no_results_text: $(this).data("notfound"), - disable_search_threshold: searchThreshold - }); - }); - - $(".select-auto-redirect").change(function() { - var regex = new RegExp($(this).data('redirect-regex'), 'g'); - window.location = $(this).data('redirect-url').replace(regex, $(this).val()); - }); +Kanboard.App.prototype.hasId = function(id) { + return !!document.getElementById(id); }; -App.prototype.showLoadingIcon = function() { +Kanboard.App.prototype.showLoadingIcon = function() { $("body").append('<span id="app-loading-icon"> <i class="fa fa-spinner fa-spin"></i></span>'); }; -App.prototype.hideLoadingIcon = function() { +Kanboard.App.prototype.hideLoadingIcon = function() { $("#app-loading-icon").remove(); }; -App.prototype.isVisible = function() { +Kanboard.App.prototype.formatDuration = function(d) { + if (d >= 86400) { + return Math.round(d/86400) + "d"; + } + else if (d >= 3600) { + return Math.round(d/3600) + "h"; + } + else if (d >= 60) { + return Math.round(d/60) + "m"; + } + + return d + "s"; +}; + +Kanboard.App.prototype.isVisible = function() { var property = ""; if (typeof document.hidden !== "undefined") { @@ -205,17 +189,3 @@ App.prototype.isVisible = function() { return true; }; - -App.prototype.formatDuration = function(d) { - if (d >= 86400) { - return Math.round(d/86400) + "d"; - } - else if (d >= 3600) { - return Math.round(d/3600) + "h"; - } - else if (d >= 60) { - return Math.round(d/60) + "m"; - } - - return d + "s"; -}; |