/common/script.php
PHP | 744 lines | 710 code | 11 blank | 23 comment | 220 complexity | f281f7d08e67bb237d903e4941aaf419 MD5 | raw file
- <div id="dialog-edit-team"></div>
- <div id="dialog-edit-note"></div>
- <div id="dialog-edit-task"></div>
- <div id="dialog-edit-link"></div>
- <div id="dialog-view-log"></div>
- <div id="dialog-loading"></div>
-
- <script>
- $.sendMsg = function(thisTITLE, thisMSG){
- if (thisTITLE==='error') {
- var thisTITLE = 'Error.';
- var thisMSG = 'Sorry, there has been an error: ['+thisMSG+']';
- } else {
- $.gritter.add({ title: thisTITLE, text: thisMSG, class_name: 'gritter-light' }); return false;
- }
- };
- $.quickUpdate = function(tab, col, val, id, act, itemLIST, itemTYPE){
- var serialData = 't='+tab+'&c='+col+'&v='+val+'&i='+id+'&a='+act;
- $.post('/manage/forms/update.php', serialData)
- .success(function(data) {
- if (itemLIST!=='success' && itemTYPE!=='msg') { $.updatePageData(itemLIST, itemTYPE); }
- $.sendMsg('Success', 'Update successful.');
- })
- .error(function(data) { $.sendMsg('error'); });
- };
- $.resetDefaults = function(list, filter){
- $('#filter-select-client').val('ALL');
- $('#filter-select-status').val('');
- $('#filter-select-label').val('');
- $('#filter-select-type').val('');
- $('#filter-select-priority').val('');
- $('#filter-select-from').val('');
- $('#filter-select-to').val('');
- $('#filter-select-sort').val('');
- $('#filter-select-in').val('');
- $('#filter-search').val('');
- // OVERRIDE DEFAULTS
- if (list==='users-rows') {
- $('#filter-select-type').val('all');
- $('#filter-select-sort').val('lastn');
- } else if (list==='logins-rows') {
- $('#filter-select-sort').val('url');
- $('#filter-select-in').val('ASC');
- } else if (list==='jobs-rows') {
- $('#filter-select-status').val('active');
- $('#filter-select-sort').val('proj.due');
- $('#filter-select-in').val('ASC');
- } else if (list==='costs-rows') {
- $('#filter-select-status').val('in queue');
- $('#filter-select-sort').val('cost.dat');
- $('#filter-select-in').val('DESC');
- } else if (list==='web-traffic-filters-rows') {
- $('#filter-select-client').val('Competition');
- }
- $.updatePageData(list, filter);
- };
- $.updatePageData = function(list, filter){
- var parentID = $('#'+filter+'_id').val();
- var setCLIENT = $('#filter-select-client').val();
- var setSTATUS = $('#filter-select-status').val();
- var setCAT = $('#filter-select-label').val();
- var setTYPE = $('#filter-select-type').val();
- var setPRI = $('#filter-select-priority').val();
- var setFROM = $('#filter-select-from').val();
- var setTO = $('#filter-select-to').val();
- var setSORT = $('#filter-select-sort').val();
- var setIN = $('#filter-select-in').val();
- var setSEARCH = $('#filter-search').val();
-
- if (list==='checklist-stickies' || list==='tasks-stickies') { <?php
- if ($contents=='checklist' || $contents=='tasks') { ?>
- if (list==='checklist-stickies') {
- var setTYPE = 'checklist';
- var setQUERY = '&src='+setSEARCH+'&frm='+setFROM+'&to='+setTO+'&tem=<?php echo $user_name; ?>&cat='+setCAT+'&pri='+setPRI;
- var setPARENT = '.lanes';
- var thisTYPE = 'todo';
- } else {
- var setTYPE = 'tasks';
- var setQUERY = '&src='+setSEARCH+'&in='+setIN+'&frm='+setFROM+'&to='+setTO+'&cli='+setCLIENT+'&pri='+setPRI;
- var setPARENT = '.lane';
- var thisTYPE = 'task';
- } <?php
- pg_result_seek($result, 0);
- while ($lane = pg_fetch_array($result)) { ?>
- var serialData = '<?php echo 'status='.$lane['alt']; ?>'+setQUERY;
- $.get('/manage/rows/'+setTYPE+'-stickies.php', serialData)
- .success(function(data) {
- $('#trello .<?php echo $lane['alt']; ?>').html(data);
- <?php if ($mobility!='desktop') { ?>
- $('.drag-it h3 a').hammer().unbind('dragend').delay(500).bind('dragend',function(e){
- e.preventDefault();
- var itemID = $(this).closest('.sticky').attr('id');
- var thisSTATUS = $(this).closest(setPARENT).attr('alt');
- var thisEV = e.direction;
- if (thisEV==='left') { var thisDIR = 'L'; }
- else if (thisEV==='right') { var thisDIR = 'R'; }
- if (thisDIR==='L' || thisDIR==='R') {
- var serialData = 'i='+itemID+'&t='+thisTYPE+'&c=status&v='+thisSTATUS+'&a='+thisDIR;
- $.post('/manage/forms/update.php', serialData)
- .success(function(data) {
- $(this).unbind('dragend');
- $.updatePageData(setTYPE+'-stickies');
- })
- .error(function(data) { $.sendMsg('error'); });
- }
- return false;
- });
- <?php } ?>
- })
- .error(function(data) { $.sendMsg('error'); });
- <?php
- }
- } ?>
- } else if (list==='checklist-edit') {
- var serialData = 'cat=todo&type=lane';
- $.get('/manage/rows/pman-settings-rows.php', serialData)
- .success(function(data) {
- $('#holder-todo-lanes').html(data);
- })
- .error(function(data) { $.sendMsg('error'); });
- var serialData = 'cat=todo&type=label';
- $.get('/manage/rows/pman-settings-rows.php', serialData)
- .success(function(data) {
- $('#holder-todo-labels').html(data);
- })
- .error(function(data) { $.sendMsg('error'); });
- } else if (list==='work-edit-rows') {
- var serialData = 'cat=work&type=client';
- $.get('/manage/rows/pman-settings-rows.php', serialData)
- .success(function(data) {
- $('#holder-work-clients-rows').html(data);
- })
- .error(function(data) { $.sendMsg('error'); });
- var serialData = 'cat=work&type=cat';
- $.get('/manage/rows/pman-settings-rows.php', serialData)
- .success(function(data) {
- $('#holder-work-cats-rows').html(data);
- })
- .error(function(data) { $.sendMsg('error'); });
- var serialData = 'cat=work&type=pri';
- $.get('/manage/rows/pman-settings-rows.php', serialData)
- .success(function(data) {
- $('#holder-work-pris-rows').html(data);
- })
- .error(function(data) { $.sendMsg('error'); });
- var serialData = 'cat=work&type=status';
- $.get('/manage/rows/pman-settings-rows.php', serialData)
- .success(function(data) {
- $('#holder-work-statuss-rows').html(data);
- })
- .error(function(data) { $.sendMsg('error'); });
- } else {
- // EXCEPTIONS BEFORE .GET
- if (list==='jobs-rows') {
- if (setSTATUS==='EMPTY') { $('#filter-select-sort').val('job.dsc'); }
- if (setSEARCH.length>3) { $('#filter-select-status').val('ALL'); setSTATUS = 'ALL'; }
- }
- // GET INFO
- var serialData = 'cat='+setTYPE+
- '&client='+setCLIENT+
- '&in='+setIN+
- '&parent='+parentID+
- '&search='+setSEARCH+
- '&sort='+setSORT+
- '&status='+setSTATUS+
- '&type='+filter;
- $.get('/manage/rows/'+list+'.php', serialData)
- .success(function(data) {
- $('#holder-'+list).html(data);
- // EXCEPTIONS ON SUCCESS
- if (list==='web-pages-rows' || list==='web-navigation-rows') {
- if (setCLIENT!=='ALL' || setSTATUS!=='ALL' || setSORT!=='ord' || setIN!=='ASC' || setSEARCH!=='') { $('.moving').hide(); }
- else { $('.moving').show(); }
- } else if (list==='inventory-ordering-rows') {
- $('.check-box').click( function() {
- var thisID = $(this).attr('alt');
- if ($(this).prop('checked') === true) {
- $('.check-in[alt="'+thisID+'"]').focus();
- } else {
- $('.check-in[alt="'+thisID+'"]').val('');
- }
- });
- $('.check-in').on('click, change', function() {
- $('.check-in').each(function(index) {
- var thisID = $(this).attr('alt');
- var thisVal = $(this).val();
- var thisNum = $.isNumeric(thisVal);
- if (thisVal < 1){
- $('.check-box[alt="'+thisID+'"]').prop('checked', false);
- } else {
- $('.check-box[alt="'+thisID+'"]').prop('checked', true);
- }
- if (thisNum === false){
- $(this).css('color', 'red');
- $('.check-box[alt="'+thisID+'"]').prop('checked', false);
- } else {
- $(this).css('color', '#575757');
- }
- });
- });
- } else if (list==='lines-rows') {
- var serialData = 'a=2&i='+parentID+'&t=1&v=1&c=1';
- $.post('/manage/forms/update.php', serialData)
- .success(function(data) {
- $('#inv_total').html('$'+data);
- })
- .error(function(data) { $.sendMsg('error'); });
- }
- })
- .error(function(data) { $.sendMsg('error'); });
- }
-
-
- $('.update-list').change( function(e){
- e.preventDefault();
- $.updatePageData(list, filter);
- });
- $('#button-search').click(function(e){
- e.preventDefault();
- $.updatePageData(list, filter);
- });
- $('.body').keyup( function (e){
- <?php if ($contents!='edit-web-page') { ?>
- if (e.keyCode === 13) { // RETURN
- e.preventDefault();
- $.updatePageData(list, filter);
- }
- <?php } ?>
- if (e.keyCode === 27) { // ESCAPE
- e.preventDefault();
- $.resetDefaults(list, filter);
- }
- });
- $('#button-reset').click(function(e){
- e.preventDefault();
- $.resetDefaults(list, filter);
- });
- };
- $.modalSafeTasks = function(taskID, projID, taskTYPE){
- if (taskID==='new') { var setTITLE = 'New Task'; } else { var setTITLE = 'Edit Task'; }
- var projStatus = $('#proj_status').val();
- if ((projStatus==='killed' || projStatus==='complete' || projStatus==='archive') && taskID==='new') {
- $.sendMsg('Error.', 'You cannot add a task to an inactive project.');
- } else {
- var serialData = 'id='+taskID+'&parent='+projID;
- $.get('/manage/forms/'+taskTYPE+'task-edit.php', serialData)
- .success(function(data) {
- $('#dialog-edit-task').html(data);
- $('#dialog-edit-task').dialog({
- title: setTITLE,
- height: 'auto',
- width: 600,
- modal: false,
- buttons: {
- 'OK': function() {
- var serialData = $('#form-edit-'+taskTYPE+'task').serialize()+'&id='+taskID+'&parent='+projID;
- $.post('/manage/forms/'+taskTYPE+'task-edit.php', serialData)
- .success(function(data) {
- if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); }
- else { $.updatePageData('tasks-rows', 'proj'); }
- $.updatePageData('tasks-stickies');
- $.updatePageData('work-tasks-rows', 'work');
- })
- .error(function(data) { $.sendMsg('error'); });
- $( this ).dialog( 'close' );
- },
- 'Cancel': function() {
- $( this ).dialog( 'close' );
- }
- }
- }).on('click', '.date', function(e){
- $(this).datepicker({
- showOn:'focus',
- dateFormat: 'yy-mm-dd',
- gotoCurrent: true
- }).focus();
- });
- })
- .error(function(data) { $.sendMsg('error'); });
- }
- };
-
- // DOCUMENT READY
- $(function() {
- $.ajaxSetup({cache: false})
- // MATCH HEIGHT AND WIDTH
- var maxWidth = 0;
- var maxHeight = 0;
- $('.match-h > span').each( function() {
- if ($(this).width() > maxWidth) {
- maxWidth = $(this).width();
- }
- }).css('width', maxWidth);
- $('.match-v > span').each( function() {
- if ($(this).height() > maxHeight) {
- maxHeight = $(this).height();
- }
- }).css('height', maxHeight);
- // LOADING ICON
- $('body').on({
- ajaxStart: function() {
- $(this).addClass('loading');
- },
- ajaxStop: function() {
- $(this).removeClass('loading');
- }
- });
- // LIVE CLICKS
- $(document)
- // DATE PICKERS
- .on('click', '.date', function(e){
- $(this).datepicker({
- showOn:'focus',
- dateFormat: 'yy-mm-dd',
- gotoCurrent: true
- }).focus();
- })
- .on('click', '.dateNaked', function(e){
- $(this).datepicker({
- showOn:'focus',
- dateFormat: 'yymmdd',
- gotoCurrent: true
- }).focus();
- })
- .on('click', '.datetime', function(e){
- $(this).datetimepicker({
- showOn:'focus',
- dateFormat: 'DD, M. d, yy,',
- timeFormat: 'h:mm tt',
- gotoCurrent: true
- }).focus();
- })
- // NOTE EDIT
- .on('click', '.button-edit-note', function(e){
- e.preventDefault();
- var noteID = $(this).attr('rel');
- var noteTYPE = $(this).attr('name');
- if (noteID==='new') { var setTITLE = 'New Note'; } else { var setTITLE = 'Edit Note'; }
- var jobID = $('#'+noteTYPE+'_id').val();
- var serialData = 'id='+noteID+'&parent='+jobID+'&type='+noteTYPE;
- $.get('/manage/forms/note-edit.php', serialData)
- .success(function(data) {
- $('#dialog-edit-note').html(data);
- $('#dialog-edit-note').dialog({
- title: setTITLE,
- height: 'auto',
- width: 450,
- modal: false,
- buttons: {
- 'OK': function() {
- var serialData = $('#form-edit-note').serialize()+'&id='+noteID+'&parent='+jobID+'&type='+noteTYPE;
- $.post('/manage/forms/note-edit.php', serialData)
- .success(function(data) {
- $('#dialog-edit-note').dialog('close');
- $.updatePageData('notes-rows', noteTYPE);
- })
- .error(function(data) { $.sendMsg('error'); });
- },
- 'Cancel': function() {
- $(this).dialog('close');
- }
- }
- });
- })
- .error(function(data) { $.sendMsg('error'); });
- })
- // DATE PICKERS THAT AUTO-SUBMIT
- .on('click', '.button-edit-task-due, .button-edit-proj-due, .button-edit-todo-due, .button-edit-work-due, .button-edit-wask-due', function(e){
- e.preventDefault();
- if ($(this).hasClass('button-edit-task-due')) { var setTYPE = 'pman_tasks'; }
- else if ($(this).hasClass('button-edit-todo-due')) { var setTYPE = 'pman_todos'; }
- else if ($(this).hasClass('button-edit-work-due')) { var setTYPE = 'work_proj'; }
- else if ($(this).hasClass('button-edit-wask-due')) { var setTYPE = 'work_task'; }
- else { var setTYPE = 'pman_projects'; }
- var itemID = $(this).attr('title');
- var itemDATE = $(this).attr('alt');
- $(this)
- .datepicker({
- onSelect: function(date) {
- var serialData = 'i='+itemID+'&t='+setTYPE+'&c=due&v='+date+'&a=1';
- $.post('/manage/forms/update.php', serialData)
- .success(function(data) {
- $.sendMsg('Thank you.', 'The due date was updated successfully.');
- if (setTYPE === 'pman_projects') {
- if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); } // project edit page?
- else { $.updatePageData('tasks-rows', 'proj'); }
- }
- else if (setTYPE === 'pman_tasks') { $.updatePageData('tasks-stickies'); }
- else if (setTYPE === 'work_proj') { $.updatePageData('work-tasks-rows'); }
- else { $.updatePageData('checklist-stickies'); }
- })
- .error(function(data) { $.sendMsg('error'); });
- },
- showOn:'focus',
- dateFormat: 'yy-mm-dd',
- gotoCurrent: true
- })
- .datepicker('setDate', itemDATE)
- .focus();
- })
- // TEAM/OWNER EDIT
- .on('click', '.input-edit-job-team, .input-edit-proj-team, .input-edit-task-team, .input-edit-mcab-team, .input-edit-work-team', function(e){
- e.preventDefault();
- var itemID = $(this).attr('title');
- var itemTEAM = $(this).attr('alt');
- if (itemID==='new') { var setTITLE = 'New Team'; } else { var setTITLE = 'Edit Team'; }
- if ($(this).hasClass('input-edit-task-team')) { var setTYPE = 'task'; }
- else if ($(this).hasClass('input-edit-proj-team')) { var setTYPE = 'proj'; }
- else if ($(this).hasClass('input-edit-mcab-team')) { var setTYPE = 'mcab'; }
- else if ($(this).hasClass('input-edit-work-team')) { var setTYPE = 'work'; }
- else { var setTYPE = 'job'; }
- var serialData = 'id='+itemID+'&team='+itemTEAM+'&type='+setTYPE;
- $.get('/manage/forms/team-edit.php', serialData)
- .success(function(data) {
- $('#dialog-edit-team').html(data);
- $('#dialog-edit-team').dialog({
- title: setTITLE,
- height: 'auto',
- width: 120,
- modal: false,
- buttons: {
- 'Done': function() {
- if ($('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').is('a')) {
- var serialData = $('#form-edit-team').serialize()+'&id='+itemID+'&team='+itemTEAM+'&type='+setTYPE;
- $.post('/manage/forms/team-edit.php', serialData)
- .success(function(data) {
- $('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').val(data);
- $.updatePageData('tasks-stickies');
- $.sendMsg('Thank you.', 'This '+setTYPE+' was updated successfully.');
- })
- .error(function(data) { $.sendMsg('error'); });
- $( this ).dialog( 'close' );
- if (typeof($('#proj_id').val())==='undefined') { $.updatePageData('tasks-rows', 'job'); $.updatePageData('jobs-rows'); } // project edit page?
- else { $.updatePageData('tasks-rows', 'proj'); }
- } else if ($('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').is('input')) {
- var sndBack = '';
- $('.team-check').each( function() {
- if ($(this).is(':checked')) {
- sndBack = $(this).attr('title')+' '+sndBack;
- }
- });
- $('.input-edit-'+setTYPE+'-team[title="'+itemID+'"]').val(sndBack);
- $( this ).dialog( 'close' );
- }
- },
- 'Cancel': function() {
- $( this ).dialog( 'close' );
- }
- }
- });
- })
- .error(function(data) { $.sendMsg('error'); });
- });
- // BODY AJAX CLICKS
- $(document) //'.body'
- // TASK EDIT
- .on('click', '.button-edit-task, .button-edit-wask', function(e){
- e.preventDefault();
- if ($(this).hasClass('button-edit-wask')) { var taskTYPE = 'work-'; }
- else { var taskTYPE = ''; }
- var taskID = $(this).attr('rel');
- var projID = $(this).attr('name');
- $.modalSafeTasks(taskID, projID, taskTYPE);
- })
- // TASK PREVIEWS
- .on('click', '.icon-box.task', function(e){
- e.preventDefault();
- var projID = $(this).attr('rel');
- var serialData = 'parent='+projID+'&type=proj';
- $.get('/manage/rows/tasks-rows.php', serialData)
- .success(function(data) {
- $('#dialog-edit-task').html(data);
- $('#dialog-edit-task .button-edit-task[rel="new"]').remove();
- $('#dialog-edit-task').dialog({
- title: 'Click to edit a task',
- height: 'auto',
- width: 'auto',
- dialog: true
- });
- $('.button-edit-task').click(function(e){
- e.preventDefault();
- var taskID = $(this).attr('rel');
- var projID = $(this).attr('name');
- $.modalSafeTasks(taskID, projID);
- })
- })
- .error(function(data) { $.sendMsg('error'); });
- })
- // SHOW DETAILS
- .on('click', '.button-show-details', function(e){
- e.preventDefault();
- var setTITLE = $('#dialog-show-details').attr('rel');
- $('#dialog-show-details').dialog({
- title: setTITLE,
- height: 'auto',
- width: 'auto',
- dialog: true
- });
- })
- // NOTE PREVIEWS
- .on('click', '.icon-box.proj-note, .icon-box.task-note, .icon-box.todo-note, .icon-box.filter-note, .icon-box.work-note', function(e){
- e.preventDefault();
- var projID = $(this).attr('rel');
- if ($(this).hasClass('task-note')) { var setTYPE = 'task'; }
- else if ($(this).hasClass('todo-note')) { var setTYPE = 'todo'; }
- else if ($(this).hasClass('filter-note')) { var setTYPE = 'filter'; }
- else if ($(this).hasClass('work-note')) { var setTYPE = 'work'; }
- else { var setTYPE = 'proj'; }
- var serialData = 'parent='+projID+'&type='+setTYPE;
- $.get('/manage/rows/notes-rows.php', serialData)
- .success(function(data) {
- $('#dialog-edit-note').html(data);
- $('#dialog-edit-note .button-edit-note[rel="new"]').remove();
- $('#dialog-edit-note').dialog({
- title: '',
- height: 'auto',
- width: 'auto',
- dialog: true
- });
- })
- .error(function(data) { $.sendMsg('error'); });
- })
- // UPDATE LOG
- .on('click', '.dialog-view-log', function(e){
- e.preventDefault();
- var itemID = $(this).attr('rel');
- var itemTYPE = $(this).attr('name');
- var serialData = 'parent='+itemID+'&type='+itemTYPE;
- $.get('/manage/rows/updates-rows.php', serialData)
- .success(function(data) {
- $('#dialog-view-log').html(data);
- $('#dialog-view-log').dialog({
- title: '',
- height: 'auto',
- width: 'auto',
- dialog: true
- });
- })
- .error(function(data) { $.sendMsg('error'); });
- })
- // MOVE STUFF
- .on('click', '.button-move', function(e){
- e.preventDefault();
- var itemID = $(this).attr('rel');
- var itemCURR = $(this).attr('title');
-
- if ($(this).hasClass('dir-up')) { var itemMOVE = 'U'; var col = '1'; var val = '1'; }
- else if ($(this).hasClass('dir-down')) { var itemMOVE = 'D'; var col = '1'; var val = '1'; }
- else if ($(this).hasClass('dir-next')) { var itemMOVE = 'N'; var col = 'tier'; var val = itemCURR; }
- else if ($(this).hasClass('dir-prev')) { var itemMOVE = 'P'; var col = 'tier'; var val = itemCURR; }
-
- if ($(this).hasClass('this-work-pri')) { var tab = 'pman_settings'; var ilist = 'work-edit-rows'; var itype = ''; }
- else if ($(this).hasClass('this-work-status')) { var tab = 'pman_settings'; var ilist = 'work-edit-rows'; var itype = ''; }
- else if ($(this).hasClass('this-work-cat')) { var tab = 'pman_settings'; var ilist = 'work-edit-rows'; var itype = ''; }
- else if ($(this).hasClass('this-work-client')) { var tab = 'pman_settings'; var ilist = 'work-edit-rows'; var itype = ''; }
- else if ($(this).hasClass('this-todo-lane')) { var tab = 'pman_settings'; var ilist = 'checklist-edit'; var itype = ''; }
- else if ($(this).hasClass('this-todo-label')) { var tab = 'pman_settings'; var ilist = 'checklist-edit'; var itype = ''; }
- else if ($(this).hasClass('this-web-survey-question')) { var tab = 'site_survey_questions'; var ilist = 'web-survey-questions-rows'; var itype = 'survey'; }
- else if ($(this).hasClass('this-web-form-question')) { var tab = 'site_form_questions'; var ilist = 'web-form-questions-rows'; var itype = 'form'; }
- else if ($(this).hasClass('this-web-page')) { var tab = 'site_page'; var ilist = 'web-pages-rows'; var itype = ''; }
- else if ($(this).hasClass('this-web-nav')) { var tab = 'site_nav'; var ilist = 'web-navigation-rows'; var itype = ''; }
-
- $.quickUpdate(tab, col, val, itemID, itemMOVE, ilist, itype);
- })
- // EDIT DIALOGS
- .on('click', '.button-edit-item', function(e){
- e.preventDefault();
-
- if ($(this).hasClass('this-line')) { var itemTYPE = 'line'; var parentTYPE = 'cost'; }
- else if ($(this).hasClass('this-web-redirect')) { var itemTYPE = 'web-redirect'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-show-date')) { var itemTYPE = 'show-date'; var parentTYPE = 'show'; }
- else if ($(this).hasClass('this-web-survey-question')) { var itemTYPE = 'web-survey-question'; var parentTYPE = 'survey'; }
- else if ($(this).hasClass('this-web-survey-option')) { var itemTYPE = 'web-survey-option'; var parentTYPE = 'survey'; }
- else if ($(this).hasClass('this-web-form-question')) { var itemTYPE = 'web-form-question'; var parentTYPE = 'form'; }
- else if ($(this).hasClass('this-web-form-option')) { var itemTYPE = 'web-form-option'; var parentTYPE = 'form'; }
- else if ($(this).hasClass('this-web-traffic-filter')) { var itemTYPE = 'web-traffic-filter'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-login')) { var itemTYPE = 'login'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-todo-lane')) { var itemTYPE = 'todo-lane'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-todo-label')) { var itemTYPE = 'todo-label'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-checklist')) { var itemTYPE = 'checklist'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-inventory-order')) { var itemTYPE = 'inventory-order'; var parentTYPE = 'mcab'; }
- else if ($(this).hasClass('this-work-pri')) { var itemTYPE = 'work-pri'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-work-status')) { var itemTYPE = 'work-status'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-work-cat')) { var itemTYPE = 'work-cat'; var parentTYPE = ''; }
- else if ($(this).hasClass('this-work-client')) { var itemTYPE = 'work-client'; var parentTYPE = ''; }
- else { $.sendMsg('error'); }
-
- var itemID = $(this).attr('rel');
- var itemOLD = $(this).attr('alt');
- if ($(this).hasClass('complete')) { var itemSTATUS = 'yes'; } else { var itemSTATUS = 'no'; }
- var parentTHIS = '#'+parentTYPE+'_id';
- var parentID = $(parentTHIS).val();
- if ($(this).attr('name')>0) { var parentID = $(this).attr('name'); }
-
- if (itemID==='new') { var setTITLE = 'New'; } else { var setTITLE = 'Edit'; }
- var serialData = 'id='+itemID+'&parent='+parentID+'&old='+itemOLD+'&approved='+itemSTATUS;
- $.get('/manage/forms/'+itemTYPE+'-edit.php', serialData)
- .success(function(data) {
- $('#dialog-edit-'+itemTYPE).html(data);
- $('#dialog-edit-'+itemTYPE).dialog({
- title: setTITLE,
- height: 'auto',
- width: 550,
- modal: false,
- buttons: {
- 'OK': function() {
- var serialData = $('#form-edit-'+itemTYPE).serialize()+'&id='+itemID+'&parent='+parentID+'&old='+itemOLD+'&approved='+itemSTATUS;
- $.post('/manage/forms/'+itemTYPE+'-edit.php', serialData)
- .success(function(data) {
- $('#dialog-edit-'+itemTYPE).dialog('close');
- if (itemTYPE === 'checklist') { $.updatePageData('checklist-stickies'); }
- else if (itemTYPE === 'todo-lane' || itemTYPE === 'todo-label') { $.updatePageData('checklist-edit'); }
- else if (itemTYPE === 'web-survey-option') { $.updatePageData('web-survey-questions-rows', parentTYPE); }
- else if (itemTYPE === 'web-form-option') { $.updatePageData('web-form-questions-rows', parentTYPE); }
- else if (itemTYPE === 'inventory-order') { document.location.href='/manage/edit-inventory/'+parentID }
- else if (
- itemTYPE === 'work-cat' ||
- itemTYPE === 'work-client' ||
- itemTYPE === 'work-pri' ||
- itemTYPE === 'work-status'
- ) { $.updatePageData('work-edit-rows'); }
- else { $.updatePageData(itemTYPE+'s-rows', parentTYPE); }
- })
- .error(function(data) { $.sendMsg('error'); });
- },
- 'Cancel': function() {
- $(this).dialog('close');
- }
- }
- }).on('click', '.date', function(e){
- $(this).datepicker({
- showOn:'focus',
- dateFormat: 'yy-mm-dd',
- gotoCurrent: true
- }).focus();
- });
- if (itemTYPE === 'line') {
- $('.line-amt, .line-price, .line-total').on('change', function() {
- var amt = $('.line-amt').val();
- var pri = $('.line-price').val();
- var tot = amt * pri;
- $('.line-total').val(tot);
- });
- }
- })
- .error(function(data) { $.sendMsg('error'); });
- });
- // NOTIFICATIONS
- $('.notify-accepted').click( function(e){
- e.preventDefault();
- var itemID = $(this).attr('rel');
- var serialData = 'i='+itemID+'&t=log_notify&c=status&v=accepted&a=1';
- $.post('/manage/forms/update.php', serialData)
- .success(function(data) {
- countNotify--;
- $('#notify-on').text(countNotify);
- $('.notify-accepted[rel="'+itemID+'"]').closest('p').remove();
- })
- .error(function(data) { $.sendMsg('error'); });
- });
- // DRAG AND DROP LANES
- <?php if (($contents=='checklist' || $contents=='tasks') && $mobility=='desktop') { ?>
- $('#trello').on('hover', '.drag-it', function () {
- $(this).draggable({ revert: 'invalid' });
- var itemID = $(this).attr('id');
- if ($(this).hasClass('task')) { var thisTYPE = 'task'; var thisSTATUS = 'complete'; }
- else if ($(this).hasClass('todo')) { var thisTYPE = 'todo'; var thisSTATUS = '<?php echo $final_status_id; ?>'; }
- <?php
- pg_result_seek($result, 0);
- while ($lane = pg_fetch_array($result)) { ?>
- $('.drop-it.<?php echo $lane['alt']; ?>').droppable({
- greedy: true,
- hoverClass: 'drop-hover',
- drop: function( event, ui ) {
- var serialData = 'i='+itemID+'&t=pman_'+thisTYPE+'s&c=status&v=<?php echo $lane['id']; ?>&a=1';
- $.post('/manage/forms/update.php', serialData)
- .error(function(data) { $.sendMsg('error'); });
- if (thisTYPE==='todo') { $.updatePageData('checklist-stickies'); }
- else if (thisTYPE==='task') { $.updatePageData('tasks-stickies'); }
- }
- });<?php
- } ?>
- $('.trash').droppable({
- greedy: true,
- hoverClass: 'drop-hover',
- drop: function( event, ui ) {
- var serialData = 'i='+itemID+'&t=pman_'+thisTYPE+'s&c=status&v='+thisSTATUS+'&a=1';
- $.post('/manage/forms/update.php', serialData)
- .error(function(data) { $.sendMsg('error'); });
- if (thisTYPE==='todo') { $.updatePageData('checklist-stickies'); }
- else if (thisTYPE==='task') { $.updatePageData('tasks-stickies'); }
- }
- });
- });
- <?php } ?>
- // BUTTONS
- $(document).keydown(function(event) {
- if (!( String.fromCharCode(event.which).toLowerCase() == 's' && event.metaKey) && !(event.which == 19)) return true;
- $('.auto-save').trigger('click');
- event.preventDefault();
- return false;
- }).keydown(function(event) {
- if (!( String.fromCharCode(event.which).toLowerCase() == 's' && event.ctrlKey) && !(event.which == 19)) return true;
- $('.auto-save').trigger('click');
- event.preventDefault();
- return false;
- });
- $('#button-toggle-lanes').click(function(e){
- e.preventDefault();
- $('#trello #killed, #trello #complete').toggle();
- });
- $('#button-save-main-form').click( function(e){
- e.preventDefault();
- var sch = $(this).attr('title');
- var frm = $(this).attr('name');
- var req1 = $('#req1').val();
- var err1 = $('#req1').attr('alt');
- var req2 = $('#req2').val();
- var err2 = $('#req2').attr('alt');
- if ($('#'+sch+'_id').val() === '') { alert('ID!'); }
- else {
- if ($('#'+sch+'_'+req1).val() === '' && req1!=='') {
- $.sendMsg('Not enough information.', 'You must enter '+err1+'.');
- } else if ($('#'+sch+'_'+req2).val() === '' && req2!=='') {
- $.sendMsg('Not enough information.', 'You must enter '+err2+'.');
- } else {
- var serialData = $('#form-edit-'+frm).serialize();
- $.post('/manage/forms/'+frm+'-edit.php', serialData)
- .success(function(data) {
- if ($('#'+sch+'_id').val() === 'new') { document.location.href='/manage/edit-'+frm+'/'+data; }
- else {
- $.sendMsg('Thank you.', 'Updated successfully.');
- $.updatePageData('tasks-rows', sch);
- $.updatePageData('notes-rows', sch);
- $.updatePageData('costs-rows', sch);
- $.updatePageData('links-rows', sch);
- }
- })
- .error(function(data) { $.sendMsg('error'); });
- }
- }
- });
- }); // DOC READY
- </script>