Skip to content

Commit f8c04e6

Browse files
author
Hwashiang Yu
committed
MAGETWO-98351: Update transaction email variable dialog
- Updated variable value storage
1 parent 6509eae commit f8c04e6

File tree

1 file changed

+64
-14
lines changed

1 file changed

+64
-14
lines changed

app/code/Magento/Variable/view/adminhtml/web/variables.js

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ window.Variables = {
1818
overlayShowEffectOptions: null,
1919
overlayHideEffectOptions: null,
2020
insertFunction: 'Variables.insertVariable',
21+
variablesValue: [],
22+
23+
/**
24+
* @param {*} textareaElementId
25+
* @param {Function} insertFunction
26+
*/
2127
init: function(textareaElementId, insertFunction) {
2228
if ($(textareaElementId)) {
2329
this.textareaElementId = textareaElementId;
@@ -27,11 +33,17 @@ window.Variables = {
2733
}
2834
},
2935

36+
/**
37+
* reset data.
38+
*/
3039
resetData: function() {
3140
this.variablesContent = null;
3241
this.dialogWindow = null;
3342
},
3443

44+
/**
45+
* @param {Object} variables
46+
*/
3547
openVariableChooser: function(variables) {
3648
if (this.variablesContent == null && variables) {
3749
this.variablesContent = '<ul class="insert-variable">';
@@ -40,8 +52,9 @@ window.Variables = {
4052
this.variablesContent += '<li><b>' + variableGroup.label.escapeHTML() + '</b></li>';
4153
(variableGroup.value).each(function(variable){
4254
if (variable.value && variable.label) {
55+
this.variablesValue.push(variable.value);
4356
this.variablesContent += '<li>' +
44-
this.prepareVariableRow(variable.value, variable.label) + '</li>';
57+
this.prepareVariableRow(this.variablesValue.length, variable.label) + '</li>';
4558
}
4659
}.bind(this));
4760
}
@@ -52,9 +65,13 @@ window.Variables = {
5265
this.openDialogWindow(this.variablesContent);
5366
}
5467
},
68+
69+
/**
70+
* @param {*} variablesContent
71+
*/
5572
openDialogWindow: function (variablesContent) {
5673
var windowId = this.dialogWindowId;
57-
jQuery('<div id="' + windowId + '">' + Variables.variablesContent + '</div>').modal({
74+
jQuery('<div id="' + windowId + '">' + variablesContent + '</div>').modal({
5875
title: $t('Insert Variable...'),
5976
type: 'slide',
6077
buttons: [],
@@ -64,40 +81,67 @@ window.Variables = {
6481
});
6582

6683
jQuery('#' + windowId).modal('openModal');
67-
68-
variablesContent.evalScripts.bind(variablesContent).defer();
6984
},
85+
86+
/**
87+
* Close dialog window.
88+
*/
7089
closeDialogWindow: function() {
7190
jQuery('#' + this.dialogWindowId).modal('closeModal');
7291
},
73-
prepareVariableRow: function(varValue, varLabel) {
74-
var value = (varValue).replace(/"/g, '&quot;').replace(/'/g, '\\&#39;');
75-
var content = '<a href="#" onclick="'+this.insertFunction+'(\''+ value.escapeHTML() +'\');return false;">' + varLabel.escapeHTML() + '</a>';
76-
return content;
92+
93+
/**
94+
* @param {Number} index
95+
* @param {*} varLabel
96+
* @return {String}
97+
*/
98+
prepareVariableRow: function (index, varLabel) {
99+
return '<a href="#" onclick="' +
100+
this.insertFunction +
101+
'(' +
102+
index +
103+
');return false;">' +
104+
varLabel.escapeHTML() +
105+
'</a>';
77106
},
78-
insertVariable: function(value) {
107+
108+
/**
109+
* @param {*} variable
110+
*/
111+
insertVariable: function(variable) {
79112
var windowId = this.dialogWindowId;
80113
jQuery('#' + windowId).modal('closeModal');
81114
var textareaElm = $(this.textareaElementId);
82115
if (textareaElm) {
83116
var scrollPos = textareaElm.scrollTop;
84-
updateElementAtCursor(textareaElm, value);
85-
textareaElm.focus();
117+
if (!isNaN(variable)) {
118+
updateElementAtCursor(textareaElm, Variables.variablesValue[variable - 1]);
119+
} else {
120+
updateElementAtCursor(textareaElm, variable);
121+
} textareaElm.focus();
86122
textareaElm.scrollTop = scrollPos;
87123
jQuery(textareaElm).change();
88124
textareaElm = null;
89125
}
90-
return;
91126
}
92127
};
93128

94129
window.MagentovariablePlugin = {
95130
editor: null,
96131
variables: null,
97132
textareaId: null,
133+
134+
/**
135+
* @param {*} editor
136+
*/
98137
setEditor: function(editor) {
99138
this.editor = editor;
100139
},
140+
141+
/**
142+
* @param {String} url
143+
* @param {*} textareaId
144+
*/
101145
loadChooser: function(url, textareaId) {
102146
this.textareaId = textareaId;
103147
if (this.variables == null) {
@@ -114,11 +158,18 @@ window.MagentovariablePlugin = {
114158
} else {
115159
this.openChooser(this.variables);
116160
}
117-
return;
118161
},
162+
163+
/**
164+
* @param {*} variables
165+
*/
119166
openChooser: function(variables) {
120167
Variables.openVariableChooser(variables);
121168
},
169+
170+
/**
171+
* @param {*} value
172+
*/
122173
insertVariable : function (value) {
123174
if (this.textareaId) {
124175
Variables.init(this.textareaId);
@@ -127,7 +178,6 @@ window.MagentovariablePlugin = {
127178
Variables.closeDialogWindow();
128179
this.editor.execCommand('mceInsertContent', false, value);
129180
}
130-
return;
131181
}
132182
};
133183

0 commit comments

Comments
 (0)