From b5525a7e5875f57ae2454609e5d3c9aa166318bb Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 25 Apr 2014 10:26:30 -0500 Subject: [PATCH] Move createNote to respective objects (user and org) --- include/ajax.orgs.php | 9 +++++++++ include/ajax.users.php | 9 +++++++++ include/staff/org-view.inc.php | 2 +- include/staff/templates/notes.tmpl.php | 2 +- include/staff/templates/user.tmpl.php | 3 ++- include/staff/user-view.inc.php | 2 +- scp/ajax.php | 6 ++++-- scp/js/scp.js | 2 +- 8 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/ajax.orgs.php b/include/ajax.orgs.php index 9a72c2044..faf8b38cf 100644 --- a/include/ajax.orgs.php +++ b/include/ajax.orgs.php @@ -205,6 +205,15 @@ class OrgsAjaxAPI extends AjaxController { } + function createNote($id) { + if (!($org = Organization::lookup($id))) + Http::response(404, 'Unknown organization'); + + require_once INCLUDE_DIR . 'ajax.note.php'; + $ajax = new NoteAjaxAPI(); + return $ajax->createNote('O'.$id); + } + static function _lookupform($form=null, $info=array()) { if (!$info or !$info['title']) diff --git a/include/ajax.users.php b/include/ajax.users.php index 1fbe7fe60..410c6ce9c 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -349,5 +349,14 @@ class UsersAjaxAPI extends AjaxController { return $resp; } + function createNote($id) { + if (!($user = User::lookup($id))) + Http::response(404, 'Unknown user'); + + require_once INCLUDE_DIR . 'ajax.note.php'; + $ajax = new NoteAjaxAPI(); + return $ajax->createNote('U'.$id); + } + } ?> diff --git a/include/staff/org-view.inc.php b/include/staff/org-view.inc.php index 5f040395f..5e334c12b 100644 --- a/include/staff/org-view.inc.php +++ b/include/staff/org-view.inc.php @@ -70,7 +70,7 @@ include STAFFINC_DIR . 'templates/tickets.tmpl.php'; <div class="tab_content" id="notes" style="display:none"> <?php $notes = QuickNote::forOrganization($org); -$ext_id = 'O'.$org->getId(); +$create_note_url = 'orgs/'.$org->getId().'/note'; include STAFFINC_DIR . 'templates/notes.tmpl.php'; ?> </div> diff --git a/include/staff/templates/notes.tmpl.php b/include/staff/templates/notes.tmpl.php index dca647715..360c519fe 100644 --- a/include/staff/templates/notes.tmpl.php +++ b/include/staff/templates/notes.tmpl.php @@ -5,7 +5,7 @@ foreach ($notes as $note) { include STAFFINC_DIR."templates/note.tmpl.php"; } ?> </div> -<div class="quicknote" id="new-note" data-ext-id="<?php echo $ext_id; ?>"> +<div class="quicknote" id="new-note" data-url="<?php echo $create_note_url; ?>"> <div class="body"> <a href="#"><i class="icon-plus icon-large"></i> Click to create a new note</a> </div> diff --git a/include/staff/templates/user.tmpl.php b/include/staff/templates/user.tmpl.php index abc451170..0f2a930d5 100644 --- a/include/staff/templates/user.tmpl.php +++ b/include/staff/templates/user.tmpl.php @@ -91,7 +91,8 @@ if ($info['error']) { foreach ($notes as $note) include STAFFINC_DIR . 'templates/note.tmpl.php'; ?> -<div class="quicknote no-options" id="new-note" data-ext-id="U<?php echo $user->getId(); ?>"> +<div class="quicknote no-options" id="new-note" + data-url="users/<?php echo $user->getId(); ?>/note"> <div class="body"> <a href="#"><i class="icon-plus icon-large"></i> Click to create a new note</a> </div> diff --git a/include/staff/user-view.inc.php b/include/staff/user-view.inc.php index 69cb2a558..4b267a9cc 100644 --- a/include/staff/user-view.inc.php +++ b/include/staff/user-view.inc.php @@ -131,7 +131,7 @@ include STAFFINC_DIR . 'templates/tickets.tmpl.php'; <div class="tab_content" id="notes" style="display:none"> <?php $notes = QuickNote::forUser($user); -$ext_id = 'U'.$user->getId(); +$create_note_url = 'users/'.$user->getId().'/note'; include STAFFINC_DIR . 'templates/notes.tmpl.php'; ?> </div> diff --git a/scp/ajax.php b/scp/ajax.php index a445bfeb9..20fddfc72 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -89,7 +89,8 @@ $dispatcher = patterns('', url_post('^/(?P<id>\d+)/manage(?:/(?P<target>\w+))?$', 'manage'), url_get('^/(?P<id>\d+)/org(?:/(?P<orgid>\d+))?$', 'updateOrg'), url_post('^/(?P<id>\d+)/org$', 'updateOrg'), - url_get('^/staff$', 'searchStaff') + url_get('^/staff$', 'searchStaff'), + url_post('^/(?P<id>\d+)/note$', 'createNote') )), url('^/orgs', patterns('ajax.orgs.php:OrgsAjaxAPI', url_get('^$', 'search'), @@ -108,7 +109,8 @@ $dispatcher = patterns('', url_get('^/(?P<id>\d+)/add-user(?:/auth:(?P<userid>.+))?$', 'addUser', array(true)), url_post('^/(?P<id>\d+)/add-user$', 'addUser'), url_get('^/(?P<id>\d+)/delete$', 'delete'), - url_delete('^/(?P<id>\d+)/delete$', 'delete') + url_delete('^/(?P<id>\d+)/delete$', 'delete'), + url_post('^/(?P<id>\d+)/note$', 'createNote') )), url('^/tickets/', patterns('ajax.tickets.php:TicketsAjaxAPI', url_get('^(?P<tid>\d+)/change-user$', 'changeUserForm'), diff --git a/scp/js/scp.js b/scp/js/scp.js index 3712f8904..489cc72ae 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -728,7 +728,7 @@ $('#new-note').live('click', function() { T = $('<textarea>'), button = $('<input type="button">').val('Create'); button.click(function() { - $.post('ajax.php/note/attach/' + note.data('extId'), + $.post('ajax.php/' + note.data('url'), { note: T.redactor('get'), no_options: note.hasClass('no-options') }, function(response) { $(T).redactor('destroy').replaceWith(note); -- GitLab