14 one.lib.registry = {};
18 empty : function($dashlet) {
21 append : function($dashlet, $content) {
22 $dashlet.append($content);
24 header : function(header) {
25 var $h4 = $(document.createElement('h4'));
29 list : function(list) {
30 var $ul = $(document.createElement('ul'));
31 $(list).each(function(index, value) {
32 var $li = $(document.createElement('li'));
39 config : function(name, id, type, size) {
41 button['name'] = name;
43 button['type'] = type;
44 button['size'] = size;
47 single : function(name, id, type, size) {
49 var button = one.lib.dashlet.button.config(name, id, type, size);
50 buttonList.push(button);
53 button : function(buttonList) {
54 var $buttonGroup = $(document.createElement('div'));
55 $buttonGroup.addClass("btn-group");
56 $(buttonList).each(function(index, value) {
57 var $button = $(document.createElement('button'));
58 $button.text(value.name);
59 $button.addClass('btn');
60 $button.addClass(value['type']);
61 $button.addClass(value['size']);
62 if (!(typeof value.id === 'undefined')) {
63 $button.attr('id', value.id);
65 $buttonGroup.append($button);
72 * The init function returns HTML markup for the datagrid per the options provided. Each consumer
73 * of the datagrid must first call init and then provide the datasource for the grid.
74 * id: this is the id of the table
76 * searchable: true/false,
77 * pagination: turned off for now,
78 * flexibleRowsPerPage: turned off
80 * classes : String containing bootstrap related classes. For ex: "table-striped table-condensed"
81 * The classes "table", "table-bordered" and "datagrid" will be added by default
83 init: function(id, options, classes) {
84 var $fuelGridContainerDiv = $(document.createElement("div"));
85 $fuelGridContainerDiv.addClass("fuelux");
86 $table = $(document.createElement("table"));
87 $table.attr("id", id);
88 $table.addClass("table table-bordered datagrid");
89 $table.addClass(classes);
90 // create datagrid header
91 $thead = $(document.createElement("thead"));
92 $headertr = $(document.createElement("tr"));
93 $headerth = $(document.createElement("th"));
94 // create datagrid footer
95 $tfoot = $(document.createElement("tfoot"));
96 $footertr = $(document.createElement("tr"));
97 $footerth = $(document.createElement("th"));
98 if(options.searchable == true) {
99 $headerth.append(one.lib.dashlet.datagrid._searchable());
101 if(options.flexibleRowsPerPage == true) {
102 $footerth.append(one.lib.dashlet.datagrid._rowsPerPage());
104 if(options.pagination == true) {
105 $footerth.append(one.lib.dashlet.datagrid._pagination());
107 $headertr.append($headerth);
108 $thead.append($headertr);
109 $footertr.append($footerth);
110 $tfoot.append($footertr);
111 $table.append($thead).append($tfoot);
112 $fuelGridContainerDiv.append($table);
113 return $fuelGridContainerDiv;
115 _searchable: function() {
116 var searchHTML = "<div class='datagrid-header-left'><div class='input-append search datagrid-search'> <input type='text' class='input-medium' placeholder='Search'><button type='button' class='btn'><i class='icon-search'></i></button></div></div>";
119 _pagination: function() {
120 var html = '<div class="datagrid-footer-right" style="display:none;"><div class="grid-pager"><button type="button" class="btn grid-prevpage"><i class="icon-chevron-left"></i></button><span>Page</span> <div style="display:inline-block;"><input type="text" name="pagenumber" style="width:25px;margin-bottom:-10px;vertical-align:middle;margin-right:5px;"></div><span>of <span class="grid-pages"></span></span><button type="button" class="btn grid-nextpage"><i class="icon-chevron-right"></i></button></div></div>';
123 _rowsPerPage: function() {
124 var html = '<div class="datagrid-footer-left" style="display:none;"><div class="grid-controls"><span><span class="grid-start"></span>-<span class="grid-end"></span> of <span class="grid-count"></span></span><div class="select grid-pagesize" data-resize="auto" style="visibility:hidden;"><button type="button" data-toggle="dropdown" class="btn dropdown-toggle"><span class="dropdown-label"></span><span class="caret"></span></button><ul class="dropdown-menu"><li data-value="5" data-selected="true"><a href="#">5</a></li><li data-value="10"><a href="#">10</a></li><li data-value="20"><a href="#">20</a></li><li data-value="50"><a href="#">50</a></li><li data-value="100"><a href="#">100</a></li></ul></div><span style="display:none;">Per Page</span></div></div>';
129 table : function(classes, id) {
130 var $table = $(document.createElement('table'));
131 $table.addClass("table");
132 $(classes).each(function(index, value) {
133 $table.addClass(value);
135 if (!(typeof id === 'undefined'))
136 $table.attr("id", id);
139 header : function(headers) {
140 var $thead = $(document.createElement('thead'));
141 var $tr = $(document.createElement('tr'));
142 $(headers).each(function(index, value) {
143 $th = $(document.createElement('th'));
150 body : function(body, thead) {
151 var $tbody = $(document.createElement('tbody'));
153 if (body.length == 0 && !(typeof thead === 'undefined')) {
154 var $tr = $(document.createElement('tr'));
155 var $td = $(document.createElement('td'));
156 $td.attr('colspan', thead.length);
157 $td.text('No data available');
158 $td.addClass('empty');
163 // else, populate as usual
164 $(body).each(function(index, value) {
165 var $tr = $(document.createElement('tr'));
166 $.each(value, function(key, value) {
169 $(value).each(function(index, value) {
172 } else if (key == 'entry') {
174 $(value).each(function(index, value) {
175 var $td = $(document.createElement('td'));
181 $tr.attr('data-' + key, value);
189 description : function(description, horizontal) {
190 var $dl = $(document.createElement('dl'));
191 if (horizontal == true) {
192 $dl.addClass("dl-horizontal");
194 $(description).each(function(index, value) {
195 var $dt = $(document.createElement('dt'));
197 var $dd = $(document.createElement('dd'));
199 $dl.append($dt).append($dd);
207 // clone default modal
208 clone : function(id) {
209 var $clone = $("#modal").clone(true);
210 $clone.attr("id", id);
214 populate : function($modal, header, $body, footer) {
215 var $h3 = $modal.find("h3");
218 var $modalBody = $modal.find(".modal-body");
219 $modalBody.append($body);
221 $(footer).each(function(index, value) {
222 $modal.find(".modal-footer").append(value);
225 // clone and populate modal
226 spawn : function(id, header, $body, footer) {
227 var $modal = one.lib.modal.clone(id);
228 one.lib.modal.populate($modal, header, $body, footer);
232 empty : function($modal) {
233 $modal.find("h3").empty();
234 $modal.find(".modal-body").empty();
235 $modal.find(".modal-footer").empty();
239 body : function($modal, $body) {
240 $modal.find(".modal-body").empty();
241 $modal.find(".modal-body").append($body);
248 // create select-option form element
250 create : function(options, multiple) {
251 // assert - auto assign
252 if (options == undefined)
255 var $select = $(document.createElement('select'));
256 if (multiple == true) {
257 $select.attr("multiple", "multiple");
259 var optionArray = one.lib.form.select.options(options);
260 $(optionArray).each(function(index, value) {
261 $select.append(value);
265 options : function(options) {
267 $.each(options, function(key, value) {
268 var $option = $(document.createElement('option'));
269 $option.attr("value", key);
271 result.push($option);
275 empty : function($select) {
278 inject : function($select, options) {
280 var options = one.lib.form.select.options(options);
281 $select.append(options);
283 prepend : function($select, options) {
284 var options = one.lib.form.select.options(options);
285 $select.prepend(options);
287 bubble : function($select, bubble) {
288 $($select.find("option")).each(function(index, value) {
289 if ($(value).attr("value") == bubble) {
290 var option = $(value);
292 $select.prepend(option);
298 // create legend form element
299 legend : function(name) {
300 var $legend = $(document.createElement('legend'));
304 // create label form element
305 label : function(name) {
306 var $label = $(document.createElement('label'));
310 // create help block form element
311 help : function(help) {
312 var $help = $(document.createElement('span'));
314 $help.addClass("help-block");
317 // create generic text input
318 input : function(placeholder) {
319 var $input = $(document.createElement('input'));
320 $input.attr('type', 'text');
321 $input.attr('placeholder', placeholder);
328 unfocus : function($nav) {
329 $($nav.find("li")).each(function(index, value) {
330 $(value).removeClass("active");
336 one.lib.alert = function(alert) {
337 $("#alert p").text(alert);
339 $("#alert").slideToggle();
340 clearTimeout(one.lib.registry.alert);
341 one.lib.registry.alert = setTimeout(function() {
342 $("#alert").slideUp();