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