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(options.popout));
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(popout) {
125 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="10" 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>';
127 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>';
133 table : function(classes, id) {
134 var $table = $(document.createElement('table'));
135 $table.addClass("table");
136 $(classes).each(function(index, value) {
137 $table.addClass(value);
139 if (!(typeof id === 'undefined'))
140 $table.attr("id", id);
143 header : function(headers) {
144 var $thead = $(document.createElement('thead'));
145 var $tr = $(document.createElement('tr'));
146 $(headers).each(function(index, value) {
147 $th = $(document.createElement('th'));
154 body : function(body, thead) {
155 var $tbody = $(document.createElement('tbody'));
157 if (body.length == 0 && !(typeof thead === 'undefined')) {
158 var $tr = $(document.createElement('tr'));
159 var $td = $(document.createElement('td'));
160 $td.attr('colspan', thead.length);
161 $td.text('No data available');
162 $td.addClass('empty');
167 // else, populate as usual
168 $(body).each(function(index, value) {
169 var $tr = $(document.createElement('tr'));
170 $.each(value, function(key, value) {
173 $(value).each(function(index, value) {
176 } else if (key == 'entry') {
178 $(value).each(function(index, value) {
179 var $td = $(document.createElement('td'));
185 $tr.attr('data-' + key, value);
193 description : function(description, horizontal) {
194 var $dl = $(document.createElement('dl'));
195 if (horizontal == true) {
196 $dl.addClass("dl-horizontal");
198 $(description).each(function(index, value) {
199 var $dt = $(document.createElement('dt'));
201 var $dd = $(document.createElement('dd'));
203 $dl.append($dt).append($dd);
211 // clone default modal
212 clone : function(id) {
213 var $clone = $("#modal").clone(true);
214 $clone.attr("id", id);
218 populate : function($modal, header, $body, footer) {
219 var $h3 = $modal.find("h3");
222 var $modalBody = $modal.find(".modal-body");
223 $modalBody.append($body);
225 $(footer).each(function(index, value) {
226 $modal.find(".modal-footer").append(value);
229 // clone and populate modal
230 spawn : function(id, header, $body, footer) {
231 var $modal = one.lib.modal.clone(id);
232 one.lib.modal.populate($modal, header, $body, footer);
236 empty : function($modal) {
237 $modal.find("h3").empty();
238 $modal.find(".modal-body").empty();
239 $modal.find(".modal-footer").empty();
243 body : function($modal, $body) {
244 $modal.find(".modal-body").empty();
245 $modal.find(".modal-body").append($body);
252 // create select-option form element
254 create : function(options, multiple) {
255 // assert - auto assign
256 if (options == undefined)
259 var $select = $(document.createElement('select'));
260 if (multiple == true) {
261 $select.attr("multiple", "multiple");
263 var optionArray = one.lib.form.select.options(options);
264 $(optionArray).each(function(index, value) {
265 $select.append(value);
269 options : function(options) {
271 $.each(options, function(key, value) {
272 var $option = $(document.createElement('option'));
273 $option.attr("value", key);
275 result.push($option);
279 empty : function($select) {
282 inject : function($select, options) {
284 var options = one.lib.form.select.options(options);
285 $select.append(options);
287 prepend : function($select, options) {
288 var options = one.lib.form.select.options(options);
289 $select.prepend(options);
291 bubble : function($select, bubble) {
292 $($select.find("option")).each(function(index, value) {
293 if ($(value).attr("value") == bubble) {
294 var option = $(value);
296 $select.prepend(option);
302 // create legend form element
303 legend : function(name) {
304 var $legend = $(document.createElement('legend'));
308 // create label form element
309 label : function(name) {
310 var $label = $(document.createElement('label'));
314 // create help block form element
315 help : function(help) {
316 var $help = $(document.createElement('span'));
318 $help.addClass("help-block");
321 // create generic text input
322 input : function(placeholder) {
323 var $input = $(document.createElement('input'));
324 $input.attr('type', 'text');
325 $input.attr('placeholder', placeholder);
332 unfocus : function($nav) {
333 $($nav.find("li")).each(function(index, value) {
334 $(value).removeClass("active");
340 one.lib.alert = function(alert) {
341 $("#alert p").text(alert);
343 $("#alert").slideToggle();
344 clearTimeout(one.lib.registry.alert);
345 one.lib.registry.alert = setTimeout(function() {
346 $("#alert").slideUp();