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);
71 table : function(classes, id) {
72 var $table = $(document.createElement('table'));
73 $table.addClass("table");
74 $(classes).each(function(index, value) {
75 $table.addClass(value);
77 if (!(typeof id === 'undefined'))
78 $table.attr("id", id);
81 header : function(headers) {
82 var $thead = $(document.createElement('thead'));
83 var $tr = $(document.createElement('tr'));
84 $(headers).each(function(index, value) {
85 $th = $(document.createElement('th'));
92 body : function(body, thead) {
93 var $tbody = $(document.createElement('tbody'));
95 if (body.length == 0 && !(typeof thead === 'undefined')) {
96 var $tr = $(document.createElement('tr'));
97 var $td = $(document.createElement('td'));
98 $td.attr('colspan', thead.length);
99 $td.text('No data available');
100 $td.addClass('empty');
105 // else, populate as usual
106 $(body).each(function(index, value) {
107 var $tr = $(document.createElement('tr'));
108 $.each(value, function(key, value) {
111 $(value).each(function(index, value) {
114 } else if (key == 'entry') {
116 $(value).each(function(index, value) {
117 var $td = $(document.createElement('td'));
123 $tr.attr('data-' + key, value);
131 description : function(description, horizontal) {
132 var $dl = $(document.createElement('dl'));
133 if (horizontal == true) {
134 $dl.addClass("dl-horizontal");
136 $(description).each(function(index, value) {
137 var $dt = $(document.createElement('dt'));
139 var $dd = $(document.createElement('dd'));
141 $dl.append($dt).append($dd);
149 // clone default modal
150 clone : function(id) {
151 var $clone = $("#modal").clone(true);
152 $clone.attr("id", id);
156 populate : function($modal, header, $body, footer) {
157 var $h3 = $modal.find("h3");
160 var $modalBody = $modal.find(".modal-body");
161 $modalBody.append($body);
163 $(footer).each(function(index, value) {
164 $modal.find(".modal-footer").append(value);
167 // clone and populate modal
168 spawn : function(id, header, $body, footer) {
169 var $modal = one.lib.modal.clone(id);
170 one.lib.modal.populate($modal, header, $body, footer);
174 empty : function($modal) {
175 $modal.find("h3").empty();
176 $modal.find(".modal-body").empty();
177 $modal.find(".modal-footer").empty();
181 body : function($modal, $body) {
182 $modal.find(".modal-body").empty();
183 $modal.find(".modal-body").append($body);
190 // create select-option form element
192 create : function(options, multiple) {
193 // assert - auto assign
194 if (options == undefined)
197 var $select = $(document.createElement('select'));
198 if (multiple == true) {
199 $select.attr("multiple", "multiple");
201 var optionArray = one.lib.form.select.options(options);
202 $(optionArray).each(function(index, value) {
203 $select.append(value);
207 options : function(options) {
209 $.each(options, function(key, value) {
210 var $option = $(document.createElement('option'));
211 $option.attr("value", key);
213 result.push($option);
217 empty : function($select) {
220 inject : function($select, options) {
222 var options = one.lib.form.select.options(options);
223 $select.append(options);
225 prepend : function($select, options) {
226 var options = one.lib.form.select.options(options);
227 $select.prepend(options);
229 bubble : function($select, bubble) {
230 $($select.find("option")).each(function(index, value) {
231 if ($(value).attr("value") == bubble) {
232 var option = $(value);
234 $select.prepend(option);
240 // create legend form element
241 legend : function(name) {
242 var $legend = $(document.createElement('legend'));
246 // create label form element
247 label : function(name) {
248 var $label = $(document.createElement('label'));
252 // create help block form element
253 help : function(help) {
254 var $help = $(document.createElement('span'));
256 $help.addClass("help-block");
259 // create generic text input
260 input : function(placeholder) {
261 var $input = $(document.createElement('input'));
262 $input.attr('type', 'text');
263 $input.attr('placeholder', placeholder);
270 unfocus : function($nav) {
271 $($nav.find("li")).each(function(index, value) {
272 $(value).removeClass("active");
278 one.lib.alert = function(alert) {
279 $("#alert p").text(alert);
281 $("#alert").slideToggle();
282 clearTimeout(one.lib.registry.alert);
283 one.lib.registry.alert = setTimeout(function() {
284 $("#alert").slideUp();