admin/js/components/widgets.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
(function(){ 'use strict'; var app = window.LS || (window.LS = {}); app.widgets = {}; /* PANEL */ app.widgets.panel = { view: function(ctrl, args){ var title = ""; var footer = ""; if (args.title){ title = m(".panel-heading", [ m("h2.panel-title", [args.title]) ]); } if (args.footer){ footer = m(".panel-footer", args.footer); } return m(".panel.panel-default", [ title, m(".panel-body", [ args.content ]), footer ]); } }; /* PAGINATOR */ app.widgets.paginator = { view: function(ctrl, args){ var max_page = Math.min(14, Math.ceil(args.total/args.limit)-1); var c_page = Math.ceil(args.offset/args.limit); var page = function(n, sign, disabled){ var klass; if (disabled) { klass = "disabled"; } else { klass = (n === c_page) ? "active" : "inactive"; } var first = (n === 0); var last = (n == max_page); var offset = args.limit * n; sign = sign || n+1; return m("li", {class: klass}, [m("a", { href: args.baseurl +(n+1), // assuming 10 elements per page //+"/"+obj.limit, config: m.route }, [m.trust(sign)] )] ); }; var pages = []; var prev; var next; for (var i=0; i<=max_page; i++){ var p; switch(i){ case c_page-1: prev = page(i, "«"); break; case c_page+1: next = page(i, "»"); break; } if (c_page === 0){ prev = page(0, "«", true); } if (c_page === max_page){ next = page(max_page, "»", true); } pages.push(page(i)); } pages.unshift(prev); pages.push(next); return m("nav", [m("ul.pagination", pages)]); } }; /* DROPDOWN */ app.widgets.dropdown = { view: function(ctrl, args){ var el = "li.dropdown"; var icon = (args.icon) ? m("i.fa."+args.icon) : ""; if (args.active.length > 0) { el += "."+args.active; } return m(el, [ m("a.dropdown-toggle[href='#'][data-toggle='dropdown'][role='button'][aria-expanded='false']", [icon, m("span", " "+args.title+" "), m("span.caret")]), m("ul.dropdown-menu[role='menu']", args.links.map(function(e){ return m("li", [m("a", {href: e.path, config: m.route}, m.trust(e.title))]);})) ]); } }; /* DROPDOWN */ app.widgets.taglink = { view: function(ctrl, args) { var color = /^\$/.test(args.name) ? "warning" : "primary" return m("span.tag-label.label.label-"+color, [m("i.fa.fa-tag"), " ", m("a", {href: "/tags/"+args.name, config:m.route}, args.name)]); } }; /* DOCLINK */ app.widgets.doclink = { view: function(ctrl, args) { return m("a", {href: "/document/view/"+args.id, config: m.route}, id); } }; /* TAGBUTTON */ app.widgets.tagbutton = { view: function(ctrl, args) { return m("a", {href: "/tags/"+args.name, config:m.route}, [m("i.fa.fa-tag"), " "+args.name+" ", m("span.badge", args.n)]); } }; /* TOOLBAR */ app.widgets.toolbar = { view: function(ctrl, args){ return m("nav.toolbar.btn-group[role='group'][aria-label='...'].pull-right", args.links.map(function(l){ return m("a.btn.btn-default", {onclick:l.action, config: l.config}, [m("i.fa.fa-"+l.icon), " "+l.title]); }) ); } }; /* MODAL */ app.widgets.modal = { view: function(ctrl, args){ return m(".modal.fade", {id: args.id, tabindex: "-1", role: "dialog"}, [ m(".modal-dialog", [ m(".modal-content", [ m(".modal-header", [ m("button", {type: "button", class: "close", "data-dismiss": "modal"}, [m.trust("×")]), m("h4.modal-title", args.title) ]), m(".modal-body", [args.content]), m(".modal-footer", [ m("button.btn.btn-default[data-dismiss='modal']", "Close"), m("button.btn.btn-primary[data-dismiss='modal']", {onclick: args.action}, args.actionText) ]) ]) ]) ] ); } }; }()); |