footer.oa.html.hook.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <?php
  2. $this->loadModel('attend');
  3. $isLogon = $this->loadModel('user')->isLogon();
  4. if($isLogon and empty($this->app->user->signed) and $this->attend->checkSignIn())
  5. {
  6. $_SESSION['user']->signed = true;
  7. $this->app->user->signed = true;
  8. }
  9. if($isLogon and isset($_SESSION['user']) and (!isset($this->app->user->mustSignOut) or $this->app->user->mustSignOut != $this->config->attend->mustSignOut))
  10. {
  11. $_SESSION['user']->mustSignOut = $this->config->attend->mustSignOut;
  12. $this->app->user->mustSignOut = $this->config->attend->mustSignOut;
  13. }
  14. ?>
  15. <?php if($isLogon and empty($this->app->user->signed)) $this->attend->signIn($this->app->user->account);?>
  16. <script>
  17. <?php if($isLogon and !empty($this->app->user->signed) and $this->app->user->mustSignOut == 'no'):?>
  18. $.get(createLink('attend', 'signOut'));
  19. <?php endif;?>
  20. <?php if($isLogon and $this->app->user->mustSignOut == 'yes'):?>
  21. $('#poweredBy').append(<?php echo json_encode(html::a($this->createLink('user', 'logout'), $lang->logout, '', "class='btn btn-sm btn-danger' id='signOut' style='color:#fff;'"));?>)
  22. <?php if(strpos(",{$this->config->attend->noAttendUsers},", ",{$this->app->user->account},") === false and $this->config->attend->signOutLimit):?>
  23. if(new Date().getTime() < '<?php echo strtotime(date("Y-m-d") . ' ' . $this->config->attend->signOutLimit) * 1000;?>')
  24. {
  25. $('#poweredBy #signOut').click(function()
  26. {
  27. if(!confirm(<?php echo json_encode($lang->attend->confirmEarly);?>)) return false;
  28. })
  29. }
  30. <?php endif;?>
  31. <?php endif;?>
  32. <?php $moduleName = $this->app->getModuleName();?>
  33. <?php if(isset($lang->oa->menu->$moduleName)):?>
  34. $('#footer #crumbs').append("<i class='icon-angle-right'></i> <?php echo $title?>");
  35. <?php endif;?>
  36. $.extend(
  37. {
  38. setAjaxForm: function(formID, callback, beforeSubmit)
  39. {
  40. if($(document).data('setAjaxForm:' + formID)) return;
  41. form = $(formID);
  42. var options =
  43. {
  44. target : null,
  45. timeout : config.timeout,
  46. dataType:'json',
  47. success: function(response)
  48. {
  49. var submitButton = $(formID).find(':input[type=submit], .submit');
  50. /* The response is not an object, some error occers, bootbox.alert it. */
  51. if($.type(response) != 'object')
  52. {
  53. $.enableForm(formID);
  54. if(response) return bootbox.alert(response);
  55. return bootbox.alert('No response.');
  56. }
  57. /* The response.result is success. */
  58. if(response.result == 'success')
  59. {
  60. if(response.message && response.message.length)
  61. {
  62. submitButton.popover($.extend(
  63. {
  64. trigger: 'manual',
  65. content: response.message,
  66. tipClass: 'popover-success popover-form-result',
  67. placement: response.placement ? response.placement : 'right'
  68. }, submitButton.data())).popover('show');
  69. setTimeout(function(){submitButton.popover('destroy')}, 2000);
  70. }
  71. if($.isFunction(callback)) return callback(response);
  72. if($('#responser').length && response.message && response.message.length)
  73. {
  74. $('#responser').html(response.message).addClass('red f-12px').show().delay(3000).fadeOut(100);
  75. }
  76. if(response.closeModal)
  77. {
  78. setTimeout($.zui.closeModal, 1200);
  79. }
  80. if(response.callback)
  81. {
  82. var rcall = window[response.callback];
  83. if($.isFunction(rcall))
  84. {
  85. if(rcall() === false)
  86. {
  87. return;
  88. }
  89. }
  90. }
  91. if(response.locate)
  92. {
  93. if(response.locate == 'loadInModal')
  94. {
  95. var modal = $('.modal');
  96. setTimeout(function()
  97. {
  98. modal.load(modal.attr('ref'), function(){$(this).find('.modal-dialog').css('width', $(this).data('width'));
  99. $.zui.ajustModalPosition()})
  100. }, 1000);
  101. }
  102. else if(response.locate == 'parent')
  103. {
  104. setTimeout(function(){window.parent.location.reload();}, 1200);
  105. }
  106. else
  107. {
  108. var reloadUrl = response.locate == 'reload' ? location.href : response.locate;
  109. setTimeout(function(){location.href = reloadUrl;}, 1200);
  110. }
  111. }
  112. if(response.ajaxReload)
  113. {
  114. var $target = $(response.ajaxReload);
  115. if($target.length === 1)
  116. {
  117. $target.load(document.location.href + ' ' + response.ajaxReload, function()
  118. {
  119. // $target.dataTable();
  120. $target.find('[data-toggle="modal"]').modalTrigger();
  121. });
  122. }
  123. }
  124. return true;
  125. }
  126. /**
  127. * The response.result is fail.
  128. */
  129. $.enableForm(formID);
  130. /* The result.message is just a string. */
  131. if($.type(response.message) == 'string')
  132. {
  133. if($('#responser').length == 0)
  134. {
  135. submitButton.popover($.extend(
  136. {
  137. trigger: 'manual',
  138. content: response.message,
  139. tipClass: 'popover-danger popover-form-result',
  140. placement: response.placement ? response.placement : 'right'
  141. }, submitButton.data())).popover('show');
  142. setTimeout(function(){submitButton.popover('destroy')}, 2000);
  143. }
  144. $('#responser').html(response.message).addClass('red small text-danger').show().delay(5000).fadeOut(100);
  145. }
  146. /* The result.message is just a object. */
  147. if($.type(response.message) == 'object')
  148. {
  149. $.each(response.message, function(key, value)
  150. {
  151. /* Define the id of the error objecjt and it's label. */
  152. var errorOBJ = '#' + key;
  153. var errorLabel = key + 'Label';
  154. /* Create the error message. */
  155. var errorMSG = '<span id="' + errorLabel + '" for="' + key + '" class="text-error red">';
  156. if($.type(value) == 'string')
  157. {
  158. errorMSG += value;
  159. }
  160. else
  161. {
  162. $.each(value, function(subKey, subValue)
  163. {
  164. errorMSG += subKey != value.length - 1 ? subValue.replace(/[\。|\.]/, ';') : subValue;
  165. })
  166. }
  167. errorMSG += '</span>';
  168. /* Append error message, set style and set the focus events. */
  169. $('#' + errorLabel).remove();
  170. var $errorOBJ = $(formID).find(errorOBJ);
  171. if($errorOBJ.closest('.input-group').length > 0)
  172. {
  173. $errorOBJ.closest('.input-group').after(errorMSG)
  174. }
  175. else
  176. {
  177. $errorOBJ.parent().append(errorMSG);
  178. }
  179. $errorOBJ.css('margin-bottom', 0);
  180. $errorOBJ.css('border-color','#953B39')
  181. $errorOBJ.change(function()
  182. {
  183. $errorOBJ.css('margin-bottom', 0);
  184. $errorOBJ.css('border-color','')
  185. $('#' + errorLabel).remove();
  186. });
  187. })
  188. /* Focus the first error field thus to nitify the user. */
  189. var firstErrorField = $('#' +$('span.red').first().attr('for'));
  190. var topOffset;
  191. if(firstErrorField.length) topOffset = parseInt(firstErrorField.offset().top) - 20; // 20px offset more for margin.
  192. /* If there's the navbar-fixed-top element, minus it's height. */
  193. if($('.navbar-fixed-top').size())
  194. {
  195. topOffset = topOffset - parseInt($('.navbar-fixed-top').height());
  196. }
  197. /* Scroll to the error field and foucus it. */
  198. $(document).scrollTop(topOffset);
  199. firstErrorField.focus();
  200. }
  201. if($.isFunction(callback)) return callback(response);
  202. },
  203. /* When error occers, alert the response text, status and error. */
  204. error: function(jqXHR, textStatus, errorThrown)
  205. {
  206. $.enableForm(formID);
  207. if(textStatus == 'timeout')
  208. {
  209. bootbox.alert(v.lang.timeout);
  210. return false;
  211. }
  212. bootbox.alert(jqXHR.responseText + textStatus + errorThrown);
  213. }
  214. };
  215. /* Call ajaxSubmit to sumit the form. */
  216. $(document).on('submit', formID, function()
  217. {
  218. $.disableForm(formID);
  219. if(!beforeSubmit || beforeSubmit() !== false)
  220. {
  221. $(this).ajaxSubmit(options);
  222. }
  223. else
  224. {
  225. $.enableForm(formID);
  226. }
  227. return false; // Prevent the submitting event of the browser.
  228. }).data('setAjaxForm:' + formID, true);
  229. },
  230. /* Disable a form. */
  231. disableForm:function(formID)
  232. {
  233. $(formID).find(':submit').attr('disabled', true);
  234. },
  235. /**
  236. * Set ajax loader.
  237. *
  238. * Bind click event for some elements thus when click them,
  239. * use $.load to load page into target.
  240. *
  241. * @param string selector
  242. * @param string target
  243. */
  244. setAjaxLoader: function(selector, target)
  245. {
  246. /* Avoid duplication of binding */
  247. var data = $('body').data('ajaxLoader');
  248. if(data && data[selector]) return;
  249. if(!data) data = {};
  250. data[selector] = true;
  251. $('body').data('ajaxLoader', data);
  252. $(document).on('click', selector, function()
  253. {
  254. var url = $(this).attr('href');
  255. if(!url) url = $(this).data('rel');
  256. if(!url) return false;
  257. var $target = $(target);
  258. if(!$target.size()) return false;
  259. var width = $(this).data('width');
  260. $target.load(url, function()
  261. {
  262. if(width) $target.find('.modal-dialog').css('width', width);
  263. if($target.hasClass('modal') && $.zui.ajustModalPosition)
  264. {
  265. $.zui.ajustModalPosition();
  266. $target.find('.modal-dialog .modal-body').resize(function(){$.zui.ajustModalPosition();});
  267. }
  268. });
  269. return false;
  270. });
  271. },
  272. /**
  273. * Set ajax jsoner.
  274. *
  275. * @param string selector
  276. * @param object callback
  277. */
  278. setAjaxJSONER: function(selector, callback)
  279. {
  280. $(document).on('click', selector, function()
  281. {
  282. /* Try to get the href of current element, then try it's data-rel attribute. */
  283. url = $(this).attr('href');
  284. if(!url) url = $(this).data('rel');
  285. if(!url) return false;
  286. $.getJSON(url, function(response)
  287. {
  288. /* If set callback, call it. */
  289. if($.isFunction(callback)) return callback(response);
  290. /* If the response has message attribute, show it in #responser or alert it. */
  291. if(response.message)
  292. {
  293. if($('#responser').length)
  294. {
  295. $('#responser').html(response.message);
  296. $('#responser').addClass('text-info f-12px');
  297. $('#responser').show().delay(3000).fadeOut(100);
  298. }
  299. else
  300. {
  301. bootbox.alert(response.message);
  302. }
  303. }
  304. /* If the response has locate param, locate the browse. */
  305. if(response.locate) return location.href = response.locate;
  306. /* If target and source returned in reponse, update target with the source. */
  307. if(response.target && response.source)
  308. {
  309. $(response.target).load(response.source);
  310. }
  311. });
  312. return false;
  313. });
  314. },
  315. /**
  316. * Set ajax deleter.
  317. *
  318. * @param string $selector
  319. * @access public
  320. * @return void
  321. */
  322. setAjaxDeleter: function (selector, callback)
  323. {
  324. $(selector).each(function()
  325. {
  326. href = $(this).attr('href');
  327. $(this).attr('href', '###').attr('data-href', href);
  328. })
  329. $(document).on('click', selector, function()
  330. {
  331. if(confirm('<?php echo $lang->confirmDelete?>'))
  332. {
  333. var deleter = $(this);
  334. deleter.text('<?php echo $lang->deleteing?>');
  335. $.getJSON(deleter.attr('data-href'), function(data)
  336. {
  337. callback && callback(data);
  338. if(data.result == 'success')
  339. {
  340. if(deleter.parents('#ajaxModal').size()) return $.reloadAjaxModal(1200);
  341. if(data.locate) return location.href = data.locate;
  342. return location.reload();
  343. }
  344. else
  345. {
  346. alert(data.message);
  347. return location.reload();
  348. }
  349. });
  350. }
  351. return false;
  352. });
  353. return false;
  354. },
  355. /**
  356. * Set reload deleter.
  357. *
  358. * @param string $selector
  359. * @access public
  360. * @return void
  361. */
  362. setReloadDeleter: function (selector)
  363. {
  364. href = $(selector).attr('href');
  365. $(selector).attr('href', '###').attr('data-href', href);
  366. $(document).on('click', selector, function()
  367. {
  368. if(confirm('<?php echo $lang->confirmDelete?>'))
  369. {
  370. var deleter = $(this);
  371. deleter.text('<?php echo $lang->deleteing?>');
  372. $.getJSON(deleter.attr('data-href'), function(data)
  373. {
  374. var afterDelete = deleter.data('afterDelete');
  375. if($.isFunction(afterDelete))
  376. {
  377. $.proxy(afterDelete, deleter)(data);
  378. }
  379. if(data.result == 'success')
  380. {
  381. var table = $(deleter).closest('table');
  382. var replaceID = table.attr('id');
  383. table.wrap("<div id='tmpDiv'></div>");
  384. var $tmpDiv = $('#tmpDiv');
  385. $tmpDiv.load(document.location.href + ' #' + replaceID, function()
  386. {
  387. $tmpDiv.replaceWith($tmpDiv.html());
  388. var $target = $('#' + replaceID);
  389. $target.find('.reloadDeleter').data('afterDelete', afterDelete);
  390. $target.find('[data-toggle="modal"]').modalTrigger();
  391. if($target.hasClass('table-data'))
  392. {
  393. $target.dataTable();
  394. }
  395. if(typeof sortTable == 'function')
  396. {
  397. sortTable();
  398. }
  399. else
  400. {
  401. $('tfoot td').css('background', 'white').unbind('click').unbind('hover');
  402. }
  403. });
  404. }
  405. else
  406. {
  407. alert(data.message);
  408. }
  409. });
  410. }
  411. return false;
  412. });
  413. },
  414. /**
  415. * Set reload.
  416. *
  417. * @param string $selector
  418. * @access public
  419. * @return void
  420. */
  421. setReload: function (selector)
  422. {
  423. $(document).on('click', selector, function()
  424. {
  425. var reload = $(this);
  426. $.getJSON(reload.attr('href'), function(data)
  427. {
  428. if(data.result == 'success')
  429. {
  430. var table = $(reload).closest('table');
  431. var replaceID = table.attr('id');
  432. table.wrap("<div id='tmpDiv'></div>");
  433. $('#tmpDiv').load(document.location.href + ' #' + replaceID, function()
  434. {
  435. $('#tmpDiv').replaceWith($('#tmpDiv').html());
  436. if(typeof sortTable == 'function')
  437. {
  438. sortTable();
  439. }
  440. else
  441. {
  442. $('tfoot td').css('background', 'white').unbind('click').unbind('hover');
  443. }
  444. });
  445. }
  446. else
  447. {
  448. alert(data.message);
  449. }
  450. });
  451. return false;
  452. });
  453. },
  454. /**
  455. * Reload ajax modal.
  456. *
  457. * @param int duration
  458. * @access public
  459. * @return void
  460. */
  461. reloadAjaxModal: function(duration)
  462. {
  463. if(typeof(duration) == 'undefined') duration = 1000;
  464. setTimeout(function()
  465. {
  466. var modal = $('#ajaxModal');
  467. modal.load(modal.attr('ref'), function(){$(this).find('.modal-dialog').css('width', $(this).data('width')); $.zui.ajustModalPosition()})
  468. }, duration);
  469. }
  470. });
  471. $(function()
  472. {
  473. $.setAjaxDeleter('.deleter');
  474. $.setAjaxLoader('.loadInModal', '#triggerModal');
  475. $('[data-toggle="tooltip"]').tooltip();
  476. $.ajaxForm('#ajaxForm');
  477. })
  478. function setRequiredFields()
  479. {
  480. if(!config.requiredFields) return false;
  481. requiredFields = config.requiredFields.split(',');
  482. for(i = 0; i < requiredFields.length; i++)
  483. {
  484. $('#' + requiredFields[i]).closest('td,th').prepend("<div class='required required-wrapper'></div>");
  485. var colEle = $('#' + requiredFields[i]).closest('[class*="col-"]');
  486. if(colEle.parent().hasClass('form-group')) colEle.addClass('required');
  487. }
  488. }
  489. /**
  490. * The most recent month is highlighted
  491. */
  492. function addRecentlyMonthActive()
  493. {
  494. var isActive = false;
  495. $('.side .panel-body .tree ul').each(function()
  496. {
  497. $(this).find('li').each(function()
  498. {
  499. if($(this).hasClass('active') && !isActive) isActive = true;
  500. })
  501. });
  502. if(!isActive) $('.side .panel-body .tree ul:last li:last').addClass('active')
  503. }
  504. </script>