diff --git a/src/apps/callflows/app.js b/src/apps/callflows/app.js index 4ed63d3..cf303ce 100644 --- a/src/apps/callflows/app.js +++ b/src/apps/callflows/app.js @@ -19,6 +19,7 @@ define(function(require) { 'media', 'menu', 'misc', + 'setvariable', 'qubicle', 'resource', 'temporalset', diff --git a/src/apps/callflows/i18n/en-US.json b/src/apps/callflows/i18n/en-US.json index dd5495e..692d4aa 100644 --- a/src/apps/callflows/i18n/en-US.json +++ b/src/apps/callflows/i18n/en-US.json @@ -659,6 +659,21 @@ "use_carriers_from_specific_account": "Use carriers from a specific account", "account_id": "Account ID" }, + "set_variable": { + "set_variable": "Set variable", + "tooltip": "Sets a variable on the current leg", + "edit_dialog": { + "title": "Set variable", + "channel": "Channel", + "channel_a": "A (caller)", + "channel_both": "Both", + "channel_tooltip": "Which channel to set the variable on", + "value": "Value", + "value_tooltip": "The value to set \"variable\"", + "variable": "Variable", + "variable_tooltip": "The variable name to set on the leg(s)" + } + }, "timeofday": { "time_of_day": "Time of Day", "time_of_day_cat": "Time of Day", diff --git a/src/apps/callflows/submodules/setvariable/setvariable.js b/src/apps/callflows/submodules/setvariable/setvariable.js new file mode 100644 index 0000000..32ef26a --- /dev/null +++ b/src/apps/callflows/submodules/setvariable/setvariable.js @@ -0,0 +1,111 @@ +define(function(require) { + var $ = require('jquery'), + monster = require('monster'); + + var app = { + requests: {}, + + subscribe: { + 'callflows.fetchActions': 'setvariableDefineActions' + }, + + setvariableDefineActions: function(args) { + var self = this, + callflow_nodes = args.actions, + i18n = self.i18n.active().callflows.set_variable; + + $.extend(callflow_nodes, { + 'set_variable[]': { + name: i18n.set_variable, + icon: 'check', + category: self.i18n.active().oldCallflows.advanced_cat, + module: 'set_variable', + tip: i18n.tooltip, + data: { + channel: 'a' + }, + rules: [ + { + type: 'quantity', + maxSize: '9999' + } + ], + isUsable: 'true', + weight: 48, + caption: function(node, caption_map) { + return node.getMetadata('variable') || ''; + }, + edit: function(node, callback) { + self.setvariableShowEditDialog(node, callback); + } + } + }); + }, + + setvariableShowEditDialog: function (node, callback) { + var self = this, + $popup, + $dialog, + i18n = self.i18n.active().callflows.set_variable, + variable = node.getMetadata('variable') || '', + value = node.getMetadata('value') || '', + channel = node.getMetadata('channel') || ''; + + $dialog = $(self.getTemplate({ + name: 'dialogEdit', + data: { + variable: variable, + value: value, + channel: channel, + channels: [ + { + 'name': i18n.edit_dialog.channel_a, + 'value': 'a' + }, { + 'name': i18n.edit_dialog.channel_both, + 'value': 'both' + } + ] + }, + submodule: 'setvariable' + })); + + $popup = monster.ui.dialog($dialog, { + title: self.i18n.active().callflows.set_variable.edit_dialog.title, + minHeight: '0', + width: 450, + beforeClose: function() { + if (typeof callback === 'function') { + callback(); + } + } + }); + + monster.ui.tooltips($dialog); + + $dialog.find('.js-save').click(function() { + var $form = $(this) + .closest('.js-set-variable-dialog') + .find('.js-set-variable-form'); + var formData = monster.ui.getFormData($form[0]); + + node.deleteMetadata('variable'); + node.deleteMetadata('value'); + node.deleteMetadata('channel'); + + formData.variable && node.setMetadata('variable', formData.variable); + formData.value && node.setMetadata('value', formData.value); + formData.channel && node.setMetadata('channel', formData.channel); + node.caption = formData.variable || ''; + + if (typeof callback === 'function') { + callback(); + } + + $popup.dialog('close'); + }); + } + }; + + return app; +}); diff --git a/src/apps/callflows/submodules/setvariable/views/dialogEdit.html b/src/apps/callflows/submodules/setvariable/views/dialogEdit.html new file mode 100644 index 0000000..8d92d74 --- /dev/null +++ b/src/apps/callflows/submodules/setvariable/views/dialogEdit.html @@ -0,0 +1,56 @@ +