From 10c6e254bb88910e372a8ec8ccb7a5b6f72b44f1 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 31 Mar 2015 17:47:41 -0500 Subject: [PATCH] user: Add set organization mass action --- include/ajax.orgs.php | 10 +++++++--- include/class.user.php | 4 ++-- include/staff/users.inc.php | 27 ++++++++++++++++++++++++--- scp/ajax.php | 2 +- scp/js/scp.js | 4 +++- scp/users.php | 9 +++++++++ 6 files changed, 46 insertions(+), 10 deletions(-) diff --git a/include/ajax.orgs.php b/include/ajax.orgs.php index 54ea1dc7f..ea7dc6f14 100644 --- a/include/ajax.orgs.php +++ b/include/ajax.orgs.php @@ -211,11 +211,11 @@ class OrgsAjaxAPI extends AjaxController { $info['title'] = __('Add New Organization'); $info['search'] = false; - return self::_lookupform($form, $info); + return $this->_lookupform($form, $info); } function lookup() { - return self::_lookupform(); + return $this->_lookupform(); } function selectOrg($id) { @@ -241,11 +241,15 @@ class OrgsAjaxAPI extends AjaxController { return $ajax->createNote('O'.$id); } - static function _lookupform($form=null, $info=array()) { + function _lookupform($form=null, $info=array()) { if (!$info or !$info['title']) $info += array('title' => __('Organization Lookup')); + if ($_POST && ($org = Organization::lookup($_POST['orgid']))) { + Http::response(201, $org->to_json()); + } + ob_start(); include(STAFFINC_DIR . 'templates/org-lookup.tmpl.php'); $resp = ob_get_contents(); diff --git a/include/class.user.php b/include/class.user.php index a6f996002..886c18db9 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -840,12 +840,12 @@ class UserAccountModel extends VerySimpleModel { function lock() { $this->setStatus(UserAccountStatus::LOCKED); - $this->save(); + return $this->save(); } function unlock() { $this->clearStatus(UserAccountStatus::LOCKED); - $this->save(); + return $this->save(); } function isLocked() { diff --git a/include/staff/users.inc.php b/include/staff/users.inc.php index be1739ec9..900651ea4 100644 --- a/include/staff/users.inc.php +++ b/include/staff/users.inc.php @@ -112,6 +112,13 @@ $_SESSION['users_qs_'.$qhash] = $query; <li><a class="users-action" href="#delete"> <i class="icon-trash icon-fixed-width"></i> <?php echo __('Delete'); ?></a></li> + <li><a href="#orgs/lookup/form" onclick="javascript: +$.dialog('ajax.php/orgs/lookup/form', 201); +return false;"> + <i class="icon-group icon-fixed-width"></i> + <?php echo __('Add to Organization'); ?></a></li> +<?php +if ('disabled' != $cfg->getClientRegistrationMode()) { ?> <li><a class="users-action" href="#reset"> <i class="icon-envelope icon-fixed-width"></i> <?php echo __('Send Password Reset Email'); ?></a></li> @@ -124,6 +131,7 @@ $_SESSION['users_qs_'.$qhash] = $query; <li><a class="users-action" href="#unlock"> <i class="icon-unlock icon-fixed-width"></i> <?php echo __('Unlock'); ?></a></li> +<?php } # end of registration-enabled? ?> </ul> </div> </div> @@ -142,6 +150,7 @@ else <input type="hidden" name="do" value="mass_process" > <input type="hidden" id="action" name="a" value="" > <input type="hidden" id="selected-count" name="count" value="" > + <input type="hidden" id="org_id" name="org_id" value="" > <table class="list" border="0" cellspacing="1" cellpadding="0" width="940"> <caption><?php echo $showing; ?></caption> <thead> @@ -240,15 +249,14 @@ $(function() { return false; }); - $(document).on('click', 'a.users-action', function(e) { - e.preventDefault(); + var goBaby = function(action) { var ids = [], $form = $('form#users-list'); $(':checkbox.mass:checked', $form).each(function() { ids.push($(this).val()); }); if (ids.length && confirm(__('You sure?'))) { - $form.find('#action').val($(this).attr('href').substr(1)); + $form.find('#action').val(action); $.each(ids, function() { $form.append($('<input type="hidden" name="ids[]">').val(this)); }); $form.find('#selected-count').val(ids.length); $form.submit(); @@ -257,8 +265,21 @@ $(function() { $.sysAlert(__('Oops'), __('You need to select at least one item')); } + }; + $(document).on('click', 'a.users-action', function(e) { + e.preventDefault(); + goBaby($(this).attr('href').substr(1)); return false; }); + $(document).on('dialog:close', function(e, json) { + $form = $('form#users-list'); + try { + var json = $.parseJSON(json); + $form.find('#org_id').val(json.id); + goBaby('setorg'); + } + catch (e) { console.log(e); } + }); }); </script> diff --git a/scp/ajax.php b/scp/ajax.php index 116851360..613473125 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -107,7 +107,7 @@ $dispatcher = patterns('', url_post('^/(?P<id>\d+)/profile$', 'updateOrg', array(true)), url_get('^/(?P<id>\d+)/edit$', 'editOrg'), url_get('^/lookup/form$', 'lookup'), - url_post('^/lookup/form$', 'addOrg'), + url_post('^/lookup$', 'lookup'), url_get('^/add$', 'addOrg'), url_post('^/add$', 'addOrg'), url_get('^/select$', 'selectOrg'), diff --git a/scp/js/scp.js b/scp/js/scp.js index f3d9ab3e1..02fe02c6b 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -570,12 +570,14 @@ $.dialog = function (url, codes, cb, options) { data: $form.serialize(), cache: false, success: function(resp, status, xhr) { + var done = $.Event('dialog:close'); if (xhr && xhr.status && codes && $.inArray(xhr.status, codes) != -1) { $.toggleOverlay(false); $popup.hide(); $('div.body', $popup).empty(); - if(cb) cb(xhr); + if(cb) cb(xhr, resp); + $popup.trigger(done, [resp, status, xhr]); } else { $('div.body', $popup).html(resp); $popup.effect('shake'); diff --git a/scp/users.php b/scp/users.php index f9915606d..bf5140215 100644 --- a/scp/users.php +++ b/scp/users.php @@ -111,6 +111,15 @@ if ($_POST) { } break; + case 'setorg': + if (!($org = Organization::lookup($_POST['org_id']))) + $errors['err'] = __('Unknown action - get technical help.'); + foreach ($users as $U) { + if ($U->setOrganization($org)) + $count++; + } + break; + default: $errors['err']=__('Unknown action - get technical help.'); } -- GitLab