PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/common/script.php

https://bitbucket.org/14rego/cman
PHP | 744 lines | 710 code | 11 blank | 23 comment | 220 complexity | f281f7d08e67bb237d903e4941aaf419 MD5 | raw file
  1. <div id="dialog-edit-team"></div>
  2. <div id="dialog-edit-note"></div>
  3. <div id="dialog-edit-task"></div>
  4. <div id="dialog-edit-link"></div>
  5. <div id="dialog-view-log"></div>
  6. <div id="dialog-loading"></div>
  7. <script>
  8. $.sendMsg = function(thisTITLE, thisMSG){
  9. if (thisTITLE==='error') {
  10. var thisTITLE = 'Error.';
  11. var thisMSG = 'Sorry, there has been an error: ['+thisMSG+']';
  12. } else {
  13. $.gritter.add({ title: thisTITLE, text: thisMSG, class_name: 'gritter-light' }); return false;
  14. }
  15. };
  16. $.quickUpdate = function(tab, col, val, id, act, itemLIST, itemTYPE){
  17. var serialData = 't='+tab+'&c='+col+'&v='+val+'&i='+id+'&a='+act;
  18. $.post('/manage/forms/update.php', serialData)
  19. .success(function(data) {
  20. if (itemLIST!=='success' && itemTYPE!=='msg') { $.updatePageData(itemLIST, itemTYPE); }
  21. $.sendMsg('Success', 'Update successful.');
  22. })
  23. .error(function(data) { $.sendMsg('error'); });
  24. };
  25. $.resetDefaults = function(list, filter){
  26. $('#filter-select-client').val('ALL');
  27. $('#filter-select-status').val('');
  28. $('#filter-select-label').val('');
  29. $('#filter-select-type').val('');
  30. $('#filter-select-priority').val('');
  31. $('#filter-select-from').val('');
  32. $('#filter-select-to').val('');
  33. $('#filter-select-sort').val('');
  34. $('#filter-select-in').val('');
  35. $('#filter-search').val('');
  36. // OVERRIDE DEFAULTS
  37. if (list==='users-rows') {
  38. $('#filter-select-type').val('all');
  39. $('#filter-select-sort').val('lastn');
  40. } else if (list==='logins-rows') {
  41. $('#filter-select-sort').val('url');
  42. $('#filter-select-in').val('ASC');
  43. } else if (list==='jobs-rows') {
  44. $('#filter-select-status').val('active');
  45. $('#filter-select-sort').val('proj.due');
  46. $('#filter-select-in').val('ASC');
  47. } else if (list==='costs-rows') {
  48. $('#filter-select-status').val('in queue');
  49. $('#filter-select-sort').val('cost.dat');
  50. $('#filter-select-in').val('DESC');
  51. } else if (list==='web-traffic-filters-rows') {
  52. $('#filter-select-client').val('Competition');
  53. }
  54. $.updatePageData(list, filter);
  55. };
  56. $.updatePageData = function(list, filter){
  57. var parentID = $('#'+filter+'_id').val();
  58. var setCLIENT = $('#filter-select-client').val();
  59. var setSTATUS = $('#filter-select-status').val();
  60. var setCAT = $('#filter-select-label').val();
  61. var setTYPE = $('#filter-select-type').val();
  62. var setPRI = $('#filter-select-priority').val();
  63. var setFROM = $('#filter-select-from').val();
  64. var setTO = $('#filter-select-to').val();
  65. var setSORT = $('#filter-select-sort').val();
  66. var setIN = $('#filter-select-in').val();
  67. var setSEARCH = $('#filter-search').val();
  68. if (list==='checklist-stickies' || list==='tasks-stickies') { <?php
  69. if ($contents=='checklist' || $contents=='tasks') { ?>
  70. if (list==='checklist-stickies') {
  71. var setTYPE = 'checklist';
  72. var setQUERY = '&src='+setSEARCH+'&frm='+setFROM+'&to='+setTO+'&tem=<?php echo $user_name; ?>&cat='+setCAT+'&pri='+setPRI;
  73. var setPARENT = '.lanes';
  74. var thisTYPE = 'todo';
  75. } else {
  76. var setTYPE = 'tasks';
  77. var setQUERY = '&src='+setSEARCH+'&in='+setIN+'&frm='+setFROM+'&to='+setTO+'&cli='+setCLIENT+'&pri='+setPRI;
  78. var setPARENT = '.lane';
  79. var thisTYPE = 'task';
  80. } <?php
  81. pg_result_seek($result, 0);
  82. while ($lane = pg_fetch_array($result)) { ?>
  83. var serialData = '<?php echo 'status='.$lane['alt']; ?>'+setQUERY;
  84. $.get('/manage/rows/'+setTYPE+'-stickies.php', serialData)
  85. .success(function(data) {
  86. $('#trello .<?php echo $lane['alt']; ?>').html(data);
  87. <?php if ($mobility!='desktop') { ?>
  88. $('.drag-it h3 a').hammer().unbind('dragend').delay(500).bind('dragend',function(e){
  89. e.preventDefault();
  90. var itemID = $(this).closest('.sticky').attr('id');
  91. var thisSTATUS = $(this).closest(setPARENT).attr('alt');
  92. var thisEV = e.direction;
  93. if (thisEV==='left') { var thisDIR = 'L'; }
  94. else if (thisEV==='right') { var thisDIR = 'R'; }
  95. if (thisDIR==='L' || thisDIR==='R') {
  96. var serialData = 'i='+itemID+'&t='+thisTYPE+'&c=status&v='+thisSTATUS+'&a='+thisDIR;
  97. $.post('/manage/forms/update.php', serialData)
  98. .success(function(data) {
  99. $(this).unbind('dragend');
  100. $.updatePageData(setTYPE+'-stickies');
  101. })
  102. .error(function(data) { $.sendMsg('error'); });
  103. }
  104. return false;
  105. });
  106. <?php } ?>
  107. })
  108. .error(function(data) { $.sendMsg('error'); });
  109. <?php
  110. }
  111. } ?>
  112. } else if (list==='checklist-edit') {
  113. var serialData = 'cat=todo&type=lane';
  114. $.get('/manage/rows/pman-settings-rows.php', serialData)
  115. .success(function(data) {
  116. $('#holder-todo-lanes').html(data);
  117. })
  118. .error(function(data) { $.sendMsg('error'); });
  119. var serialData = 'cat=todo&type=label';
  120. $.get('/manage/rows/pman-settings-rows.php', serialData)
  121. .success(function(data) {
  122. $('#holder-todo-labels').html(data);
  123. })
  124. .error(function(data) { $.sendMsg('error'); });
  125. } else if (list==='work-edit-rows') {
  126. var serialData = 'cat=work&type=client';
  127. $.get('/manage/rows/pman-settings-rows.php', serialData)
  128. .success(function(data) {
  129. $('#holder-work-clients-rows').html(data);
  130. })
  131. .error(function(data) { $.sendMsg('error'); });
  132. var serialData = 'cat=work&type=cat';
  133. $.get('/manage/rows/pman-settings-rows.php', serialData)
  134. .success(function(data) {
  135. $('#holder-work-cats-rows').html(data);
  136. })
  137. .error(function(data) { $.sendMsg('error'); });
  138. var serialData = 'cat=work&type=pri';
  139. $.get('/manage/rows/pman-settings-rows.php', serialData)
  140. .success(function(data) {
  141. $('#holder-work-pris-rows').html(data);
  142. })
  143. .error(function(data) { $.sendMsg('error'); });
  144. var serialData = 'cat=work&type=status';
  145. $.get('/manage/rows/pman-settings-rows.php', serialData)
  146. .success(function(data) {
  147. $('#holder-work-statuss-rows').html(data);
  148. })
  149. .error(function(data) { $.sendMsg('error'); });
  150. } else {
  151. // EXCEPTIONS BEFORE .GET
  152. if (list==='jobs-rows') {
  153. if (setSTATUS==='EMPTY') { $('#filter-select-sort').val('job.dsc'); }
  154. if (setSEARCH.length>3) { $('#filter-select-status').val('ALL'); setSTATUS = 'ALL'; }
  155. }
  156. // GET INFO
  157. var serialData = 'cat='+setTYPE+
  158. '&client='+setCLIENT+
  159. '&in='+setIN+
  160. '&parent='+parentID+
  161. '&search='+setSEARCH+
  162. '&sort='+setSORT+
  163. '&status='+setSTATUS+
  164. '&type='+filter;
  165. $.get('/manage/rows/'+list+'.php', serialData)
  166. .success(function(data) {
  167. $('#holder-'+list).html(data);
  168. // EXCEPTIONS ON SUCCESS
  169. if (list==='web-pages-rows' || list==='web-navigation-rows') {
  170. if (setCLIENT!=='ALL' || setSTATUS!=='ALL' || setSORT!=='ord' || setIN!=='ASC' || setSEARCH!=='') { $('.moving').hide(); }
  171. else { $('.moving').show(); }
  172. } else if (list==='inventory-ordering-rows') {
  173. $('.check-box').click( function() {
  174. var thisID = $(this).attr('alt');
  175. if ($(this).prop('checked') === true) {
  176. $('.check-in[alt="'+thisID+'"]').focus();
  177. } else {
  178. $('.check-in[alt="'+thisID+'"]').val('');
  179. }
  180. });
  181. $('.check-in').on('click, change', function() {
  182. $('.check-in').each(function(index) {
  183. var thisID = $(this).attr('alt');
  184. var thisVal = $(this).val();
  185. var thisNum = $.isNumeric(thisVal);
  186. if (thisVal < 1){
  187. $('.check-box[alt="'+thisID+'"]').prop('checked', false);
  188. } else {
  189. $('.check-box[alt="'+thisID+'"]').prop('checked', true);
  190. }
  191. if (thisNum === false){
  192. $(this).css('color', 'red');
  193. $('.check-box[alt="'+thisID+'"]').prop('checked', false);
  194. } else {
  195. $(this).css('color', '#575757');
  196. }
  197. });
  198. });
  199. } else if (list==='lines-rows') {
  200. var serialData = 'a=2&i='+parentID+'&t=1&v=1&c=1';
  201. $.post('/manage/forms/update.php', serialData)
  202. .success(function(data) {
  203. $('#inv_total').html('$'+data);
  204. })
  205. .error(function(data) { $.sendMsg('error'); });
  206. }
  207. })
  208. .error(function(data) { $.sendMsg('error'); });
  209. }
  210. $('.update-list').change( function(e){
  211. e.preventDefault();
  212. $.updatePageData(list, filter);
  213. });
  214. $('#button-search').click(function(e){
  215. e.preventDefault();
  216. $.updatePageData(list, filter);
  217. });
  218. $('.body').keyup( function (e){
  219. <?php if ($contents!='edit-web-page') { ?>
  220. if (e.keyCode === 13) { // RETURN
  221. e.preventDefault();
  222. $.updatePageData(list, filter);
  223. }
  224. <?php } ?>
  225. if (e.keyCode === 27) { // ESCAPE
  226. e.preventDefault();
  227. $.resetDefaults(list, filter);
  228. }
  229. });
  230. $('#button-reset').click(function(e){
  231. e.preventDefault();
  232. $.resetDefaults(list, filter);
  233. });
  234. };
  235. $.modalSafeTasks = function(taskID, projID, taskTYPE){
  236. if (taskID==='new') { var setTITLE = 'New Task'; } else { var setTITLE = 'Edit Task'; }
  237. var projStatus = $('#proj_status').val();
  238. if ((projStatus==='killed' || projStatus==='complete' || projStatus==='archive') && taskID==='new') {
  239. $.sendMsg('Error.', 'You cannot add a task to an inactive project.');
  240. } else {
  241. var serialData = 'id='+taskID+'&parent='+projID;
  242. $.get('/manage/forms/'+taskTYPE+'task-edit.php', serialData)
  243. .success(function(data) {
  244. $('#dialog-edit-task').html(data);
  245. $('#dialog-edit-task').dialog({
  246. title: setTITLE,
  247. height: 'auto',
  248. width: 600,
  249. modal: false,
  250. buttons: {
  251. 'OK': function() {
  252. var serialData = $('#form-edit-'+taskTYPE+'task').serialize()+'&id='+taskID+'&parent='+projID;
  253. $.post('/manage/forms/'+taskTYPE+'task-edit.php', serialData)
  254. .success(function(data) {
  255. if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); }
  256. else { $.updatePageData('tasks-rows', 'proj'); }
  257. $.updatePageData('tasks-stickies');
  258. $.updatePageData('work-tasks-rows', 'work');
  259. })
  260. .error(function(data) { $.sendMsg('error'); });
  261. $( this ).dialog( 'close' );
  262. },
  263. 'Cancel': function() {
  264. $( this ).dialog( 'close' );
  265. }
  266. }
  267. }).on('click', '.date', function(e){
  268. $(this).datepicker({
  269. showOn:'focus',
  270. dateFormat: 'yy-mm-dd',
  271. gotoCurrent: true
  272. }).focus();
  273. });
  274. })
  275. .error(function(data) { $.sendMsg('error'); });
  276. }
  277. };
  278. // DOCUMENT READY
  279. $(function() {
  280. $.ajaxSetup({cache: false})
  281. // MATCH HEIGHT AND WIDTH
  282. var maxWidth = 0;
  283. var maxHeight = 0;
  284. $('.match-h > span').each( function() {
  285. if ($(this).width() > maxWidth) {
  286. maxWidth = $(this).width();
  287. }
  288. }).css('width', maxWidth);
  289. $('.match-v > span').each( function() {
  290. if ($(this).height() > maxHeight) {
  291. maxHeight = $(this).height();
  292. }
  293. }).css('height', maxHeight);
  294. // LOADING ICON
  295. $('body').on({
  296. ajaxStart: function() {
  297. $(this).addClass('loading');
  298. },
  299. ajaxStop: function() {
  300. $(this).removeClass('loading');
  301. }
  302. });
  303. // LIVE CLICKS
  304. $(document)
  305. // DATE PICKERS
  306. .on('click', '.date', function(e){
  307. $(this).datepicker({
  308. showOn:'focus',
  309. dateFormat: 'yy-mm-dd',
  310. gotoCurrent: true
  311. }).focus();
  312. })
  313. .on('click', '.dateNaked', function(e){
  314. $(this).datepicker({
  315. showOn:'focus',
  316. dateFormat: 'yymmdd',
  317. gotoCurrent: true
  318. }).focus();
  319. })
  320. .on('click', '.datetime', function(e){
  321. $(this).datetimepicker({
  322. showOn:'focus',
  323. dateFormat: 'DD, M. d, yy,',
  324. timeFormat: 'h:mm tt',
  325. gotoCurrent: true
  326. }).focus();
  327. })
  328. // NOTE EDIT
  329. .on('click', '.button-edit-note', function(e){
  330. e.preventDefault();
  331. var noteID = $(this).attr('rel');
  332. var noteTYPE = $(this).attr('name');
  333. if (noteID==='new') { var setTITLE = 'New Note'; } else { var setTITLE = 'Edit Note'; }
  334. var jobID = $('#'+noteTYPE+'_id').val();
  335. var serialData = 'id='+noteID+'&parent='+jobID+'&type='+noteTYPE;
  336. $.get('/manage/forms/note-edit.php', serialData)
  337. .success(function(data) {
  338. $('#dialog-edit-note').html(data);
  339. $('#dialog-edit-note').dialog({
  340. title: setTITLE,
  341. height: 'auto',
  342. width: 450,
  343. modal: false,
  344. buttons: {
  345. 'OK': function() {
  346. var serialData = $('#form-edit-note').serialize()+'&id='+noteID+'&parent='+jobID+'&type='+noteTYPE;
  347. $.post('/manage/forms/note-edit.php', serialData)
  348. .success(function(data) {
  349. $('#dialog-edit-note').dialog('close');
  350. $.updatePageData('notes-rows', noteTYPE);
  351. })
  352. .error(function(data) { $.sendMsg('error'); });
  353. },
  354. 'Cancel': function() {
  355. $(this).dialog('close');
  356. }
  357. }
  358. });
  359. })
  360. .error(function(data) { $.sendMsg('error'); });
  361. })
  362. // DATE PICKERS THAT AUTO-SUBMIT
  363. .on('click', '.button-edit-task-due, .button-edit-proj-due, .button-edit-todo-due, .button-edit-work-due, .button-edit-wask-due', function(e){
  364. e.preventDefault();
  365. if ($(this).hasClass('button-edit-task-due')) { var setTYPE = 'pman_tasks'; }
  366. else if ($(this).hasClass('button-edit-todo-due')) { var setTYPE = 'pman_todos'; }
  367. else if ($(this).hasClass('button-edit-work-due')) { var setTYPE = 'work_proj'; }
  368. else if ($(this).hasClass('button-edit-wask-due')) { var setTYPE = 'work_task'; }
  369. else { var setTYPE = 'pman_projects'; }
  370. var itemID = $(this).attr('title');
  371. var itemDATE = $(this).attr('alt');
  372. $(this)
  373. .datepicker({
  374. onSelect: function(date) {
  375. var serialData = 'i='+itemID+'&t='+setTYPE+'&c=due&v='+date+'&a=1';
  376. $.post('/manage/forms/update.php', serialData)
  377. .success(function(data) {
  378. $.sendMsg('Thank you.', 'The due date was updated successfully.');
  379. if (setTYPE === 'pman_projects') {
  380. if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); } // project edit page?
  381. else { $.updatePageData('tasks-rows', 'proj'); }
  382. }
  383. else if (setTYPE === 'pman_tasks') { $.updatePageData('tasks-stickies'); }
  384. else if (setTYPE === 'work_proj') { $.updatePageData('work-tasks-rows'); }
  385. else { $.updatePageData('checklist-stickies'); }
  386. })
  387. .error(function(data) { $.sendMsg('error'); });
  388. },
  389. showOn:'focus',
  390. dateFormat: 'yy-mm-dd',
  391. gotoCurrent: true
  392. })
  393. .datepicker('setDate', itemDATE)
  394. .focus();
  395. })
  396. // TEAM/OWNER EDIT
  397. .on('click', '.input-edit-job-team, .input-edit-proj-team, .input-edit-task-team, .input-edit-mcab-team, .input-edit-work-team', function(e){
  398. e.preventDefault();
  399. var itemID = $(this).attr('title');
  400. var itemTEAM = $(this).attr('alt');
  401. if (itemID==='new') { var setTITLE = 'New Team'; } else { var setTITLE = 'Edit Team'; }
  402. if ($(this).hasClass('input-edit-task-team')) { var setTYPE = 'task'; }
  403. else if ($(this).hasClass('input-edit-proj-team')) { var setTYPE = 'proj'; }
  404. else if ($(this).hasClass('input-edit-mcab-team')) { var setTYPE = 'mcab'; }
  405. else if ($(this).hasClass('input-edit-work-team')) { var setTYPE = 'work'; }
  406. else { var setTYPE = 'job'; }
  407. var serialData = 'id='+itemID+'&team='+itemTEAM+'&type='+setTYPE;
  408. $.get('/manage/forms/team-edit.php', serialData)
  409. .success(function(data) {
  410. $('#dialog-edit-team').html(data);
  411. $('#dialog-edit-team').dialog({
  412. title: setTITLE,
  413. height: 'auto',
  414. width: 120,
  415. modal: false,
  416. buttons: {
  417. 'Done': function() {
  418. if ($('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').is('a')) {
  419. var serialData = $('#form-edit-team').serialize()+'&id='+itemID+'&team='+itemTEAM+'&type='+setTYPE;
  420. $.post('/manage/forms/team-edit.php', serialData)
  421. .success(function(data) {
  422. $('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').val(data);
  423. $.updatePageData('tasks-stickies');
  424. $.sendMsg('Thank you.', 'This '+setTYPE+' was updated successfully.');
  425. })
  426. .error(function(data) { $.sendMsg('error'); });
  427. $( this ).dialog( 'close' );
  428. if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); $.updatePageData('jobs-rows'); } // project edit page?
  429. else { $.updatePageData('tasks-rows', 'proj'); }
  430. } else if ($('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').is('input')) {
  431. var sndBack = '';
  432. $('.team-check').each( function() {
  433. if ($(this).is(':checked')) {
  434. sndBack = $(this).attr('title')+' '+sndBack;
  435. }
  436. });
  437. $('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').val(sndBack);
  438. $( this ).dialog( 'close' );
  439. }
  440. },
  441. 'Cancel': function() {
  442. $( this ).dialog( 'close' );
  443. }
  444. }
  445. });
  446. })
  447. .error(function(data) { $.sendMsg('error'); });
  448. });
  449. // BODY AJAX CLICKS
  450. $(document) //'.body'
  451. // TASK EDIT
  452. .on('click', '.button-edit-task, .button-edit-wask', function(e){
  453. e.preventDefault();
  454. if ($(this).hasClass('button-edit-wask')) { var taskTYPE = 'work-'; }
  455. else { var taskTYPE = ''; }
  456. var taskID = $(this).attr('rel');
  457. var projID = $(this).attr('name');
  458. $.modalSafeTasks(taskID, projID, taskTYPE);
  459. })
  460. // TASK PREVIEWS
  461. .on('click', '.icon-box.task', function(e){
  462. e.preventDefault();
  463. var projID = $(this).attr('rel');
  464. var serialData = 'parent='+projID+'&type=proj';
  465. $.get('/manage/rows/tasks-rows.php', serialData)
  466. .success(function(data) {
  467. $('#dialog-edit-task').html(data);
  468. $('#dialog-edit-task .button-edit-task[rel="new"]').remove();
  469. $('#dialog-edit-task').dialog({
  470. title: 'Click to edit a task',
  471. height: 'auto',
  472. width: 'auto',
  473. dialog: true
  474. });
  475. $('.button-edit-task').click(function(e){
  476. e.preventDefault();
  477. var taskID = $(this).attr('rel');
  478. var projID = $(this).attr('name');
  479. $.modalSafeTasks(taskID, projID);
  480. })
  481. })
  482. .error(function(data) { $.sendMsg('error'); });
  483. })
  484. // SHOW DETAILS
  485. .on('click', '.button-show-details', function(e){
  486. e.preventDefault();
  487. var setTITLE = $('#dialog-show-details').attr('rel');
  488. $('#dialog-show-details').dialog({
  489. title: setTITLE,
  490. height: 'auto',
  491. width: 'auto',
  492. dialog: true
  493. });
  494. })
  495. // NOTE PREVIEWS
  496. .on('click', '.icon-box.proj-note, .icon-box.task-note, .icon-box.todo-note, .icon-box.filter-note, .icon-box.work-note', function(e){
  497. e.preventDefault();
  498. var projID = $(this).attr('rel');
  499. if ($(this).hasClass('task-note')) { var setTYPE = 'task'; }
  500. else if ($(this).hasClass('todo-note')) { var setTYPE = 'todo'; }
  501. else if ($(this).hasClass('filter-note')) { var setTYPE = 'filter'; }
  502. else if ($(this).hasClass('work-note')) { var setTYPE = 'work'; }
  503. else { var setTYPE = 'proj'; }
  504. var serialData = 'parent='+projID+'&type='+setTYPE;
  505. $.get('/manage/rows/notes-rows.php', serialData)
  506. .success(function(data) {
  507. $('#dialog-edit-note').html(data);
  508. $('#dialog-edit-note .button-edit-note[rel="new"]').remove();
  509. $('#dialog-edit-note').dialog({
  510. title: '',
  511. height: 'auto',
  512. width: 'auto',
  513. dialog: true
  514. });
  515. })
  516. .error(function(data) { $.sendMsg('error'); });
  517. })
  518. // UPDATE LOG
  519. .on('click', '.dialog-view-log', function(e){
  520. e.preventDefault();
  521. var itemID = $(this).attr('rel');
  522. var itemTYPE = $(this).attr('name');
  523. var serialData = 'parent='+itemID+'&type='+itemTYPE;
  524. $.get('/manage/rows/updates-rows.php', serialData)
  525. .success(function(data) {
  526. $('#dialog-view-log').html(data);
  527. $('#dialog-view-log').dialog({
  528. title: '',
  529. height: 'auto',
  530. width: 'auto',
  531. dialog: true
  532. });
  533. })
  534. .error(function(data) { $.sendMsg('error'); });
  535. })
  536. // MOVE STUFF
  537. .on('click', '.button-move', function(e){
  538. e.preventDefault();
  539. var itemID = $(this).attr('rel');
  540. var itemCURR = $(this).attr('title');
  541. if ($(this).hasClass('dir-up')) { var itemMOVE = 'U'; var col = '1'; var val = '1'; }
  542. else if ($(this).hasClass('dir-down')) { var itemMOVE = 'D'; var col = '1'; var val = '1'; }
  543. else if ($(this).hasClass('dir-next')) { var itemMOVE = 'N'; var col = 'tier'; var val = itemCURR; }
  544. else if ($(this).hasClass('dir-prev')) { var itemMOVE = 'P'; var col = 'tier'; var val = itemCURR; }
  545. if ($(this).hasClass('this-work-pri')) { var tab = 'pman_settings'; var ilist = 'work-edit-rows'; var itype = ''; }
  546. else if ($(this).hasClass('this-work-status')) { var tab = 'pman_settings'; var ilist = 'work-edit-rows'; var itype = ''; }
  547. else if ($(this).hasClass('this-work-cat')) { var tab = 'pman_settings'; var ilist = 'work-edit-rows'; var itype = ''; }
  548. else if ($(this).hasClass('this-work-client')) { var tab = 'pman_settings'; var ilist = 'work-edit-rows'; var itype = ''; }
  549. else if ($(this).hasClass('this-todo-lane')) { var tab = 'pman_settings'; var ilist = 'checklist-edit'; var itype = ''; }
  550. else if ($(this).hasClass('this-todo-label')) { var tab = 'pman_settings'; var ilist = 'checklist-edit'; var itype = ''; }
  551. else if ($(this).hasClass('this-web-survey-question')) { var tab = 'site_survey_questions'; var ilist = 'web-survey-questions-rows'; var itype = 'survey'; }
  552. else if ($(this).hasClass('this-web-form-question')) { var tab = 'site_form_questions'; var ilist = 'web-form-questions-rows'; var itype = 'form'; }
  553. else if ($(this).hasClass('this-web-page')) { var tab = 'site_page'; var ilist = 'web-pages-rows'; var itype = ''; }
  554. else if ($(this).hasClass('this-web-nav')) { var tab = 'site_nav'; var ilist = 'web-navigation-rows'; var itype = ''; }
  555. $.quickUpdate(tab, col, val, itemID, itemMOVE, ilist, itype);
  556. })
  557. // EDIT DIALOGS
  558. .on('click', '.button-edit-item', function(e){
  559. e.preventDefault();
  560. if ($(this).hasClass('this-line')) { var itemTYPE = 'line'; var parentTYPE = 'cost'; }
  561. else if ($(this).hasClass('this-web-redirect')) { var itemTYPE = 'web-redirect'; var parentTYPE = ''; }
  562. else if ($(this).hasClass('this-show-date')) { var itemTYPE = 'show-date'; var parentTYPE = 'show'; }
  563. else if ($(this).hasClass('this-web-survey-question')) { var itemTYPE = 'web-survey-question'; var parentTYPE = 'survey'; }
  564. else if ($(this).hasClass('this-web-survey-option')) { var itemTYPE = 'web-survey-option'; var parentTYPE = 'survey'; }
  565. else if ($(this).hasClass('this-web-form-question')) { var itemTYPE = 'web-form-question'; var parentTYPE = 'form'; }
  566. else if ($(this).hasClass('this-web-form-option')) { var itemTYPE = 'web-form-option'; var parentTYPE = 'form'; }
  567. else if ($(this).hasClass('this-web-traffic-filter')) { var itemTYPE = 'web-traffic-filter'; var parentTYPE = ''; }
  568. else if ($(this).hasClass('this-login')) { var itemTYPE = 'login'; var parentTYPE = ''; }
  569. else if ($(this).hasClass('this-todo-lane')) { var itemTYPE = 'todo-lane'; var parentTYPE = ''; }
  570. else if ($(this).hasClass('this-todo-label')) { var itemTYPE = 'todo-label'; var parentTYPE = ''; }
  571. else if ($(this).hasClass('this-checklist')) { var itemTYPE = 'checklist'; var parentTYPE = ''; }
  572. else if ($(this).hasClass('this-inventory-order')) { var itemTYPE = 'inventory-order'; var parentTYPE = 'mcab'; }
  573. else if ($(this).hasClass('this-work-pri')) { var itemTYPE = 'work-pri'; var parentTYPE = ''; }
  574. else if ($(this).hasClass('this-work-status')) { var itemTYPE = 'work-status'; var parentTYPE = ''; }
  575. else if ($(this).hasClass('this-work-cat')) { var itemTYPE = 'work-cat'; var parentTYPE = ''; }
  576. else if ($(this).hasClass('this-work-client')) { var itemTYPE = 'work-client'; var parentTYPE = ''; }
  577. else { $.sendMsg('error'); }
  578. var itemID = $(this).attr('rel');
  579. var itemOLD = $(this).attr('alt');
  580. if ($(this).hasClass('complete')) { var itemSTATUS = 'yes'; } else { var itemSTATUS = 'no'; }
  581. var parentTHIS = '#'+parentTYPE+'_id';
  582. var parentID = $(parentTHIS).val();
  583. if ($(this).attr('name')>0) { var parentID = $(this).attr('name'); }
  584. if (itemID==='new') { var setTITLE = 'New'; } else { var setTITLE = 'Edit'; }
  585. var serialData = 'id='+itemID+'&parent='+parentID+'&old='+itemOLD+'&approved='+itemSTATUS;
  586. $.get('/manage/forms/'+itemTYPE+'-edit.php', serialData)
  587. .success(function(data) {
  588. $('#dialog-edit-'+itemTYPE).html(data);
  589. $('#dialog-edit-'+itemTYPE).dialog({
  590. title: setTITLE,
  591. height: 'auto',
  592. width: 550,
  593. modal: false,
  594. buttons: {
  595. 'OK': function() {
  596. var serialData = $('#form-edit-'+itemTYPE).serialize()+'&id='+itemID+'&parent='+parentID+'&old='+itemOLD+'&approved='+itemSTATUS;
  597. $.post('/manage/forms/'+itemTYPE+'-edit.php', serialData)
  598. .success(function(data) {
  599. $('#dialog-edit-'+itemTYPE).dialog('close');
  600. if (itemTYPE === 'checklist') { $.updatePageData('checklist-stickies'); }
  601. else if (itemTYPE === 'todo-lane' || itemTYPE === 'todo-label') { $.updatePageData('checklist-edit'); }
  602. else if (itemTYPE === 'web-survey-option') { $.updatePageData('web-survey-questions-rows', parentTYPE); }
  603. else if (itemTYPE === 'web-form-option') { $.updatePageData('web-form-questions-rows', parentTYPE); }
  604. else if (itemTYPE === 'inventory-order') { document.location.href='/manage/edit-inventory/'+parentID }
  605. else if (
  606. itemTYPE === 'work-cat' ||
  607. itemTYPE === 'work-client' ||
  608. itemTYPE === 'work-pri' ||
  609. itemTYPE === 'work-status'
  610. ) { $.updatePageData('work-edit-rows'); }
  611. else { $.updatePageData(itemTYPE+'s-rows', parentTYPE); }
  612. })
  613. .error(function(data) { $.sendMsg('error'); });
  614. },
  615. 'Cancel': function() {
  616. $(this).dialog('close');
  617. }
  618. }
  619. }).on('click', '.date', function(e){
  620. $(this).datepicker({
  621. showOn:'focus',
  622. dateFormat: 'yy-mm-dd',
  623. gotoCurrent: true
  624. }).focus();
  625. });
  626. if (itemTYPE === 'line') {
  627. $('.line-amt, .line-price, .line-total').on('change', function() {
  628. var amt = $('.line-amt').val();
  629. var pri = $('.line-price').val();
  630. var tot = amt * pri;
  631. $('.line-total').val(tot);
  632. });
  633. }
  634. })
  635. .error(function(data) { $.sendMsg('error'); });
  636. });
  637. // NOTIFICATIONS
  638. $('.notify-accepted').click( function(e){
  639. e.preventDefault();
  640. var itemID = $(this).attr('rel');
  641. var serialData = 'i='+itemID+'&t=log_notify&c=status&v=accepted&a=1';
  642. $.post('/manage/forms/update.php', serialData)
  643. .success(function(data) {
  644. countNotify--;
  645. $('#notify-on').text(countNotify);
  646. $('.notify-accepted[rel="'+itemID+'"]').closest('p').remove();
  647. })
  648. .error(function(data) { $.sendMsg('error'); });
  649. });
  650. // DRAG AND DROP LANES
  651. <?php if (($contents=='checklist' || $contents=='tasks') && $mobility=='desktop') { ?>
  652. $('#trello').on('hover', '.drag-it', function () {
  653. $(this).draggable({ revert: 'invalid' });
  654. var itemID = $(this).attr('id');
  655. if ($(this).hasClass('task')) { var thisTYPE = 'task'; var thisSTATUS = 'complete'; }
  656. else if ($(this).hasClass('todo')) { var thisTYPE = 'todo'; var thisSTATUS = '<?php echo $final_status_id; ?>'; }
  657. <?php
  658. pg_result_seek($result, 0);
  659. while ($lane = pg_fetch_array($result)) { ?>
  660. $('.drop-it.<?php echo $lane['alt']; ?>').droppable({
  661. greedy: true,
  662. hoverClass: 'drop-hover',
  663. drop: function( event, ui ) {
  664. var serialData = 'i='+itemID+'&t=pman_'+thisTYPE+'s&c=status&v=<?php echo $lane['id']; ?>&a=1';
  665. $.post('/manage/forms/update.php', serialData)
  666. .error(function(data) { $.sendMsg('error'); });
  667. if (thisTYPE==='todo') { $.updatePageData('checklist-stickies'); }
  668. else if (thisTYPE==='task') { $.updatePageData('tasks-stickies'); }
  669. }
  670. });<?php
  671. } ?>
  672. $('.trash').droppable({
  673. greedy: true,
  674. hoverClass: 'drop-hover',
  675. drop: function( event, ui ) {
  676. var serialData = 'i='+itemID+'&t=pman_'+thisTYPE+'s&c=status&v='+thisSTATUS+'&a=1';
  677. $.post('/manage/forms/update.php', serialData)
  678. .error(function(data) { $.sendMsg('error'); });
  679. if (thisTYPE==='todo') { $.updatePageData('checklist-stickies'); }
  680. else if (thisTYPE==='task') { $.updatePageData('tasks-stickies'); }
  681. }
  682. });
  683. });
  684. <?php } ?>
  685. // BUTTONS
  686. $(document).keydown(function(event) {
  687. if (!( String.fromCharCode(event.which).toLowerCase() == 's' && event.metaKey) && !(event.which == 19)) return true;
  688. $('.auto-save').trigger('click');
  689. event.preventDefault();
  690. return false;
  691. }).keydown(function(event) {
  692. if (!( String.fromCharCode(event.which).toLowerCase() == 's' && event.ctrlKey) && !(event.which == 19)) return true;
  693. $('.auto-save').trigger('click');
  694. event.preventDefault();
  695. return false;
  696. });
  697. $('#button-toggle-lanes').click(function(e){
  698. e.preventDefault();
  699. $('#trello #killed, #trello #complete').toggle();
  700. });
  701. $('#button-save-main-form').click( function(e){
  702. e.preventDefault();
  703. var sch = $(this).attr('title');
  704. var frm = $(this).attr('name');
  705. var req1 = $('#req1').val();
  706. var err1 = $('#req1').attr('alt');
  707. var req2 = $('#req2').val();
  708. var err2 = $('#req2').attr('alt');
  709. if ($('#'+sch+'_id').val() === '') { alert('ID!'); }
  710. else {
  711. if ($('#'+sch+'_'+req1).val() === '' && req1!=='') {
  712. $.sendMsg('Not enough information.', 'You must enter '+err1+'.');
  713. } else if ($('#'+sch+'_'+req2).val() === '' && req2!=='') {
  714. $.sendMsg('Not enough information.', 'You must enter '+err2+'.');
  715. } else {
  716. var serialData = $('#form-edit-'+frm).serialize();
  717. $.post('/manage/forms/'+frm+'-edit.php', serialData)
  718. .success(function(data) {
  719. if ($('#'+sch+'_id').val() === 'new') { document.location.href='/manage/edit-'+frm+'/'+data; }
  720. else {
  721. $.sendMsg('Thank you.', 'Updated successfully.');
  722. $.updatePageData('tasks-rows', sch);
  723. $.updatePageData('notes-rows', sch);
  724. $.updatePageData('costs-rows', sch);
  725. $.updatePageData('links-rows', sch);
  726. }
  727. })
  728. .error(function(data) { $.sendMsg('error'); });
  729. }
  730. }
  731. });
  732. }); // DOC READY
  733. </script>