1 var updateAutoData = {};
2 var refreshAutoData = {};
3 var lastUpdatedId = false;
4 var postUpdateAction = [];
5 var postRefreshAction = [];
6 var postCollectAction = [];
7 var searchHandler = {};
13 function hasPlaceholderSupport() {
14 var input = document.createElement('input');
15 return ('placeholder' in input);
18 function generalNotice(header,body)
20 $('#modalGeneralNotice h3').html(header);
21 $('#modalGeneralNotice .modal-body').html(body);
22 $('#modalGeneralNotice').modal('show');
25 $('input:text,input:password,textarea').focus(function (){
26 if (!hasPlaceholderSupport())
29 if ($(this).hasClass('datepicker'))
32 $(this).datepicker('remove');
42 $('input:text,input:password,textarea').blur(function (){
43 if (!hasPlaceholderSupport() && $(this).val() == '')
46 text = $(this).attr('placeholder');
47 if ($(this).hasClass('datepicker'))
50 $(this).datepicker('remove');
63 $(document).ready(function() {
65 if (!hasPlaceholderSupport())
67 $('input:text,input:password,textarea').each(function () {
69 text = $(this).attr('placeholder');
70 if ($(this).hasClass('datepicker'))
73 $(this).datepicker('remove');
85 $('.nav-vertical .nav-list:odd:not(:first)').slideToggle();
86 $('.nav-vertical .nav-header > span > i').toggleClass('icon-circle-arrow-down');
87 $('.nav-vertical .nav-list:even').click(function () {
88 $(this).next().slideToggle();
89 $(this).find("i").toggleClass('icon-circle-arrow-down');
91 //$("input:checkbox, input:radio").uniform();
92 $("[rel=tooltip]").tooltip({
97 $(".popover").popover();
98 $(".datepicker").datepicker({
99 dateFormat: 'yy-mm-dd'
101 setInterval('updateClock()', 1000);
102 jQuery.validator.messages.required = "";
103 jQuery.validator.messages.email = "";
106 $("#deleteForm").submit(function () {
107 $("[rel=tooltip]").tooltip('hide');
109 $('#delete_namespace').val(),
110 $('#delete_remove_action').val(),
111 $('#delete_refresh_container').val(),
112 $('#delete_refresh_action').val(),
117 function loadPage(page, options) {
118 $("[rel=tooltip]").tooltip('hide');
119 $('#adminMainContent').fadeTo(300, 0.5);
120 $('#adminMainContent').load(
121 '/admin/' + page, options,
123 $('#adminMainContent').fadeTo(200, 1);
124 $("[rel=tooltip]").tooltip({
129 $(".popover").popover();
130 $(".datepicker").datepicker({
131 dateFormat: 'yy-mm-dd'
136 function pagerPage(section, action, pagenum) {
137 $("[rel=tooltip]").tooltip('hide');
138 $('#' + section).fadeTo(300, 0.5);
139 $('#' + section).load(
140 '/' + theme + '/' + action,
145 $('#' + section).fadeTo(200, 1);
149 function pagerRecords(section, action, numrecords) {
150 $("[rel=tooltip]").tooltip('hide');
151 $('#' + section).fadeTo(300, 0.5);
152 $('#' + section).load(
153 '/' + theme + '/' + action,
155 pg_records: numrecords,
159 $('#' + section).fadeTo(200, 1);
163 function search(namespace) {
164 prepend = namespace.replace('-', '_') + '_';
165 meta = searchHandler[namespace];
166 $("[rel=tooltip]").tooltip('hide');
167 $('#' + meta['container']).fadeTo(300, 0.5);
170 inputs = $('input.' + namespace + ', select.' + namespace).toArray();
171 for (index in inputs) {
172 item = inputs[index];
173 if ($(item).attr('name') != undefined) {
174 value = $(item).val();
176 name = $(item).attr('name');
177 name = name.replace(prepend, '');
182 refreshContent(meta['container'], meta['action'], false, false, {
188 function order(namespace, field, direction) {
189 meta = searchHandler['srch-' + namespace];
190 $("[rel=tooltip]").tooltip('hide');
191 $('#' + meta['container']).fadeTo(300, 0.5);
193 data[field] = direction;
194 refreshContent(meta['container'], meta['action'], false, false, {
200 function flagItem(field, id, label, refreshContainer, refreshAction) {
201 $("[rel=tooltip]").tooltip('hide');
202 $('#' + refreshContainer).fadeTo(300, 0.5);
205 url: '/util/utility/set-data-flag',
211 success: function(data, textStatus, jqXHR) {
212 $('#' + refreshContainer).fadeTo(300, 1);
214 response = typeof(data)=='string'
218 alert('Could not flag data entry!');
220 refreshContent(refreshContainer, refreshAction);
222 error: function(jqXHR, textStatus, errorThrown) {
223 $('#' + refreshContainer).fadeTo(300, 1);
224 alert('Oops: Could not flag data entry!');
230 function collectData(dataAction, requestData) {
231 $("[rel=tooltip]").tooltip('hide');
237 url: '/' + dataAction,
239 success: function(data, textStatus, jqXHR) {
241 response = typeof(data)=='string'
245 alert('Oops, incorrect data format received from the server!');
247 while (postCollectAction.length) {
248 (postCollectAction.shift())(response['Data']);
252 error: function(jqXHR, textStatus, errorThrown) {
253 alert('Oops: ' + errorThrown);
259 function refreshContent(section, action, titleId, title, data) {
260 $("[rel=tooltip]").tooltip('hide');
261 $('#' + section).fadeTo(300, 0.5);
265 $('#' + section).load(
269 $('#' + section).fadeTo(200, 1);
270 while (postRefreshAction.length) {
271 (postRefreshAction.shift())();
275 $('#' + titleId).html(title);
279 function clearForm(namespace, modalElement) {
280 $("[rel=tooltip]").tooltip('hide');
281 $("[form-id=" + namespace + "]").each(function() {
283 if ($(this).is(':checkbox')) {
284 $(this).prop("checked", false);
285 } else if ($(this).is('textarea')) {
287 $('.wysihtml5-sandbox').contents().find('body').html('');
288 } else if ($(this).hasClass('data-dependant-chain') || $(this).hasClass('data-dependant-child')) {
289 meta = $(this).metadata({
293 meta = $('#' + meta['parent']).metadata({
297 $(this).html('<option value="">--- Select ' + meta['title'] + ' ---</option>');
304 $('#' + modalElement).modal('toggle');
309 function populateForm(namespace, context, dataItem, modalElement) {
311 $("[rel=tooltip]").tooltip('hide');
313 $('[id^=' + namespace + '_]').each(function (){
314 field = $(this).attr('id');
315 field = field.replace(namespace + '_', '');
318 if (typeof(dataItem[field]) == "undefined")
320 bits = field.split("_");
321 sub = bits[bits.length-1];
322 bits = bits.splice(0, bits.length-1);
323 dataValue = (dataItem[bits.join('_')])
324 ? dataItem[bits.join('_')][sub]
329 dataValue = dataItem[field];
331 if (typeof(dataValue) != "undefined")
333 if (element.is(':checkbox')) {
334 if ('1' == dataValue) {
335 element.prop("checked", true);
337 element.prop("checked", false);
339 } else if (element.is('textarea')) {
340 element.val(dataValue);
341 $('.wysihtml5-sandbox').contents().find('body').html(dataValue);
342 } else if (element.hasClass('data-dependant-chain') || element.hasClass('data-dependant-child')) {
343 meta = element.metadata({
347 parentDataField = context + '_' + meta['parent'].replace(namespace + '_', '')
348 meta = $('#' + meta['parent']).metadata({
353 '/' + theme + '/' + 'list-dependancy-select',
357 field:meta['filterField'],
358 value:dataItem[parentDataField],
364 element.val(dataValue);
370 $('#' + modalElement).modal('toggle');
375 function collectFormData(selector) {
377 $(selector).each(function() {
379 shortname = this.name;
380 if ($(this).is(':checkbox'))
382 values[$(this).val()] = $(this).is(':checked') ? 1 : 0;
384 else if ($(this).is(':radio'))
386 values[shortname] = $('input[name=' + this.name + ']:checked').val();
390 values[shortname] = $(this).val();
398 function doUpdate(namespace, datanamespace, updateAction, refreshContainer, refreshAction,
399 warningContainer, closeOnSave, redirect, addon) {
400 $("[rel='tooltip']").tooltip('hide');
401 if (refreshContainer) {
402 $('#' + refreshContainer).fadeTo(300, 0.5);
404 $('.btn-save').button('loading');
407 values = collectFormData("[form-id='" + namespace + "']");
410 for (index in addon) {
411 values[index] = addon[index];
414 if (updateAutoData[updateAction]) {
415 for (index in updateAutoData[updateAction]) {
416 values[index] = updateAutoData[updateAction][index];
421 postData[datanamespace] = values;
423 var postData = values;
427 url: '/' + updateAction,
429 success: function(data, textStatus, jqXHR) {
431 if ('Success' == response['Status']) {
432 if ('RecordId' in response) {
433 lastUpdatedId = response['RecordId'];
435 lastUpdatedId = false;
437 if (warningContainer) {
439 warningContainer.element,
440 (warningContainer.placement) ? warningContainer.placement : "right",
441 (warningContainer.title) ? warningContainer.title : "Oops",
443 (warningContainer.length) ? warningContainer.length : 3000
447 if ((refreshContainer) && (refreshAction)) {
448 if (refreshAutoData[refreshContainer]) {
449 refreshContent(refreshContainer, refreshAction, false, false, refreshAutoData[refreshContainer]);
451 refreshContent(refreshContainer, refreshAction);
455 if ('boolean' == typeof(closeOnSave)) {
456 modalElement = '#modal' + ucfirst(namespace);
458 modalElement = '#' + closeOnSave;
460 $(modalElement).modal('toggle');
462 while (postUpdateAction.length) {
463 (postUpdateAction.shift())(response);
466 $('.btn-save').button('complete');
467 window.location = redirect;
469 } else if ('Error' == response['Status']) {
470 if (refreshContainer) {
471 $('#' + refreshContainer).fadeTo(300, 1.0);
473 if (warningContainer) {
475 warningContainer.element,
476 (warningContainer.placement) ? warningContainer.placement : "right",
477 (warningContainer.title) ? warningContainer.title : "Oops",
479 (warningContainer.length) ? warningContainer.length : 3000
482 alert('Service Error: ' + response['Message']);
487 $('.btn-save').button('complete');
490 error: function(jqXHR, textStatus, errorThrown) {
491 if (refreshContainer) {
492 $('#' + refreshContainer).fadeTo(300, 1.0);
494 $('.btn-save').button('complete');
495 alert('Oops: ' + errorThrown);
501 function confirmDelete(namespace, removeAction, id, refreshContainer, refreshAction) {
502 $('#delete_id').val(id);
503 $('#delete_namespace').val(namespace);
504 $('#delete_remove_action').val(removeAction);
505 $('#delete_refresh_container').val(refreshContainer);
506 $('#delete_refresh_action').val(refreshAction);
507 $('#modalDelete').modal('toggle');
510 function flashPopover(element, placement, title, content, length) {
511 $('#' + element).popover({
512 "placement": placement,
517 $('#btnLogin').popover('show');
521 setTimeout(function () {
522 $('#' + element).popover('hide');
527 * Function wrapping code.
528 * fn - reference to function.
529 * context - what you want "this" to be.
530 * params - array of parameters to pass to function.
532 * var sayStuff = function(str) { alert(str); };
533 * var fun1 = wrapFunction(sayStuff, this, ["Hello, world!"]);
534 * funqueue.push(fun1);
536 var wrapFunction = function(fn, context, params) {
538 fn.apply(context, params);
542 function resetSaveButton() {
543 $('.btn-save').button('complete');
546 function resetTooltips() {
547 $(".tooltip").remove();
548 $("[rel=tooltip]").tooltip({
552 setTimeout(function() {
553 $(".icon-fade").fadeTo(300, 0.35);
557 function populateSelect(target, instruction, data, selected) {
558 var opts = '<option value="">-- ' + instruction + ' --</option>';
559 for (var i in data) {
560 var chosen = (selected == i) ? ' selected' : '';
561 opts += '<option value="' + i + '"' + chosen + '>' + data[i] + '</option>';
563 $('#' + target).html(opts);
566 function ucfirst(string)
568 return string.charAt(0).toUpperCase() + string.slice(1);
571 function updateClock()
573 var currentTime = new Date ( );
574 var currentHours = currentTime.getHours ( );
575 var currentMinutes = currentTime.getMinutes ( );
576 var currentSeconds = currentTime.getSeconds ( );
577 currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
578 currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
579 currentHours = ( currentHours == 0 ) ? 12 : currentHours;
580 var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds;
581 $("#clock").html(currentTimeString);
582 $("#clockmobi").html(currentTimeString);
585 function calculateTimeLeft(value)
587 var dateTime = value.split(' '),
591 dateParts = date.split('-').map(function(part){
592 return parseInt(part, 10);
594 timeParts = time.split(':').map(function(part){
595 return parseInt(part, 10);
597 expieDateTime = new Date(dateParts[0], dateParts[1]-1, dateParts[2], timeParts[0], timeParts[1], timeParts[2] ),
598 currentDateTime = new Date(),
599 difference = expieDateTime.getTime() - currentDateTime.getTime(),
600 daysDifference, hoursDifference, minutesDifference, secondsDifference;
602 daysDifference = Math.floor(difference/1000/60/60/24);
603 difference -= daysDifference*1000*60*60*24;
604 hoursDifference = Math.floor(difference/1000/60/60);
605 difference -= hoursDifference*1000*60*60;
606 minutesDifference = Math.floor(difference/1000/60);
607 difference -= minutesDifference*1000*60;
608 secondsDifference = Math.floor(difference/1000);
610 if (expieDateTime.getTime() < currentDateTime.getTime()) {
614 return daysDifference > 0
615 ? daysDifference + 'd, ' + hoursDifference + 'h, ' + minutesDifference + 'm'
616 : hoursDifference + 'h, ' + minutesDifference + 'm';