diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index efadebca3587ecb338a9ce6f26fcc3da16f79b84..93e90758c2963eebcefa43518b757e5c473d8eef 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -457,6 +457,10 @@ class TicketsAjaxAPI extends AjaxController { || !$ticket->checkStaffAccess($thisstaff)) Http::response(404, 'No such ticket'); + //If not a post then assume new collaborator form + if(!$_POST) + return self::_addcollaborator($ticket); + $user = $form = null; if (isset($_POST['id']) && $_POST['id']) { //Existing user/ $user = User::lookup($_POST['id']); @@ -465,17 +469,22 @@ class TicketsAjaxAPI extends AjaxController { $user = User::fromForm($form); } + $errors = $info = array(); if ($user && ($c=$ticket->addCollaborator($user, $errors))) { - $info +=array('msg' => sprintf('%s added as a collaborator', + $info =array('msg' => sprintf('%s added as a collaborator', $c->getName())); - $form = null; - } elseif($errors && $errors['err']) { - $info +=array('add_error' => $errors['err']); + + return self::_collaborators($ticket, $info); + } + + if($errors && $errors['err']) { + $info +=array('error' => $errors['err']); } else { - $info +=array('add_error' =>'Errors occurred - try again'); + $info +=array('error' =>'Unable to add collaborator - try again'); } - return self::_collaborators($ticket, $form, $info); + + return self::_addcollaborator($ticket, $user, $form, $info); } function updateCollaborator($cid) { @@ -495,7 +504,7 @@ class TicketsAjaxAPI extends AjaxController { $info = array('msg' => sprintf('%s updated successfully', $c->getName())); - return self::_collaborators($ticket, null, $info); + return self::_collaborators($ticket, $info); } function viewCollaborator($cid) { @@ -516,7 +525,22 @@ class TicketsAjaxAPI extends AjaxController { || !$ticket->checkStaffAccess($thisstaff)) Http::response(404, 'No such ticket'); - return self::_collaborators($ticket); + if($ticket->getCollaborators()) + return self::_collaborators($ticket); + + return self::_addcollaborator($ticket); + } + + + + function _addcollaborator($ticket, $user=null, $form=null, $info=array()) { + + $info += array( + 'title' => sprintf('Ticket #%s: Add a collaborator', $ticket->getNumber()), + 'action' => sprintf('#tickets/%d/add-collaborator', $ticket->getId()) + ); + + return self::_userlookup($user, $form, $info); } @@ -534,22 +558,26 @@ class TicketsAjaxAPI extends AjaxController { $info +=array('error' => $errors['err']); } - return self::_collaborators($ticket, null, $info); + return self::_collaborators($ticket, $info); } - function _collaborator($collaborator, $form=null, $errors=array()) { + function _collaborator($collaborator, $form=null, $info=array()) { + + $info += array('action' => '#collaborators/'.$collaborator->getId()); + + $user = $collaborator->getUser(); ob_start(); - include(STAFFINC_DIR . 'templates/collaborator.tmpl.php'); + include(STAFFINC_DIR . 'templates/user.tmpl.php'); $resp = ob_get_contents(); ob_end_clean(); return $resp; } - function _collaborators($ticket, $form=null, $info=array()) { + function _collaborators($ticket, $info=array()) { ob_start(); include(STAFFINC_DIR . 'templates/collaborators.tmpl.php'); @@ -626,6 +654,11 @@ class TicketsAjaxAPI extends AjaxController { 'title' => sprintf('Change user for ticket #%s', $ticket->getNumber()) ); + return self::_userlookup($user, $info); + } + + function _userlookup($user, $form, $info) { + ob_start(); include(STAFFINC_DIR . 'templates/user-lookup.tmpl.php'); $resp = ob_get_contents(); diff --git a/include/class.user.php b/include/class.user.php index 85a01d784b52f0084ed6a6504a754da05606b13b..85bffe026d3769715c466219d487749de92f6fca 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -76,7 +76,7 @@ class User extends UserModel { $this->default_email = UserEmail::lookup($ht['default_email_id']); } - static function fromVars($vars=false) { + static function fromVars($vars) { // Try and lookup by email address $user = User::lookup(array('emails__address'=>$vars['email'])); if (!$user) { diff --git a/include/staff/templates/collaborators.tmpl.php b/include/staff/templates/collaborators.tmpl.php index 385daa01dfb9b9a4fecff8cafee0545bcd312b55..a10bf0c105b5d9ea5a116a09600d66ac29ca93eb 100644 --- a/include/staff/templates/collaborators.tmpl.php +++ b/include/staff/templates/collaborators.tmpl.php @@ -7,7 +7,7 @@ if($info && $info['msg']) { <hr/> <?php if(($users=$ticket->getCollaborators())) {?> -<div id="manage_collaborators" <?php echo $form? 'style="display:none;"' : ''; ?>> +<div id="manage_collaborators"> <form method="post" class="collaborators" action="#tickets/<?php echo $ticket->getId(); ?>/collaborators"> <table border="0" cellspacing="1" cellpadding="1" width="100%"> <?php @@ -16,7 +16,7 @@ if(($users=$ticket->getCollaborators())) {?> echo sprintf('<tr> <td> <input type="checkbox" name="cid[]" id="c%d" value="%d" %s> - <a class="editcollaborator" href="#collaborators/%d/view">%s</a> + <a class="collaborator" href="#collaborators/%d/view">%s</a> <span class="faded"><em>%s</em></span></td> <td width="10"> <input type="hidden" name="del[]" id="d%d" value=""> @@ -35,7 +35,8 @@ if(($users=$ticket->getCollaborators())) {?> ?> </table> <hr style="margin-top:1em"/> - <div><a id="addcollaborator" href="#" >Add New Collaborator</a></div> + <div><a class="collaborator" + href="#tickets/<?php echo $ticket->getId(); ?>/add-collaborator" >Add New Collaborator</a></div> <div id="savewarning" style="display:none; padding-top:2px;"><p id="msg_warning">You have made changes that you need to save.</p></div> <p class="full-width"> <span class="buttons" style="float:left"> @@ -50,31 +51,7 @@ if(($users=$ticket->getCollaborators())) {?> <div class="clear"></div> </div> <?php +} else { + echo "Bro, not sure how you got here!"; } ?> -<div id="add_collaborator" <?php echo ($users && !$form)? 'style="display:none;"' : ''; ?>> -<?php -if($info && $info['add_error']) { ?> -<p id="msg_error"><?php echo $info['add_error']; ?></p> -<?php -} ?> -<div>Please complete the form below to add a new collaborator.</div> -<form method="post" class="collaborators" action="#tickets/<?php echo $ticket->getId(); ?>/collaborators/add"> - <table width="100%"> - <?php - if(!$form) $form = UserForm::getInstance(); - $form->render(); ?> - </table> - <hr style="margin-top:1em"/> - <p class="full-width"> - <span class="buttons" style="float:left"> - <input type="reset" value="Reset"> - <input type="button" name="cancel" class="<?php echo !$users ? 'close': 'cancel'; ?>" value="Cancel"> - </span> - <span class="buttons" style="float:right"> - <input type="submit" value="Add"> - </span> - </p> -</form> -<div class="clear"></div> -</div> diff --git a/include/staff/templates/user-lookup.tmpl.php b/include/staff/templates/user-lookup.tmpl.php index de8dedb4e79b8d513dedf64c5134d6f1a579f783..8a6edd8f8771ca1cd583f3d1801eb1f72925969d 100644 --- a/include/staff/templates/user-lookup.tmpl.php +++ b/include/staff/templates/user-lookup.tmpl.php @@ -10,7 +10,7 @@ if ($info['error']) { echo sprintf('<p id="msg_notice">%s</p>', $info['msg']); } ?> <div id="selected-user-info" style="display:<?php echo $user ? 'block' :'none'; ?>;margin:5px;"> -<form method="get" class="user" action="#users/lookup"> +<form method="post" class="user" action="<?php echo $info['action'] ? $info['action'] : '#users/lookup'; ?>"> <input type="hidden" id="user-id" name="id" value="<?php echo $user ? $user->getId() : 0; ?>"/> <i class="icon-user icon-4x pull-left icon-border"></i> <a class="action-button pull-right" style="overflow:inherit" @@ -30,7 +30,7 @@ if ($info['error']) { </form> </div> <div id="new-user-form" style="display:<?php echo $user ? 'none' :'block'; ?>;"> -<form method="post" class="user" action="#users/lookup/form"> +<form method="post" class="user" action="<?php echo $info['action'] ? $info['action'] : '#users/lookup/form'; ?>"> <table width="100%"> <?php if(!$form) $form = UserForm::getInstance(); diff --git a/include/staff/templates/user.tmpl.php b/include/staff/templates/user.tmpl.php index 92bbe3754effd5161a51e2f3a1ebca4d9e65c910..37528cc52d13deff96f20c7062231503c43ec45a 100644 --- a/include/staff/templates/user.tmpl.php +++ b/include/staff/templates/user.tmpl.php @@ -30,7 +30,7 @@ if ($info['error']) { <div id="user-form" style="display:<?php echo $forms ? 'block' : 'none'; ?>;"> <div><p id="msg_info"><i class="icon-info-sign"></i> Please note that updates will be reflected system-wide.</p></div> <?php -$action = '#users/'.$user->getId(); +$action = $info['action'] ? $info['action'] : ('#users/'.$user->getId()); if ($ticket && $ticket->getOwnerId() == $user->getId()) $action = '#tickets/'.$ticket->getId().'/user'; ?> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index a98c90bd075c1dc5602d6e2b954d6924b04ef770..3866de15be2f54303d12e983e5d6dab78dce8042 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -438,12 +438,12 @@ $tcount+= $ticket->getNumNotes(); <input type='checkbox' value='1' name="emailcollab" id="emailcollab" <?php echo ((!$info['emailcollab'] && !$errors) || isset($info['emailcollab']))?'checked="checked"':''; ?>> <?php - echo sprintf('<a id="managecollaborators" + echo sprintf('<a class="collaborators" href="#tickets/%d/collaborators/manage">Collaborators (%d)</a>', $ticket->getId(), $ticket->getNumCollaborators()); } else { - echo sprintf('<div><a id="addcollaborators" + echo sprintf('<div><a class="collaborators" href="#tickets/%d/collaborators/manage" >Add Collaborators</a></div>', $ticket->getId()); } @@ -821,9 +821,6 @@ $tcount+= $ticket->getNumNotes(); <?php } ?> </div> -<div style="display:none;width:650px;" class="dialog draggable collaborators"> - <div class="body"></div> -</div> <div style="display:none;" class="dialog" id="print-options"> <h3>Ticket Print Options</h3> <a class="close" href=""><i class="icon-remove-circle"></i></a> diff --git a/scp/ajax.php b/scp/ajax.php index ad152cdfb6d4a8075458d8ada5644c9b2fd438ac..eaca914dbcc67c9834839fd74ab98265339d315b 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -77,7 +77,8 @@ $dispatcher = patterns('', url_post('^(?P<tid>\d+)/lock/(?P<id>\d+)/release', 'releaseLock'), url_get('^(?P<tid>\d+)/collaborators/manage$', 'showCollaborators'), url_post('^(?P<tid>\d+)/collaborators$', 'updateCollaborators'), - url_post('^(?P<tid>\d+)/collaborators/add$', 'addCollaborator'), + url_post('^(?P<tid>\d+)/add-collaborator$', 'addCollaborator'), + url_get('^(?P<tid>\d+)/add-collaborator$', 'addCollaborator'), url_get('^lookup', 'lookup'), url_get('^search', 'search') )), diff --git a/scp/js/ticket.js b/scp/js/ticket.js index b063edd5f16b819af19496d0fb25109c1957720c..c91cacaa9eff51205a25265bdfa210d5e7c3864f 100644 --- a/scp/js/ticket.js +++ b/scp/js/ticket.js @@ -364,14 +364,11 @@ jQuery(function($) { }); //Collaborators - $(document).on('click', 'a#managecollaborators, a#addcollaborators, a.editcollaborator', function(e) { + $(document).on('click', 'a.collaborator, a.collaborators', function(e) { e.preventDefault(); - var target = $(this).attr('href').substr(1); - $('.dialog.collaborators .body').load('ajax.php/'+target, function () { - $('#overlay').show(); - $('.dialog.collaborators').show(); - }); - + var url = 'ajax.php/'+$(this).attr('href').substr(1); + $.dialog(url, 201, function (resp) { + }); return false; }); @@ -432,24 +429,6 @@ jQuery(function($) { $cc.show(); }); - $(document).on('submit', 'form.collaborators', function(e) { - e.preventDefault(); - var fObj = $(this); - $.ajax({ - type: "POST", - url: 'ajax.php/'+fObj.attr('action').substr(1), - data: fObj.serialize(), - cache: false, - success: function(resp){ - $('.dialog.collaborators .body').html(resp); - $('#msg_notice, #msg_error').delay(5000).fadeOut(); - } - }) - .done(function() { }) - .fail(function() { }); - return false; - }); - var showNonLocalImage = function(div) { var $div = $(div), $img = $div.append($('<img>')