add a mechanism in knockout simpleGrid binding to add callback subscribe on values change

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1233120 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-01-18 23:29:49 +00:00
parent 7852bfcf1d
commit a4d3620a65
4 changed files with 14 additions and 8 deletions

View File

@ -299,13 +299,16 @@ $(function() {
title: "Repository type (default is Maven 2)" 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)); ko.applyBindings(managedRepositoriesViewModel,$("#main-content #managed-repositories-table").get(0));
$("#main-content #managed-repositories-pills").pills(); $("#main-content #managed-repositories-pills").pills();
$("#managed-repositories-view").addClass("active"); $("#managed-repositories-view").addClass("active");
removeMediumSpinnerImg("#main-content #managed-repositories-content"); removeMediumSpinnerImg("#main-content #managed-repositories-content");
$("#main-content #managed-repositories-table [title]").twipsy();
activateManagedRepositoriesGridTab(); activateManagedRepositoriesGridTab();
} }
} }

View File

@ -42,12 +42,11 @@
<div id="managed-repositories-tabs-content" class="pill-content"> <div id="managed-repositories-tabs-content" class="pill-content">
<div id="managed-repositories-view" class="active"> <div id="managed-repositories-view" class="active">
<table class="bordered-table zebra-striped" id="managed-repositories-table" <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> </table>
<div id="managed-repositoriesPagination"></div> <div id="managed-repositoriesPagination"></div>
</div> </div>
<div id="managed-repository-edit" data-bind='template: {name:"managed-repository-edit-tmpl"}'> <div id="managed-repository-edit" data-bind='template: {name:"managed-repository-edit-tmpl"}'>
</div> </div>
</div> </div>
</div> </div>

View File

@ -2743,6 +2743,7 @@ ko.exportSymbol('templateRewriting.applyMemoizedBindingsToNextSibling', ko.templ
} }
function executeTemplate(targetNodeOrNodeArray, renderMode, template, bindingContext, options) { function executeTemplate(targetNodeOrNodeArray, renderMode, template, bindingContext, options) {
options = options || {}; options = options || {};
var templateEngineToUse = (options['templateEngine'] || _templateEngine); var templateEngineToUse = (options['templateEngine'] || _templateEngine);
ko.templateRewriting.ensureTemplateIsRewritten(template, templateEngineToUse); ko.templateRewriting.ensureTemplateIsRewritten(template, templateEngineToUse);
@ -2797,7 +2798,6 @@ ko.exportSymbol('templateRewriting.applyMemoizedBindingsToNextSibling', ko.templ
// Support selecting template as a function of the data being rendered // Support selecting template as a function of the data being rendered
var templateName = typeof(template) == 'function' ? template(bindingContext['$data']) : template; var templateName = typeof(template) == 'function' ? template(bindingContext['$data']) : template;
var renderedNodesArray = executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options); var renderedNodesArray = executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options);
if (renderMode == "replaceNode") { if (renderMode == "replaceNode") {
targetNodeOrNodeArray = renderedNodesArray; targetNodeOrNodeArray = renderedNodesArray;

View File

@ -15,7 +15,7 @@
ko.simpleGrid = { ko.simpleGrid = {
// Defines a view model class you can use to populate a grid // Defines a view model class you can use to populate a grid
viewModel: function (configuration) { viewModel: function (configuration) {
this.data = configuration.data; this.data = ko.observableArray(configuration.data);
this.currentPageIndex = ko.observable(0); this.currentPageIndex = ko.observable(0);
this.pageSize = configuration.pageSize || 5; this.pageSize = configuration.pageSize || 5;
this.columns = configuration.columns; this.columns = configuration.columns;
@ -31,6 +31,8 @@
this.i18n=function(key){ this.i18n=function(key){
return $.i18n.prop(key); return $.i18n.prop(key);
}; };
this.gridUpdateCallBack = configuration.gridUpdateCallBack;
this.pageLinksUpdateCallBack = configuration.pageLinksUpdateCallBack;
} }
}; };
@ -54,11 +56,13 @@
// Render the main grid // Render the main grid
var gridContainer = element.appendChild(document.createElement("DIV")); 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 // Render the page links
var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0); 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(){});
} }
}; };
})(); })();