From 2a276fd69dd171f89edafda234f4b3f50801a74f Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 26 Mar 2012 23:05:09 +0000 Subject: [PATCH] load knockout grid binding as a require js module git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1305660 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/webapp/index.html | 2 +- .../src/main/webapp/js/archiva/main.js | 3 +- .../src/main/webapp/js/knockout.simpleGrid.js | 102 +++++++++--------- .../src/main/webapp/js/redback/redback.js | 3 +- 4 files changed, 58 insertions(+), 52 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html index b7667532e..f35bc74b0 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html @@ -85,8 +85,8 @@ "choosen": "chosen.jquery-0.9.7", "jquery_validate": "jquery.validate-1.9.0", "jquery_json": "jquery.json-2.3.min", - "knockout.simpleGrid": "knockout.simpleGrid", "knockout": "knockout-2.0.0.debug", + "knockout.simpleGrid": "knockout.simpleGrid", "knockout.sortable": "knockout-sortable", "redback": "redback/redback", "general-admin":"archiva/general-admin", diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js index 9dfc039ef..b4e6ad894 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js @@ -18,7 +18,8 @@ */ define("main",["order!jquery","jquery_ui","jquery_cookie","bootstrap","order!archiva/search", "jquery_validate","jquery_json","order!knockout","order!redback-templates","order!main-templates","order!roles", - "order!redback","general-admin","repositories","network-proxies","proxy-connectors","repository-groups"], + "order!redback","general-admin","repositories","network-proxies","proxy-connectors","repository-groups", + "order!knockout.simpleGrid"], function() { /** diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js index 68f7cfa30..ddcec4490 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js @@ -9,64 +9,68 @@ // * Creating some API to fetch table data using Ajax requests // ... etc -(function () { +define("knockout.simpleGrid",["jquery","order!utils","i18n","order!knockout"], function() { + (function () { - ko.simpleGrid = { - // Defines a view model class you can use to populate a grid - viewModel: function (configuration) { - this.data = configuration.data; - this.currentPageIndex = ko.observable(0); - this.pageSize = configuration.pageSize || 5; - this.columns = configuration.columns; - this.itemsOnCurrentPage = ko.computed(function () { - var startIndex = this.pageSize * this.currentPageIndex(); - return this.data.slice(startIndex, startIndex + this.pageSize); - }, this); + ko.simpleGrid = { + // Defines a view model class you can use to populate a grid + viewModel: function (configuration) { + this.data = configuration.data; + this.currentPageIndex = ko.observable(0); + this.pageSize = configuration.pageSize || 5; + this.columns = configuration.columns; - this.maxPageIndex = ko.computed(function () { - return Math.ceil(ko.utils.unwrapObservable(this.data).length / this.pageSize); - }, this); - this.i18n=function(key){ - return $.i18n.prop(key); - }; - this.gridUpdateCallBack = configuration.gridUpdateCallBack; - this.pageLinksUpdateCallBack = configuration.pageLinksUpdateCallBack; - } - }; + this.itemsOnCurrentPage = ko.computed(function () { + var startIndex = this.pageSize * this.currentPageIndex(); + return this.data.slice(startIndex, startIndex + this.pageSize); + }, this); - // Templates used to render the grid - var templateEngine = new ko.jqueryTmplTemplateEngine(); + this.maxPageIndex = ko.computed(function () { + return Math.ceil(ko.utils.unwrapObservable(this.data).length / this.pageSize); + }, this); + this.i18n=function(key){ + return $.i18n.prop(key); + }; + this.gridUpdateCallBack = configuration.gridUpdateCallBack; + this.pageLinksUpdateCallBack = configuration.pageLinksUpdateCallBack; + } + }; + // Templates used to render the grid + var templateEngine = new ko.jqueryTmplTemplateEngine(); - // The "simpleGrid" binding - ko.bindingHandlers.simpleGrid = { - // This method is called to initialize the node, and will also be called again if you change what the grid is bound to - update: function (element, viewModelAccessor, allBindingsAccessor) { - var viewModel = viewModelAccessor(), allBindings = allBindingsAccessor(); - // Empty the element - while(element.firstChild) { - ko.removeNode(element.firstChild); - } + // The "simpleGrid" binding + ko.bindingHandlers.simpleGrid = { + // This method is called to initialize the node, and will also be called again if you change what the grid is bound to + update: function (element, viewModelAccessor, allBindingsAccessor) { + var viewModel = viewModelAccessor(), allBindings = allBindingsAccessor(); - // Allow the default templates to be overridden - var gridTemplateName = allBindings.simpleGridTemplate || "ko_usersGrid_grid", - pageLinksTemplateName = allBindings.simpleGridPagerTemplate || "ko_simpleGrid_pageLinks"; + // Empty the element + while(element.firstChild) { + ko.removeNode(element.firstChild); + } - // Render the main grid - var gridContainer = element.appendChild(document.createElement("DIV")); - ko.renderTemplate(gridTemplateName, viewModel, { templateEngine: templateEngine }, gridContainer, "replaceNode") - .subscribe(viewModel.gridUpdateCallBack?viewModel.gridUpdateCallBack:function(){}); + // Allow the default templates to be overridden + var gridTemplateName = allBindings.simpleGridTemplate || "ko_usersGrid_grid", + pageLinksTemplateName = allBindings.simpleGridPagerTemplate || "ko_simpleGrid_pageLinks"; - if (viewModel.gridUpdateCallBack) viewModel.gridUpdateCallBack(); + // Render the main grid + var gridContainer = element.appendChild(document.createElement("DIV")); + ko.renderTemplate(gridTemplateName, viewModel, { templateEngine: templateEngine }, gridContainer, "replaceNode") + .subscribe(viewModel.gridUpdateCallBack?viewModel.gridUpdateCallBack:function(){}); - // Render the page links - var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0); - ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode") - .subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){}); - if (viewModel.pageLinksUpdateCallBack) viewModel.pageLinksUpdateCallBack(); - } - }; -})(); \ No newline at end of file + if (viewModel.gridUpdateCallBack) viewModel.gridUpdateCallBack(); + + // Render the page links + var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0); + ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode") + .subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){}); + if (viewModel.pageLinksUpdateCallBack) viewModel.pageLinksUpdateCallBack(); + } + }; + })(); + +}) \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js index fb0370a8b..c3b72f168 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js @@ -16,7 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -define("redback",["jquery","order!utils","jquery_validate","jquery_json","roles","user","users"], function() { +define("redback",["jquery","order!utils","jquery_validate","jquery_json","order!knockout", + "order!knockout.simpleGrid","roles","user","users"], function() { // define a container object with various datas window.redbackModel = {userOperationNames:null,key:null,i18n:$.i18n.map}; -- 2.39.5