Skip to content

Commit

Permalink
fix(tags): tags with min2 were not creating
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jan 4, 2019
1 parent 64731cb commit 9a22364
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 99 deletions.
47 changes: 47 additions & 0 deletions src/public/js/angularjs/controllers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<option id="TAG__' + data.tag._id + '" value="' + data.tag._id + '">' + data.tag.name + '</option>');
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() {
Expand Down
35 changes: 0 additions & 35 deletions src/public/js/angularjs/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
42 changes: 0 additions & 42 deletions src/public/js/angularjs/controllers/singleTicket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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('<option id="TAG__' + data.tag._id + '" value="' + data.tag._id + '">' + data.tag.name + '</option>');
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();
Expand Down
2 changes: 1 addition & 1 deletion src/public/js/modules/ajaxify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/views/partials/createTagWindow.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="uk-modal" id="createTagModal" ng-controller="settingsCtrl">
<div class="uk-modal" id="createTagModal" ng-controller="commonCtrl">
<div class="uk-modal-dialog">
<form class="uk-form-stacked" id="createTagForm" ng-submit="createTag($event)">
<form class="uk-form-stacked" id="createTagForm" ng-submit="createTag('{{page}}', $event)">
<div class="">
<h2 class="nomargin mb-5">Create a tag</h2>
<p class="uk-text-small uk-text-muted">Tags categorize tickets, making it easy to identify issues</p>
Expand Down
4 changes: 2 additions & 2 deletions src/views/settings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@
</h5>
</div>
<div class="right" style="position:relative;">
<div style="margin: 12px 15px 0 0;">
<div style="margin: 12px 15px 0 0;" ng-controller="commonCtrl">
<button class="uk-float-right md-btn md-btn-flat md-btn-flat-success md-btn-wave-light" ng-click="showCreateTagWindow($event);">Create</button>
</div>
</div>
Expand All @@ -707,7 +707,7 @@
</div>
</div>
</div>
{{> createTagWindow}}
{{> createTagWindow page='settings' }}
</div>

</div>
Expand Down
21 changes: 4 additions & 17 deletions src/views/subviews/singleticket.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,9 @@
<option id="TAG__{{_id}}" value="{{_id}}">{{name}}</option>
{{/each}}
</select>
<button type="button" ng-click="showCreateTags($event)" style="border-radius: 0; -moz-border-radius: 0;"><i class="fa fa-plus" style="margin-right: 0;"></i></button>
<div ng-controller="commonCtrl">
<button type="button" ng-click="showCreateTagWindow($event);" style="border-radius: 0; -moz-border-radius: 0;"><i class="fa fa-plus" style="margin-right: 0;"></i></button>
</div>
</div>

<div class="left" style="margin-top: 15px;">
Expand All @@ -734,24 +736,9 @@
</div>
</div>

<div id="createTagModal" class="uk-modal" aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<div class="uk-modal-dialog uk-clearfix">
<a class="uk-modal-close uk-close no-ajaxy"></a>
<h5 style="font-weight: 300;">Create Tag</h5>
<div>
<form id="createTagForm" action="#" method="POST" class="nomargin" ng-submit="submitAddNewTag($event)">
<input type="text" id="tag" name="tag" class="md-input" />

<div class="right" style="margin-top: 15px;">
<button class="uk-button uk-button-success nomargin" type="submit">Create Tag</button>
</div>
</form>
</div>
</div>
</div>
{{> createTagWindow page='singleticket'}}

</div>
</div>

{{#contentFor 'js-plugins'}}

Expand Down

0 comments on commit 9a22364

Please sign in to comment.