summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-08-30 11:06:15 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-08-30 11:06:15 -0400
commit6d1efe3c266e0990bcd114aa14935f31a00d56dd (patch)
tree35c8323c23e2b001572629bf4d9efab7b3983c85
parent12b93bd0d5ab6b66ba002af8b282d32c713254dd (diff)
js: Extract more rendering to functions.
* js/guix-packages.js (guix.view): Extract renderPackageTable and renderSearchBox functions.
-rw-r--r--js/guix-packages.js78
1 files changed, 43 insertions, 35 deletions
diff --git a/js/guix-packages.js b/js/guix-packages.js
index 024eb8c..437dca1 100644
--- a/js/guix-packages.js
+++ b/js/guix-packages.js
@@ -209,6 +209,35 @@ guix.view = function(ctrl) {
}, "install");
}
+ function renderPackageTable() {
+ return m("table.table", [
+ m("thead", [
+ m("tr", [
+ ctrl.columns.map(function(column) {
+ return m("th", {
+ class: columnHeaderClass(column),
+ onclick: function() {
+ ctrl.sortBy(column.sortField);
+ }
+ }, column.header);
+ }).concat([m("th", "")])
+ ])
+ ]),
+ m("tbody", [
+ ctrl.currentPage().map(function(package) {
+ return m("tr", [
+ m("td", renderName(package)),
+ m("td", package.version),
+ m("td", package.synopsis),
+ m("td", renderHomepage(package)),
+ m("td", renderLicense(package)),
+ m("td", renderInstallLink(package))
+ ]);
+ })
+ ])
+ ]);
+ }
+
function renderPagination() {
function renderPage(text, opts) {
return m("li", {
@@ -250,6 +279,18 @@ guix.view = function(ctrl) {
]));
}
+ function renderSearchBox() {
+ return m("input.form-control", {
+ type: "text",
+ placeholder: "Search",
+ onchange: m.withAttr("value", function(value) {
+ ctrl.searchTerm(value);
+ ctrl.doSearch();
+ }),
+ value: ctrl.searchTerm()
+ });
+ }
+
function columnHeaderClass(column) {
var sorter = ctrl.sorter();
@@ -353,41 +394,8 @@ guix.view = function(ctrl) {
m("span.badge", ctrl.packageCount())
]),
renderModal(),
- m("input.form-control", {
- type: "text",
- placeholder: "Search",
- onchange: m.withAttr("value", function(value) {
- ctrl.searchTerm(value);
- ctrl.doSearch();
- }),
- value: ctrl.searchTerm()
- }),
- m("table.table", [
- m("thead", [
- m("tr", [
- ctrl.columns.map(function(column) {
- return m("th", {
- class: columnHeaderClass(column),
- onclick: function() {
- ctrl.sortBy(column.sortField);
- }
- }, column.header);
- }).concat([m("th", "")])
- ])
- ]),
- m("tbody", [
- ctrl.currentPage().map(function(package) {
- return m("tr", [
- m("td", renderName(package)),
- m("td", package.version),
- m("td", package.synopsis),
- m("td", renderHomepage(package)),
- m("td", renderLicense(package)),
- m("td", renderInstallLink(package))
- ]);
- })
- ])
- ]),
+ renderSearchBox(),
+ renderPackageTable(),
renderPagination()
];
};