From 310e410dfc1916e19b3aca655bbfedc62db35216 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 7 Feb 2014 19:48:09 -0500 Subject: Improved TPS UI page loading. Previously the TPS UI would reload the JS libraries and CSS files every time a page is opened. The pages have been simplified such that it will only contain the necessary elements of the page. A new Page class has been added to the framework to define page initialization. Ticket #654 --- base/server/share/webapps/pki/js/pki-ui.js | 33 ++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'base/server/share/webapps') diff --git a/base/server/share/webapps/pki/js/pki-ui.js b/base/server/share/webapps/pki/js/pki-ui.js index c16af03ba..d35de5893 100644 --- a/base/server/share/webapps/pki/js/pki-ui.js +++ b/base/server/share/webapps/pki/js/pki-ui.js @@ -107,27 +107,52 @@ var Collection = Backbone.Collection.extend({ } }); +var Page = Backbone.View.extend({ + initialize: function(options) { + var self = this; + Page.__super__.initialize.call(self, options); + + self.url = options.url; + }, + load: function() { + } +}); + var Navigation = Backbone.View.extend({ initialize: function(options) { var self = this; Navigation.__super__.initialize.call(self, options); self.content = options.content; - self.homeURL = options.homeURL; + self.pages = options.pages; + self.homePage = options.homePage; $("li", self.$el).each(function(index) { var li = $(this); var link = $("a", li); var url = link.attr("href"); link.click(function(e) { - if (url != "#") { - self.content.load(url); + // get page name + if (url.charAt(0) == "#" && url.length > 1) { + var name = url.substring(1); + self.load(name); } e.preventDefault(); }); }); - if (self.homeURL) self.content.load(self.homeURL); + if (self.homePage) self.load(self.homePage); + }, + load: function(name) { + var self = this; + var page = self.pages[name]; + if (!page) { + alert("Invalid page: " + name); + return; + } + self.content.load(page.url, function(response, status, xhr) { + page.load(); + }); } }); -- cgit