]> source.dussan.org Git - archiva.git/commitdiff
add a mechanism in knockout simpleGrid binding to add callback subscribe on values...
authorOlivier Lamy <olamy@apache.org>
Wed, 18 Jan 2012 23:29:49 +0000 (23:29 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 18 Jan 2012 23:29:49 +0000 (23:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1233120 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/repositories.html
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout-debug.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js

index 0b90ed946826ac8e896a2ce275042fd457aa621e..54375c32e764c20d4ef5e60e8d94e0bb7a6b92a8 100644 (file)
@@ -299,13 +299,16 @@ $(function() {
               title: "Repository type (default is Maven 2)"
               }
             ],
-            pageSize: 5
+            pageSize: 5,
+            gridUpdateCallBack: function(){
+              $.log("gridUpdateCallBack");
+              $("#main-content #managed-repositories-table [title]").twipsy();
+            }
           });
           ko.applyBindings(managedRepositoriesViewModel,$("#main-content #managed-repositories-table").get(0));
           $("#main-content #managed-repositories-pills").pills();
           $("#managed-repositories-view").addClass("active");
           removeMediumSpinnerImg("#main-content #managed-repositories-content");
-          $("#main-content #managed-repositories-table [title]").twipsy();
           activateManagedRepositoriesGridTab();
         }
       }
index 2eef3caff46835a17c1fc8d223cb051493857fb2..427efee05d88c6415efe5679649d3504e38d24d6 100644 (file)
             <div id="managed-repositories-tabs-content" class="pill-content">
               <div id="managed-repositories-view" class="active">
                   <table class="bordered-table zebra-striped" id="managed-repositories-table"
-                         data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko_managed-repositoriesGrid',pageLinksId:'managed-repositoriesPagination'">
+                         data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko_managed-repositoriesGrid',pageLinksId:'managed-repositoriesPagination',data:'managedRepositories'">
                   </table>
                   <div id="managed-repositoriesPagination"></div>
               </div>
               <div id="managed-repository-edit" data-bind='template: {name:"managed-repository-edit-tmpl"}'>
-
               </div>
             </div>
        </div>
index 49d2a63844c46f530b69d0aa58b2f34bf59ef0a0..781bf43840fea29283817af4a38c10d42aeb12bb 100644 (file)
@@ -2743,6 +2743,7 @@ ko.exportSymbol('templateRewriting.applyMemoizedBindingsToNextSibling', ko.templ
     }\r
 \r
     function executeTemplate(targetNodeOrNodeArray, renderMode, template, bindingContext, options) {\r
+\r
         options = options || {};\r
         var templateEngineToUse = (options['templateEngine'] || _templateEngine);\r
         ko.templateRewriting.ensureTemplateIsRewritten(template, templateEngineToUse);\r
@@ -2797,7 +2798,6 @@ ko.exportSymbol('templateRewriting.applyMemoizedBindingsToNextSibling', ko.templ
 \r
                     // Support selecting template as a function of the data being rendered\r
                     var templateName = typeof(template) == 'function' ? template(bindingContext['$data']) : template; \r
-\r
                     var renderedNodesArray = executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options);\r
                     if (renderMode == "replaceNode") {\r
                         targetNodeOrNodeArray = renderedNodesArray;\r
index a86f7d8b6e305aff98263d2ebd6ae7e740eafded..02815f7312888210f84b451a9f42622bf5a71e9a 100644 (file)
@@ -15,7 +15,7 @@
     ko.simpleGrid = {
       // Defines a view model class you can use to populate a grid
       viewModel: function (configuration) {
-        this.data = configuration.data;
+        this.data = ko.observableArray(configuration.data);
         this.currentPageIndex = ko.observable(0);
         this.pageSize = configuration.pageSize || 5;
         this.columns = configuration.columns;
@@ -31,6 +31,8 @@
         this.i18n=function(key){
           return $.i18n.prop(key);
         };
+        this.gridUpdateCallBack = configuration.gridUpdateCallBack;
+        this.pageLinksUpdateCallBack = configuration.pageLinksUpdateCallBack;
       }
     };
 
 
           // Render the main grid
           var gridContainer = element.appendChild(document.createElement("DIV"));
-          ko.renderTemplate(gridTemplateName, viewModel, { templateEngine: templateEngine }, gridContainer, "replaceNode");
+          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");
+          ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode")
+              .subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){});
         }
     };
 })();
\ No newline at end of file