From: Jason Skomorowski Date: Fri, 8 Aug 2014 16:16:40 +0000 (-0400) Subject: Template Ranking widget. X-Git-Tag: 1.0.0~324^2~40 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=131b209f651be944c64a7a419ba720d30273364d;p=mkws-moved-to-github.git Template Ranking widget. --- diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index be2f588..2988550 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -215,90 +215,43 @@ mkws.registerWidgetType('SearchForm', function() { mkws.registerWidgetType('Results', function() { - var tname = this.team.name(); - - this.node.html('\ -\ - \ - \ - \ - \ - \ - \ - \ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ -
'); - + var template = this.team.loadTemplate(this.config.template || "Results"); + this.node.html(template({team: this.team.name()})); this.autosearch(); }); mkws.registerWidgetType('Ranking', function() { - var tname = this.team.name(); - var that = this; - var M = mkws.M; - - var s = '
'; - if (this.config.show_sort) { - s += M('Sort by') + ' ' + mkwsHtmlSort() + ' '; - } - if (this.config.show_perpage) { - s += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.'; + var output = {}; + output.perPage = []; + output.sort = []; + output.team = this.team.name(); + output.showSort = this.config.show_sort; + output.showPerPage = this.config.show_perpage; + + var order = this.team.sortOrder(); + this.log("making sort, sortOrder = '" + order + "'"); + for (var i = 0; i < this.config.sort_options.length; i++) { + var cur = {}; + var opt = this.config.sort_options[i]; + cur.key = opt[0]; + cur.label = opt.length == 1 ? opt[0] : opt[1]; + if (order == cur.key || order == cur.label) cur.selected = true; + output.sort.push(cur); } - s += '
'; - - this.node.html(s); - - - function mkwsHtmlSort() { - var order = that.team.sortOrder(); - that.log("making sort HTML, sortOrder = '" + order + "'"); - var sort_html = ''; - - return sort_html; + var perpage = this.team.perpage(); + this.log("making perpage, perpage = " + perpage); + for(var i = 0; i < this.config.perpage_options.length; i++) { + var cur = {}; + cur.perPage = this.config.perpage_options[i]; + if (cur.perPage == perpage) cur.selected = true; + output.perPage.push(cur); } - function mkwsHtmlPerpage() { - var perpage = that.team.perpage(); - - that.log("making perpage HTML, perpage = " + perpage); - var perpage_html = ''; - - return perpage_html; - } + var template = this.team.loadTemplate(this.config.template || "Ranking"); + console.log(output); + this.node.html(template(output)); }); diff --git a/src/mkws-widget-main.templates/Ranking.handlebars b/src/mkws-widget-main.templates/Ranking.handlebars new file mode 100644 index 0000000..0f2bc17 --- /dev/null +++ b/src/mkws-widget-main.templates/Ranking.handlebars @@ -0,0 +1,42 @@ +{{! +Ranking -- widget to select sort ordering and number of records to display + +team - team for this widget +showSort +showPerPage +sort + key - machine readable value for this sort option + label - text to display for this sort option + selected - exists if this sort is selected +perPage + perPage - a number of records per page that can be selected + selected - exists if this number is the current selection +}} +
+ {{~#if showSort~}} + {{{mkws-translate "Sort by"}}} + + {{~/if~}} + {{~#if showPerPage~}} + {{{mkws-translate "and show"}}} + + {{{mkws-translate "per page."}}} + {{~/if~}} +
+