From 9a22364fcf059f48e08f02270daebc3a389e5908 Mon Sep 17 00:00:00 2001 From: Chris Brame Date: Fri, 4 Jan 2019 00:19:21 -0500 Subject: [PATCH] fix(tags): tags with min2 were not creating --- src/public/js/angularjs/controllers/common.js | 47 +++++++++++++++++++ .../js/angularjs/controllers/settings.js | 35 -------------- .../js/angularjs/controllers/singleTicket.js | 42 ----------------- src/public/js/modules/ajaxify.js | 2 +- src/views/partials/createTagWindow.hbs | 4 +- src/views/settings.hbs | 4 +- src/views/subviews/singleticket.hbs | 21 ++------- 7 files changed, 56 insertions(+), 99 deletions(-) diff --git a/src/public/js/angularjs/controllers/common.js b/src/public/js/angularjs/controllers/common.js index 31b88de92..27b27253a 100644 --- a/src/public/js/angularjs/controllers/common.js +++ b/src/public/js/angularjs/controllers/common.js @@ -16,6 +16,53 @@ define(['angular', 'underscore', 'jquery', 'modules/socket', 'uikit', 'modules/t return angular.module('trudesk.controllers.common', ['trudesk.controllers.messages']) .controller('commonCtrl', function($scope, $window, $http, $cookies, $timeout, $log) { + $scope.showCreateTagWindow = function($event) { + $event.preventDefault(); + var createTagModal = $('#createTagModal'); + if (createTagModal.length > 0) + UI.modal(createTagModal, {bgclose: false}).show(); + }; + + $scope.createTag = function(page, $event) { + $event.preventDefault(); + var form = $('#createTagForm'); + if (!form.isValid(null, null, false)) + return true; + else { + var tagName = form.find('input[name="tagName"]').val(); + if (!tagName || tagName.length < 2) return true; + + $http.post('/api/v1/tags/create', { + tag: tagName + }, { + headers: { + 'Content-Type': 'application/json' + } + }).then(function successCallback(response) { + var data = response.data; + helpers.UI.showSnackbar('Tag: ' + tagName + ' created successfully', false); + if (page === 'settings') { + var time = new Date().getTime(); + History.pushState(null, null, '/settings/tickets/?refresh=' + time); + } else if (page === 'singleticket') { + var tagModal = $('#createTagModal'); + var tagFormField = $('select#tags'); + tagFormField.append(''); + tagFormField.find('option#TAG__' + data.tag._id).prop('selected', true); + tagFormField.trigger('chosen:updated'); + form.find('#tag').val(''); + if (tagModal.length > 0) UI.modal(tagModal).hide(); + $timeout(function() { + $scope.showTags($event); + }, 250); + } + }, function errorCallback(err) { + helpers.UI.showSnackbar('Unable to create tag. Check console', true); + $log.error(err); + }); + } + }; + //NG Init function $scope.setDefaultCreateTicketValues = function() { $timeout(function() { diff --git a/src/public/js/angularjs/controllers/settings.js b/src/public/js/angularjs/controllers/settings.js index 51b08bbd6..436729a05 100644 --- a/src/public/js/angularjs/controllers/settings.js +++ b/src/public/js/angularjs/controllers/settings.js @@ -914,41 +914,6 @@ define([ }); }; - $scope.showCreateTagWindow = function($event) { - $event.preventDefault(); - var createTagModal = $('#createTagModal'); - if (createTagModal.length > 0) - UIkit.modal(createTagModal, {bgclose: false}).show(); - - }; - - $scope.createTag = function($event) { - $event.preventDefault(); - var form = $('#createTagForm'); - if (!form.isValid(null, null, false)) - return true; - else { - var tagName = form.find('input[name="tagName"]').val(); - if (!tagName || tagName.length < 3) return true; - - $http.post('/api/v1/tags/create', { - tag: tagName - }, { - headers: { - 'Content-Type': 'application/json' - } - }).then(function successCallback() { - helpers.UI.showSnackbar('Tag: ' + tagName + ' created successfully', false); - var time = new Date().getTime(); - History.pushState(null, null, '/settings/tickets/?refresh=' + time); - - }, function errorCallback(err) { - helpers.UI.showSnackbar('Unable to create tag. Check console', true); - $log.error(err); - }); - } - }; - $scope.showCreateTicketTypeWindow = function($event) { $event.preventDefault(); var createTicketTypeModal = $('#createTicketTypeModal'); diff --git a/src/public/js/angularjs/controllers/singleTicket.js b/src/public/js/angularjs/controllers/singleTicket.js index f7a3e8f22..2806dbfcb 100644 --- a/src/public/js/angularjs/controllers/singleTicket.js +++ b/src/public/js/angularjs/controllers/singleTicket.js @@ -277,14 +277,6 @@ define(['angular', 'underscore', 'jquery', 'uikit', 'modules/socket', 'modules/n }); }; - $scope.showCreateTags = function(event) { - event.preventDefault(); - var tagModal = $('#createTagModal'); - if (tagModal.length > 0) - UIkit.modal(tagModal, {bgclose: false}).show(); - - }; - $scope.showTags = function(event) { event.preventDefault(); var tagModal = $('#addTagModal'); @@ -309,40 +301,6 @@ define(['angular', 'underscore', 'jquery', 'uikit', 'modules/socket', 'modules/n } }; - $scope.submitAddNewTag = function(event) { - event.preventDefault(); - var form = $('form#createTagForm'); - if (form.length > 0) { - var tag = form.find('#tag').val(); - var data = { - tag: tag - }; - - $http({ - method: 'POST', - url: '/api/v1/tags/create', - data: data, - headers: { 'Content-Type': 'application/json'} - }) - .success(function(data) { - var tagModal = $('#createTagModal'); - var tagFormField = $('select#tags'); - tagFormField.append(''); - tagFormField.find('option#TAG__' + data.tag._id).prop('selected', true); - tagFormField.trigger('chosen:updated'); - form.find('#tag').val(''); - if (tagModal.length > 0) UIkit.modal(tagModal).hide(); - $timeout(function() { - $scope.showTags(event); - }, 250); - }) - .error(function(err) { - $log.log('[trudesk:tickets:addTag} - Error: ' + err.error); - helpers.UI.showSnackbar('Error: ' + err.error, true); - }); - } - }; - $scope.submitAddTags = function(event) { event.preventDefault(); var id = $('#__ticketId').text(); diff --git a/src/public/js/modules/ajaxify.js b/src/public/js/modules/ajaxify.js index 6ee503b2c..52dad7554 100644 --- a/src/public/js/modules/ajaxify.js +++ b/src/public/js/modules/ajaxify.js @@ -132,7 +132,7 @@ define('modules/ajaxify', [ var $this = $(this); // Ajaxify - $this.find('a:internal:not(.no-ajaxy):not(.ajaxify-bound)').addClass('ajaxify-bound').on('click', function(event){ + $this.find('a:internal:not(.no-ajaxy):not(.ajaxify-bound):not(.search-choice-close)').addClass('ajaxify-bound').on('click', function(event){ // Prepare var $this = $(this), diff --git a/src/views/partials/createTagWindow.hbs b/src/views/partials/createTagWindow.hbs index 249549db0..1d5a6199f 100644 --- a/src/views/partials/createTagWindow.hbs +++ b/src/views/partials/createTagWindow.hbs @@ -1,6 +1,6 @@ -
+
-
+

Create a tag

Tags categorize tickets, making it easy to identify issues

diff --git a/src/views/settings.hbs b/src/views/settings.hbs index 2612b3d71..03cc73afd 100644 --- a/src/views/settings.hbs +++ b/src/views/settings.hbs @@ -691,7 +691,7 @@
-
+
@@ -707,7 +707,7 @@
- {{> createTagWindow}} + {{> createTagWindow page='settings' }}
diff --git a/src/views/subviews/singleticket.hbs b/src/views/subviews/singleticket.hbs index e2a513590..bf4e05093 100644 --- a/src/views/subviews/singleticket.hbs +++ b/src/views/subviews/singleticket.hbs @@ -719,7 +719,9 @@ {{/each}} - +
+ +
@@ -734,24 +736,9 @@
- + {{> createTagWindow page='singleticket'}} - {{#contentFor 'js-plugins'}}