Skip to content

Commit 57702ba

Browse files
committed
Version 4.1.1
1 parent ab6f736 commit 57702ba

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

operator/js/ticket_view.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(function () {
22
function Form() {
3+
var reply_selector = '#newMessage';
4+
35
/**
46
* Key, value pair of editors which have been initialised.
57
* Key is the text editor element ID. Value is bool (initialised or not).
@@ -8,8 +10,12 @@
810
*/
911
var editors = {};
1012

13+
var isInitialised = function (selector) {
14+
return editors.hasOwnProperty(selector) && editors[selector] === true;
15+
}
16+
1117
var initEditor = function(selector, $form, opts) {
12-
if (editors.hasOwnProperty(selector) && editors[selector] === true) {
18+
if (isInitialised(selector)) {
1319
return;
1420
}
1521

@@ -77,10 +83,19 @@
7783
});
7884
};
7985

86+
this.destroyReplyForm = function () {
87+
if (! isInitialised(reply_selector)) {
88+
return;
89+
}
90+
91+
editors[reply_selector] = false;
92+
$(reply_selector).editor().remove();
93+
};
94+
8095
this.initReplyForm = function (opts) {
8196
var $form = $('.message-form');
8297
initFileUploads($form, 'replyFileUpload');
83-
initEditor('#newMessage', $form, opts);
98+
initEditor(reply_selector, $form, opts);
8499
};
85100

86101
this.initNotesForm = function () {
@@ -100,17 +115,16 @@
100115
};
101116
}
102117

103-
App.extend('TicketViewForm', Form);
118+
App.extend('TicketViewForm', new Form);
104119

105120
$(document).ready(function() {
106121

107122
var polling = new PollReplies(30000);
108123
polling.start();
109124

110125
// Initialise reply editor.
111-
var form = new Form();
112126
if ($('.sp-reply-type .sp-action[data-type=0]').hasClass('sp-active')) {
113-
form.initReplyForm();
127+
App.TicketViewForm.initReplyForm();
114128
}
115129

116130
// Enable hide/show password toggle
@@ -133,7 +147,7 @@
133147
switch ($(this).data('type')) {
134148
case 1:
135149
$form = $('.notes-form').toggle();
136-
form.initNotesForm();
150+
App.TicketViewForm.initNotesForm();
137151
break;
138152

139153
case 2:
@@ -153,7 +167,7 @@
153167
};
154168

155169
$form = $('.forward-form').toggle();
156-
form.initForwardForm(isFresh ? editor_opts : {});
170+
App.TicketViewForm.initForwardForm(isFresh ? editor_opts : {});
157171
if (isFresh) {
158172
return;
159173
}
@@ -162,7 +176,7 @@
162176

163177
default:
164178
$form = $('.message-form:not(.edit)').toggle();
165-
form.initReplyForm();
179+
App.TicketViewForm.initReplyForm();
166180
}
167181

168182
// If form is now visible, focus in editor and scroll to it.

0 commit comments

Comments
 (0)