diff --git a/i18n/en-US.json b/i18n/en-US.json index 325524a..9b9d6a0 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -149,7 +149,9 @@ "__comment": "UI-2104: Adding a warning when adding a group with no endpoints", "__version": "3.22", - "emptyEndpointsWarning": "You need to select at least one member to create a group" + "emptyEndpointsWarning": "You need to select at least one member to create a group", + "ringGroup": "{{name}} Ring Group", + "baseGroup": "{{name}} Base Group" }, "devices": { diff --git a/submodules/groups/groups.js b/submodules/groups/groups.js index 2caa9f8..6650c80 100644 --- a/submodules/groups/groups.js +++ b/submodules/groups/groups.js @@ -1045,17 +1045,69 @@ define(function(require) { //formData = self.groupsCleanNameData(formData); + var repeats = _.get(data.callflow, 'flow.data.repeats'); + data = $.extend(true, {}, data, formData); + var baseGroupName = self.getTemplate({ + name: '!' + self.i18n.active().groups.baseGroup, + data: { + name: data.group.name + } + }), + ringGroupName = self.getTemplate({ + name: '!' + self.i18n.active().groups.ringGroup, + data: { + name: data.group.name + } + }); + monster.parallel([ function(callback) { + if (self.isGroupEdited(data, baseGroupName, repeats)) { + callback(null); + return; + } + self.groupsUpdate(data.group, function(data) { callback(null); }); }, function(callback) { - self.groupsUpdateCallflow(data.callflow, function(data) { + if (self.isGroupEdited(data, baseGroupName, repeats)) { callback(null); + return; + } + + self.groupsPatchCallflow({ + data: { + callflowId: data.callflow.id, + data: { + name: baseGroupName, + flow: data.callflow.flow + } + }, + success: function() { + callback(null); + } + }); + }, + function(callback) { + if (ringGroupName === data.callflowRingGroup.name) { + callback(null); + return; + } + + self.groupsPatchCallflow({ + data: { + callflowId: data.callflowRingGroup.id, + data: { + name: ringGroupName + } + }, + success: function() { + callback(null); + } }); } ], function(err, results) { @@ -1083,6 +1135,10 @@ define(function(require) { }); }, + isGroupEdited: function(data, baseGroupName, repeats) { + return baseGroupName === data.callflow.name && repeats === parseInt(_.get(data.callflow, 'flow.data.repeats')); + }, + groupsBindNumbers: function(template, data) { var self = this, toastrMessages = self.i18n.active().groups.toastrMessages, @@ -1551,6 +1607,11 @@ define(function(require) { self.groupsGetBaseRingGroup(groupId, function(data) { callback(null, data); }); + }, + callflowRingGroup: function(callback) { + self.groupsGetRingGroup(groupId, function(data) { + callback(null, data); + }); } }, function(err, results) { globalCallback && globalCallback(results); @@ -2111,6 +2172,20 @@ define(function(require) { }); }, + groupsPatchCallflow: function(args) { + var self = this; + + self.callApi({ + resource: 'callflow.patch', + data: _.merge({ + accountId: self.accountId + }, args.data), + success: function(data) { + args.success(data.data); + } + }); + }, + groupsGetGroup: function(groupId, callback) { var self = this;