]> source.dussan.org Git - archiva.git/commitdiff
load knockout grid binding as a require js module
authorOlivier Lamy <olamy@apache.org>
Mon, 26 Mar 2012 23:05:09 +0000 (23:05 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 26 Mar 2012 23:05:09 +0000 (23:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1305660 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/index.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/redback.js

index b7667532e70b69090d57f16e82ed022e94db55a6..f35bc74b02d973f94f8660f165054c04d9b1dfe6 100644 (file)
@@ -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",
index 9dfc039efab97650b08b6a50d0a7d35fe44b9fc9..b4e6ad894a4418191aaf02d7d56ebdf1b1c50f65 100644 (file)
@@ -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() {
 
   /**
index 68f7cfa30100bfd3c1de9c5dd446b4bc9143cc4e..ddcec4490dc43aebde6a81a95e0ee8c5b317d207 100644 (file)
@@ -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
index fb0370a8bda4b9814aa7d54e4cb4d6a785735143..c3b72f168c60ba74122047da6a49686813d2272e 100644 (file)
@@ -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};