diff --git a/src/apps/callflows/.gitattributes b/src/apps/callflows/.gitattributes new file mode 100644 index 0000000..e7ec678 --- /dev/null +++ b/src/apps/callflows/.gitattributes @@ -0,0 +1,2 @@ +# Set the default behavior, in case people don't have core.autocrlf set +* text=auto diff --git a/src/apps/callflows/LICENSE b/src/apps/callflows/LICENSE new file mode 100644 index 0000000..87f4e7c --- /dev/null +++ b/src/apps/callflows/LICENSE @@ -0,0 +1,471 @@ + MOZILLA PUBLIC LICENSE + Version 1.1 + + --------------- + +1. Definitions. + + 1.0.1. "Commercial Use" means distribution or otherwise making the + Covered Code available to a third party. + + 1.1. "Contributor" means each entity that creates or contributes to + the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original + Code, prior Modifications used by a Contributor, and the Modifications + made by that particular Contributor. + + 1.3. "Covered Code" means the Original Code or Modifications or the + combination of the Original Code and Modifications, in each case + including portions thereof. + + 1.4. "Electronic Distribution Mechanism" means a mechanism generally + accepted in the software development community for the electronic + transfer of data. + + 1.5. "Executable" means Covered Code in any form other than Source + Code. + + 1.6. "Initial Developer" means the individual or entity identified + as the Initial Developer in the Source Code notice required by Exhibit + A. + + 1.7. "Larger Work" means a work which combines Covered Code or + portions thereof with code not governed by the terms of this License. + + 1.8. "License" means this document. + + 1.8.1. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means any addition to or deletion from the + substance or structure of either the Original Code or any previous + Modifications. When Covered Code is released as a series of files, a + Modification is: + A. Any addition to or deletion from the contents of a file + containing Original Code or previous Modifications. + + B. Any new file that contains any part of the Original Code or + previous Modifications. + + 1.10. "Original Code" means Source Code of computer software code + which is described in the Source Code notice required by Exhibit A as + Original Code, and which, at the time of its release under this + License is not already Covered Code governed by this License. + + 1.10.1. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, process, + and apparatus claims, in any patent Licensable by grantor. + + 1.11. "Source Code" means the preferred form of the Covered Code for + making modifications to it, including all modules it contains, plus + any associated interface definition files, scripts used to control + compilation and installation of an Executable, or source code + differential comparisons against either the Original Code or another + well known, available Covered Code of the Contributor's choice. The + Source Code can be in a compressed or archival form, provided the + appropriate decompression or de-archiving software is widely available + for no charge. + + 1.12. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms of, this + License or a future version of this License issued under Section 6.1. + For legal entities, "You" includes any entity which controls, is + controlled by, or is under common control with You. For purposes of + this definition, "control" means (a) the power, direct or indirect, + to cause the direction or management of such entity, whether by + contract or otherwise, or (b) ownership of more than fifty percent + (50%) of the outstanding shares or beneficial ownership of such + entity. + +2. Source Code License. + + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, + non-exclusive license, subject to third party intellectual property + claims: + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer to use, reproduce, + modify, display, perform, sublicense and distribute the Original + Code (or portions thereof) with or without Modifications, and/or + as part of a Larger Work; and + + (b) under Patents Claims infringed by the making, using or + selling of Original Code, to make, have made, use, practice, + sell, and offer for sale, and/or otherwise dispose of the + Original Code (or portions thereof). + + (c) the licenses granted in this Section 2.1(a) and (b) are + effective on the date Initial Developer first distributes + Original Code under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: 1) for code that You delete from the Original Code; 2) + separate from the Original Code; or 3) for infringements caused + by: i) the modification of the Original Code or ii) the + combination of the Original Code with other software or devices. + + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor + hereby grants You a world-wide, royalty-free, non-exclusive license + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor, to use, reproduce, modify, + display, perform, sublicense and distribute the Modifications + created by such Contributor (or portions thereof) either on an + unmodified basis, with other Modifications, as Covered Code + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or + selling of Modifications made by that Contributor either alone + and/or in combination with its Contributor Version (or portions + of such combination), to make, use, sell, offer for sale, have + made, and/or otherwise dispose of: 1) Modifications made by that + Contributor (or portions thereof); and 2) the combination of + Modifications made by that Contributor with its Contributor + Version (or portions of such combination). + + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are + effective on the date Contributor first makes Commercial Use of + the Covered Code. + + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: 1) for any code that Contributor has deleted from the + Contributor Version; 2) separate from the Contributor Version; + 3) for infringements caused by: i) third party modifications of + Contributor Version or ii) the combination of Modifications made + by that Contributor with other software (except as part of the + Contributor Version) or other devices; or 4) under Patent Claims + infringed by Covered Code in the absence of Modifications made by + that Contributor. + +3. Distribution Obligations. + + 3.1. Application of License. + The Modifications which You create or to which You contribute are + governed by the terms of this License, including without limitation + Section 2.2. The Source Code version of Covered Code may be + distributed only under the terms of this License or a future version + of this License released under Section 6.1, and You must include a + copy of this License with every copy of the Source Code You + distribute. You may not offer or impose any terms on any Source Code + version that alters or restricts the applicable version of this + License or the recipients' rights hereunder. However, You may include + an additional document offering the additional rights described in + Section 3.5. + + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be + made available in Source Code form under the terms of this License + either on the same media as an Executable version or via an accepted + Electronic Distribution Mechanism to anyone to whom you made an + Executable version available; and if made available via Electronic + Distribution Mechanism, must remain available for at least twelve (12) + months after the date it initially became available, or at least six + (6) months after a subsequent version of that particular Modification + has been made available to such recipients. You are responsible for + ensuring that the Source Code version remains available even if the + Electronic Distribution Mechanism is maintained by a third party. + + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a + file documenting the changes You made to create that Covered Code and + the date of any change. You must include a prominent statement that + the Modification is derived, directly or indirectly, from Original + Code provided by the Initial Developer and including the name of the + Initial Developer in (a) the Source Code, and (b) in any notice in an + Executable version or related documentation in which You describe the + origin or ownership of the Covered Code. + + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's + intellectual property rights is required to exercise the rights + granted by such Contributor under Sections 2.1 or 2.2, + Contributor must include a text file with the Source Code + distribution titled "LEGAL" which describes the claim and the + party making the claim in sufficient detail that a recipient will + know whom to contact. If Contributor obtains such knowledge after + the Modification is made available as described in Section 3.2, + Contributor shall promptly modify the LEGAL file in all copies + Contributor makes available thereafter and shall take other steps + (such as notifying appropriate mailing lists or newsgroups) + reasonably calculated to inform those who received the Covered + Code that new knowledge has been obtained. + + (b) Contributor APIs. + If Contributor's Modifications include an application programming + interface and Contributor has knowledge of patent licenses which + are reasonably necessary to implement that API, Contributor must + also include this information in the LEGAL file. + + (c) Representations. + Contributor represents that, except as disclosed pursuant to + Section 3.4(a) above, Contributor believes that Contributor's + Modifications are Contributor's original creation(s) and/or + Contributor has sufficient rights to grant the rights conveyed by + this License. + + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source + Code. If it is not possible to put such notice in a particular Source + Code file due to its structure, then You must include such notice in a + location (such as a relevant directory) where a user would be likely + to look for such a notice. If You created one or more Modification(s) + You may add your name as a Contributor to the notice described in + Exhibit A. You must also duplicate this License in any documentation + for the Source Code where You describe recipients' rights or ownership + rights relating to Covered Code. You may choose to offer, and to + charge a fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Code. However, You + may do so only on Your own behalf, and not on behalf of the Initial + Developer or any Contributor. You must make it absolutely clear than + any such warranty, support, indemnity or liability obligation is + offered by You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred by the + Initial Developer or such Contributor as a result of warranty, + support, indemnity or liability terms You offer. + + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the + requirements of Section 3.1-3.5 have been met for that Covered Code, + and if You include a notice stating that the Source Code version of + the Covered Code is available under the terms of this License, + including a description of how and where You have fulfilled the + obligations of Section 3.2. The notice must be conspicuously included + in any notice in an Executable version, related documentation or + collateral in which You describe recipients' rights relating to the + Covered Code. You may distribute the Executable version of Covered + Code or ownership rights under a license of Your choice, which may + contain terms different from this License, provided that You are in + compliance with the terms of this License and that the license for the + Executable version does not attempt to limit or alter the recipient's + rights in the Source Code version from the rights set forth in this + License. If You distribute the Executable version under a different + license You must make it absolutely clear that any terms which differ + from this License are offered by You alone, not by the Initial + Developer or any Contributor. You hereby agree to indemnify the + Initial Developer and every Contributor for any liability incurred by + the Initial Developer or such Contributor as a result of any such + terms You offer. + + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code + not governed by the terms of this License and distribute the Larger + Work as a single product. In such a case, You must make sure the + requirements of this License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + + If it is impossible for You to comply with any of the terms of this + License with respect to some or all of the Covered Code due to + statute, judicial order, or regulation then You must: (a) comply with + the terms of this License to the maximum extent possible; and (b) + describe the limitations and the code they affect. Such description + must be included in the LEGAL file described in Section 3.4 and must + be included with all distributions of the Source Code. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. + +5. Application of this License. + + This License applies to code to which the Initial Developer has + attached the notice in Exhibit A and to related Covered Code. + +6. Versions of the License. + + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised + and/or new versions of the License from time to time. Each version + will be given a distinguishing version number. + + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the + License, You may always continue to use it under the terms of that + version. You may also choose to use such Covered Code under the terms + of any subsequent version of the License published by Netscape. No one + other than Netscape has the right to modify the terms applicable to + Covered Code created under this License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may + only do in order to apply it to code which is not already Covered Code + governed by this License), You must (a) rename Your license so that + the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", + "MPL", "NPL" or any confusingly similar phrase do not appear in your + license (except to note that your license differs from this License) + and (b) otherwise make it clear that Your version of the license + contains terms which differ from the Mozilla Public License and + Netscape Public License. (Filling in the name of the Initial + Developer, Original Code or Contributor in the notice described in + Exhibit A shall not of themselves be deemed to be modifications of + this License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF + DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. + THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE + IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, + YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE + COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER + OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to cure + such breach within 30 days of becoming aware of the breach. All + sublicenses to the Covered Code which are properly granted shall + survive any termination of this License. Provisions which, by their + nature, must remain in effect beyond the termination of this License + shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement + claim (excluding declatory judgment actions) against Initial Developer + or a Contributor (the Initial Developer or Contributor against whom + You file such action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly + infringes any patent, then any and all rights granted by such + Participant to You under Sections 2.1 and/or 2.2 of this License + shall, upon 60 days notice from Participant terminate prospectively, + unless if within 60 days after receipt of notice You either: (i) + agree in writing to pay Participant a mutually agreeable reasonable + royalty for Your past and future use of Modifications made by such + Participant, or (ii) withdraw Your litigation claim with respect to + the Contributor Version against such Participant. If within 60 days + of notice, a reasonable royalty and payment arrangement are not + mutually agreed upon in writing by the parties or the litigation claim + is not withdrawn, the rights granted by Participant to You under + Sections 2.1 and/or 2.2 automatically terminate at the expiration of + the 60 day notice period specified above. + + (b) any software, hardware, or device, other than such Participant's + Contributor Version, directly or indirectly infringes any patent, then + any rights granted to You by such Participant under Sections 2.1(b) + and 2.2(b) are revoked effective as of the date You first made, used, + sold, distributed, or had made, Modifications made by that + Participant. + + 8.3. If You assert a patent infringement claim against Participant + alleging that such Participant's Contributor Version directly or + indirectly infringes any patent where such claim is resolved (such as + by license or settlement) prior to the initiation of patent + infringement litigation, then the reasonable value of the licenses + granted by such Participant under Sections 2.1 or 2.2 shall be taken + into account in determining the amount or value of any payment or + license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, + all end user license agreements (excluding distributors and resellers) + which have been validly granted by You or any distributor hereunder + prior to termination shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL + DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, + OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR + ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY + CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, + WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY + RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW + PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE + EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO + THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in + 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer + software" and "commercial computer software documentation," as such + terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 + C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), + all U.S. Government End Users acquire Covered Code with only those + rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed by + California law provisions (except to the extent applicable law, if + any, provides otherwise), excluding its conflict-of-law provisions. + With respect to disputes in which at least one party is a citizen of, + or an entity chartered or registered to do business in the United + States of America, any litigation relating to this License shall be + subject to the jurisdiction of the Federal Courts of the Northern + District of California, with venue lying in Santa Clara County, + California, with the losing party responsible for costs, including + without limitation, court costs and reasonable attorneys' fees and + expenses. The application of the United Nations Convention on + Contracts for the International Sale of Goods is expressly excluded. + Any law or regulation which provides that the language of a contract + shall be construed against the drafter shall not apply to this + License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or indirectly, + out of its utilization of rights under this License and You agree to + work with Initial Developer and Contributors to distribute such + responsibility on an equitable basis. Nothing herein is intended or + shall be deemed to constitute any admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as + "Multiple-Licensed". "Multiple-Licensed" means that the Initial + Developer permits you to utilize portions of the Covered Code under + Your choice of the NPL or the alternative licenses, if any, specified + by the Initial Developer in the file described in Exhibit A. + +EXHIBIT A -Mozilla Public License. + + ``The contents of this file are subject to the Mozilla Public License + Version 1.1 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + License for the specific language governing rights and limitations + under the License. + + The Original Code is ___Monster_____________________________. + + The Initial Developer of the Original Code is ___VoIP INC___. + Portions created by ______________________ are Copyright (C) _2015_ + _______________________. All Rights Reserved. + + Contributor(s): __Jean-Roch Maitre____________________________. + __Maxime Roux______________________________. + __Joris Tirado______________________________. + + Alternatively, the contents of this file may be used under the terms + of the _____ license (the "[___] License"), in which case the + provisions of [______] License are applicable instead of those + above. If you wish to allow use of your version of this file only + under the terms of the [____] License and not to allow others to use + your version of this file under the MPL, indicate your decision by + deleting the provisions above and replace them with the notice and + other provisions required by the [___] License. If you do not delete + the provisions above, a recipient may use your version of this file + under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of + the notices in the Source Code files of the Original Code. You should + use the text of this Exhibit A rather than the text found in the + Original Code Source Code for Your Modifications.] diff --git a/src/apps/callflows/app.js b/src/apps/callflows/app.js index 829ca78..f3d361c 100644 --- a/src/apps/callflows/app.js +++ b/src/apps/callflows/app.js @@ -1,28 +1,34 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); - - require([ - './submodules/misc/misc', - './submodules/blacklist/blacklist', - './submodules/conference/conference', - './submodules/device/device', - './submodules/directory/directory', - './submodules/faxbox/faxbox', - './submodules/groups/groups', - './submodules/media/media', - './submodules/menu/menu', - './submodules/qubicle/qubicle', - './submodules/resource/resource', - './submodules/timeofday/timeofday', - './submodules/user/user', - './submodules/vmbox/vmbox', - './submodules/featurecodes/featurecodes', - './submodules/temporalset/temporalset', - './submodules/callcenter/callcenter', + var appSubmodules = [ + 'blacklist', + 'conference', + 'device', + 'directory', + 'faxbox', + 'featurecodes', + 'groups', + 'media', + 'menu', + 'misc', + 'qubicle', + 'resource', + 'temporalset', + 'timeofday', + 'user', + 'vmbox', + 'callcenter' + ]; + + var appSubmodulesFullPath = _.map(appSubmodules, function(name) { + return './submodules/' + name + '/' + name; + }) + + require(_.merge(appSubmodulesFullPath, [ 'bootstraptour' - ]); + ])); var app = { name: 'callflows', @@ -37,11 +43,9 @@ define(function(require){ requests: {}, // Define the events available for other apps - subscribe: { - 'callflows.fetchActions': 'define_callflow_nodes' - }, + subscribe: {}, - subModules: ['misc', 'blacklist', 'conference', 'device', 'directory', 'faxbox', 'groups', 'media', 'menu', 'qubicle', 'resource', 'timeofday', 'user', 'vmbox', 'featurecodes', 'temporalset', 'callcenter'], + subModules: appSubmodules, appFlags: { flow: {}, @@ -57,7 +61,7 @@ define(function(require){ flow: {}, // Method used by the Monster-UI Framework, shouldn't be touched unless you're doing some advanced kind of stuff! - load: function(callback){ + load: function(callback) { var self = this; self.initApp(function() { @@ -115,12 +119,11 @@ define(function(require){ } else { return options.inverse(this); } - }); }, // Entry Point of the app - render: function(container){ + render: function(container) { var self = this, parent = _.isEmpty(container) ? $('#monster_content') : container; @@ -129,11 +132,14 @@ define(function(require){ self.renderEntityManager(parent); }, - renderCallflows: function(container){ + renderCallflows: function(container) { var self = this, - callflowsTemplate = $(monster.template(self, 'callflow-manager', { - canToggleCallflows: (monster.config.hasOwnProperty('developerFlags') && monster.config.developerFlags.showAllCallflows) || monster.apps.auth.originalAccount.superduper_admin, - hasAllCallflows: self.appFlags.showAllCallflows + callflowsTemplate = $(self.getTemplate({ + name: 'callflow-manager', + data: { + canToggleCallflows: (monster.config.hasOwnProperty('developerFlags') && monster.config.developerFlags.showAllCallflows) || monster.apps.auth.originalAccount.superduper_admin, + hasAllCallflows: self.appFlags.showAllCallflows + } })); self.bindCallflowsEvents(callflowsTemplate, container); @@ -148,9 +154,10 @@ define(function(require){ .append(callflowsTemplate); container.find('.search-query').focus(); + self.hackResize(callflowsTemplate); - if($('.js-callflows-list .list-element').length === 0) { + if ($('.js-callflows-list .list-element').length === 0) { self.initGuideTour(); } } @@ -161,7 +168,7 @@ define(function(require){ var self = this; var i18n = self.i18n.active(); - self.tour = new Tour({ + self.tour = new Tour ({ name: 'callflow-guide', backdrop: true, debug: true, @@ -184,10 +191,10 @@ define(function(require){ element: '.js-callflow-edition .js-list-add', placement: 'right', content: i18n.callflows.guide.addCallflow, - onShown: function (tour) { + onShown: function() { $('.popover').find('[data-role="prev"]').remove(); }, - onNext: function (tour) { + onNext: function() { $('.js-callflow-edition .js-list-add').click(); } }, @@ -195,10 +202,10 @@ define(function(require){ element: '#ws_callflow .js-add-number', placement: 'bottom', content: i18n.callflows.guide.addNumber, - onShown: function (tour) { + onShown: function() { $('.popover').find('[data-role="prev"]').remove(); }, - onNext: function (tour) { + onNext: function(tour) { $('#ws_callflow .js-add-number').click(); tour.end(); } @@ -207,18 +214,18 @@ define(function(require){ element: '#ws_cf_tools > div', placement: 'left', content: i18n.callflows.guide.dragAndDropAction, - onShown: function (tour) { + onShown: function() { $('.popover').find('[data-role="next"],[data-role="prev"]').remove(); } } - ]}); + ] }); self.tour.init(); - if(self.tour.ended()) { + if (self.tour.ended()) { self.tour.restart(); } - if(self.tour.getCurrentStep() !== 0) { + if (self.tour.getCurrentStep() !== 0) { self.tour.goTo(0); } }, @@ -228,7 +235,9 @@ define(function(require){ callflowList = template.find('.list-container .list'), isLoading = false, loader = $('
  • '), - searchLink = $(monster.template(self, 'callflowList-searchLink')); + searchLink = $(self.getTemplate({ + name: 'callflowList-searchLink' + })); template.find('.superadmin-mode #switch_role').on('change', function(e) { self.appFlags.showAllCallflows = $(this).is(':checked'); @@ -239,20 +248,21 @@ define(function(require){ // Add Callflow template.find('.list-add').on('click', function() { template.find('.callflow-content') - .removeClass('listing-mode') - .addClass('edition-mode'); + .removeClass('listing-mode') + .addClass('edition-mode'); + + $('.list-element-active').removeClass('list-element-active'); + $(this).addClass('list-element-active'); self.editCallflow(); - if($('.js-callflows-list .list-element').length === 0) { - if(self.tour.ended()) { + if ($('.js-callflows-list .list-element').length === 0) { + if (self.tour.ended()) { self.tour.restart(); } - if(self.tour.getCurrentStep() !== 1) { + if (self.tour.getCurrentStep() !== 1) { self.tour.goTo(1); } - } else { - delete self.tour; } }); @@ -261,6 +271,9 @@ define(function(require){ var $this = $(this), callflowId = $this.data('id'); + $this.closest('.list').find('.list-element-active').removeClass('list-element-active'); + $this.addClass('list-element-active'); + template.find('.callflow-content') .removeClass('listing-mode') .addClass('edition-mode'); @@ -268,21 +281,26 @@ define(function(require){ self.editCallflow({ id: callflowId }); }); - callflowList.on('scroll', function() { - if(!isLoading && callflowList.data('next-key') && (callflowList.scrollTop() >= (callflowList[0].scrollHeight - callflowList.innerHeight() - 100))) { + if (!isLoading && callflowList.data('next-key') && (callflowList.scrollTop() >= (callflowList[0].scrollHeight - callflowList.innerHeight() - 100))) { isLoading = true; callflowList.append(loader); self.listData({ callback: function(callflowData) { - var listCallflows = monster.template(self, 'callflowList', { callflows: callflowData.data }); + var listCallflows = $(self.getTemplate({ + name: 'callflowList', + data: { + callflows: callflowData.data, + activeEntityId: callflowData.id + } + })); loader.remove(); callflowList - .append(listCallflows) - .data('next-key', callflowData.next_start_key || null); + .append(listCallflows) + .data('next-key', callflowData.next_start_key || null); isLoading = false; }, @@ -297,10 +315,10 @@ define(function(require){ var search = $(this).val(); searchLink.find('.search-value').text(search); - if(search) { + if (search) { $.each(template.find('.list-element'), function() { var $elem = $(this); - if($elem.data('search').toLowerCase().indexOf(search.toLowerCase()) >= 0) { + if ($elem.data('search').toLowerCase().indexOf(search.toLowerCase()) >= 0) { $elem.show(); } else { $elem.hide(); @@ -314,17 +332,21 @@ define(function(require){ }); callflowList.on('click', '.search-link', function() { - if(searchLink.hasClass('active')) { + if (searchLink.hasClass('active')) { callflowList.data('search-value', null); - searchLink.removeClass('active') - .remove(); - template.find('.search-query').prop('disabled', false) - .val(''); + searchLink + .removeClass('active') + .remove(); + template + .find('.search-query') + .prop('disabled', false) + .val(''); self.repaintList({template: template}); } else { var searchValue = searchLink.find('.search-value').text(); - searchLink.addClass('active') - .remove(); + searchLink + .addClass('active') + .remove(); callflowList.data('search-value', searchValue); template.find('.search-query').prop('disabled', true); @@ -342,10 +364,21 @@ define(function(require){ renderEntityManager: function(container) { var self = this, - entityActions = _.keyBy(_.filter(self.actions, function(action) { - return action.hasOwnProperty('listEntities'); - }), 'module'), - template = $(monster.template(self, 'layout', { actions: entityActions })); + entityActions = _ + .chain(self.actions) + .filter('listEntities') + .keyBy('module') + .value(), + template = $(self.getTemplate({ + name: 'layout', + data: { + actions: _ + .chain(entityActions) + .map() + .sortBy('name') + .value() + } + })); self.bindEntityManagerEvents({ parent: container, @@ -360,7 +393,6 @@ define(function(require){ bindEntityManagerEvents: function(args) { var self = this, - parent = args.parent, template = args.template, actions = args.actions, editEntity = function(type, id) { @@ -398,25 +430,22 @@ define(function(require){ template.find('.entity-manager .entity-element').on('click', function() { var $this = $(this); - if($this.hasClass('callflow-element')) { + if ($this.hasClass('callflow-element')) { self.renderCallflows(template.find('.callflow-edition')); template.find('.callflow-app-section').hide(); template.find('.callflow-edition').show(); - } - else if($this.hasClass('account-element')) { + } else if ($this.hasClass('account-element')) { self.renderAccountSettings(template.find('.callflow-edition')); template.find('.callflow-app-section').hide(); template.find('.callflow-edition').show(); - } - else if($this.hasClass('feature-code-element')) { + } else if ($this.hasClass('feature-code-element')) { monster.pub('callflows.featurecode.render', template.find('.callflow-edition')); template.find('.callflow-app-section').hide(); template.find('.callflow-edition').show(); - } - else { + } else { var entityType = $this.data('type'); template.find('.entity-edition .entity-header .entity-title').text(actions[entityType].name); self.refreshEntityList({ @@ -456,10 +485,10 @@ define(function(require){ template.find('.entity-edition .search-query').on('keyup', function() { var search = $(this).val(); - if(search) { + if (search) { $.each(template.find('.entity-edition .list-element'), function() { var $elem = $(this); - if($elem.data('search').toLowerCase().indexOf(search.toLowerCase()) >= 0) { + if ($elem.data('search').toLowerCase().indexOf(search.toLowerCase()) >= 0) { $elem.show(); } else { $elem.hide(); @@ -481,17 +510,20 @@ define(function(require){ actions[entityType].listEntities(function(entities) { self.formatEntityData(entities, entityType); - var listEntities = $(monster.template(self, 'entity-list', { - entities: entities, - activeEntityId: activeEntityId + var listEntities = $(self.getTemplate({ + name: 'entity-list', + data: { + entities: entities, + activeEntityId: activeEntityId + } })); monster.ui.tooltips(listEntities); template.find('.entity-edition .list-container .list') - .empty() - .append(listEntities) - .data('type', entityType); + .empty() + .append(listEntities) + .data('type', entityType); template.find('.callflow-app-section').hide(); template.find('.entity-edition').show(); @@ -506,20 +538,16 @@ define(function(require){ formatEntityData: function(entities, entityType) { var self = this; _.each(entities, function(entity) { - if(entity.first_name && entity.last_name) { + if (entity.first_name && entity.last_name) { entity.displayName = entity.first_name + ' ' + entity.last_name; - } else if(entity.name) { + } else if (entity.name) { entity.displayName = entity.name; } else { entity.displayName = entity.id; } - switch(entityType) { - case 'play': //media - if(entity.media_source) { - entity.additionalInfo = self.i18n.active().callflows.media.mediaSources[entity.media_source] - } - break; + if (entityType === 'play' && entity.media_source) { + entity.additionalInfo = self.i18n.active().callflows.media.mediaSources[entity.media_source]; } }); }, @@ -529,13 +557,37 @@ define(function(require){ self.loadAccountSettingsData(function(accountSettingsData) { var formattedData = self.formatAccountSettingsData(accountSettingsData), - template = $(monster.template(self, 'accountSettings', formattedData)), + template = $(self.getTemplate({ + name: 'accountSettings', + data: _.merge({ + showPAssertedIdentity: monster.config.whitelabel.showPAssertedIdentity + }, formattedData) + })), widgetBlacklist = self.renderBlacklists(template, accountSettingsData); monster.ui.tooltips(template); - template.find('.cid-number-select, .preflow-callflows-dropdown').chosen({ search_contains: true, width: '220px' }); + // Setup input fields + monster.ui.chosen(template.find('.cid-number-select, .preflow-callflows-dropdown')); + monster.ui.mask(template.find('.phone-number'), 'phoneNumber'); + + // Set validation rules + monster.ui.validate(template.find('#account_settings_form'), { + rules: { + 'caller_id.asserted.number': { + phoneNumber: true + }, + 'caller_id.asserted.realm': { + realm: true + } + }, + messages: { + 'caller_id.asserted.number': self.i18n.active().callflows.accountSettings.callerId.messages.invalidNumber + } + }); + container.empty().append(template); + self.bindAccountSettingsEvents(template, accountSettingsData, widgetBlacklist); }); }, @@ -543,6 +595,8 @@ define(function(require){ formatAccountSettingsData: function(data) { var formattedData = data; + formattedData.showMediaUploadDisclosure = monster.config.whitelabel.showMediaUploadDisclosure; + formattedData.silenceMedia = 'silence_stream://300000'; formattedData.extra = formattedData.extra || {}; @@ -611,9 +665,9 @@ define(function(require){ template.find('.upload-div').slideUp(function() { template.find('.upload-toggle').removeClass('active'); }); - if(newMedia) { + if (newMedia) { var mediaSelect = template.find('.media-dropdown'); - mediaSelect.append(''); + mediaSelect.append(''); mediaSelect.val(newMedia.id); } }; @@ -624,15 +678,6 @@ define(function(require){ $(this).tab('show'); }); - monster.ui.validate(template.find('#account_settings_form'), { - rules: { - 'extra.shoutcastUrl': { - protocol: true, - required: true - } - } - }); - template.find('.media-dropdown').on('change', function() { template.find('.shoutcast-div').toggleClass('active', $(this).val() === 'shoutcast').find('input').val(''); }); @@ -647,7 +692,7 @@ define(function(require){ mediaToUpload = results[0]; }, error: function(errors) { - if(errors.hasOwnProperty('size') && errors.size.length > 0) { + if (errors.hasOwnProperty('size') && errors.size.length > 0) { monster.ui.alert(self.i18n.active().callflows.accountSettings.musicOnHold.fileTooBigAlert); } template.find('.upload-div input').val(''); @@ -656,7 +701,7 @@ define(function(require){ }); template.find('.upload-toggle').on('click', function() { - if($(this).hasClass('active')) { + if ($(this).hasClass('active')) { template.find('.upload-div').stop(true, true).slideUp(); } else { template.find('.upload-div').stop(true, true).slideDown(); @@ -669,7 +714,7 @@ define(function(require){ template.find('.upload-submit').on('click', function() { template.find('.shoutcast-div').removeClass('active'); - if(mediaToUpload) { + if (mediaToUpload) { self.callApi({ resource: 'media.create', data: { @@ -677,7 +722,7 @@ define(function(require){ data: { streamable: true, name: mediaToUpload.name, - media_source: "upload", + media_source: 'upload', description: mediaToUpload.name } }, @@ -713,50 +758,59 @@ define(function(require){ }); template.find('.account-settings-update').on('click', function() { - if (monster.ui.valid(template.find('#account_settings_form'))) { - var formData = monster.ui.getFormData('account_settings_form'), - newData = $.extend(true, {}, data.account, formData); - - if (formData.music_on_hold.media_id === '') { - delete newData.music_on_hold.media_id; - } else if (formData.music_on_hold.media_id === 'shoutcast') { - newData.music_on_hold.media_id = template.find('.shoutcast-url-input').val(); - } + // Validate form + if (!monster.ui.valid(template.find('#account_settings_form'))) { + return; + } - if (formData.caller_id.external.name === '') { - delete newData.caller_id.external.name; - } - if (formData.caller_id.external.number === '') { - delete newData.caller_id.external.number; - } + // Collect data + var formData = monster.ui.getFormData('account_settings_form'), + newData = _.merge({}, data.account, formData); - if (formData.preflow.always === '_disabled') { - delete newData.preflow.always; - } + // Format data + if (_.has(newData.caller_id, 'asserted')) { + newData.caller_id.asserted.number = monster.util.getFormatPhoneNumber(newData.caller_id.asserted.number).e164Number; + } - if (newData.hasOwnProperty('outbound_flags')) { - newData.outbound_flags.dynamic = newData.outbound_flags.dynamic ? newData.outbound_flags.dynamic.split(',') : []; - newData.outbound_flags.static = newData.outbound_flags.static ? newData.outbound_flags.static.split(',') : []; - _.isEmpty(newData.outbound_flags.dynamic) && delete newData.outbound_flags.dynamic; - _.isEmpty(newData.outbound_flags.static) && delete newData.outbound_flags.static; - _.isEmpty(newData.outbound_flags) && delete newData.outbound_flags; - } + // Clean empty data + if (formData.music_on_hold.media_id === '') { + delete newData.music_on_hold.media_id; + } else if (formData.music_on_hold.media_id === 'shoutcast') { + newData.music_on_hold.media_id = template.find('.shoutcast-url-input').val(); + } - newData.blacklists = widgetBlacklist.getSelectedItems(); + self.compactObject(newData.caller_id); - delete newData.extra; + if (_.isEmpty(newData.caller_id)) { + delete newData.caller_id; + } - self.callApi({ - resource: 'account.update', - data: { - accountId: newData.id, - data: newData - }, - success: function(data, status) { - self.render(); - } - }); + if (formData.preflow.always === '_disabled') { + delete newData.preflow.always; + } + + if (newData.hasOwnProperty('outbound_flags')) { + newData.outbound_flags.dynamic = newData.outbound_flags.dynamic ? newData.outbound_flags.dynamic.split(',') : []; + newData.outbound_flags.static = newData.outbound_flags.static ? newData.outbound_flags.static.split(',') : []; + _.isEmpty(newData.outbound_flags.dynamic) && delete newData.outbound_flags.dynamic; + _.isEmpty(newData.outbound_flags.static) && delete newData.outbound_flags.static; + _.isEmpty(newData.outbound_flags) && delete newData.outbound_flags; } + + newData.blacklists = widgetBlacklist.getSelectedItems(); + + delete newData.extra; + + self.callApi({ + resource: 'account.update', + data: { + accountId: newData.id, + data: newData + }, + success: function(data, status) { + self.render(); + } + }); }); }, @@ -846,7 +900,7 @@ define(function(require){ $flowChart = container.find('.flowchart'), contentHeight = window.innerHeight - $('.core-topbar-wrapper').outerHeight(), contentHeightPx = contentHeight + 'px', - innerContentHeightPx = (contentHeight-71) + 'px'; + innerContentHeightPx = (contentHeight - 71) + 'px'; $listContainer.css('height', window.innerHeight - $listContainer.position().top + 'px'); $mainContent.css('height', contentHeightPx); @@ -864,12 +918,18 @@ define(function(require){ self.listData({ callback: function(callflowData) { - var listCallflows = monster.template(self, 'callflowList', { callflows: callflowData.data }); + var listCallflows = $(self.getTemplate({ + name: 'callflowList', + data: { + callflows: callflowData.data, + activeEntityId: args.id + } + })); template.find('.list-container .list') - .empty() - .append(listCallflows) - .data('next-key', callflowData.next_start_key || null); + .empty() + .append(listCallflows) + .data('next-key', callflowData.next_start_key || null); callback && callback(callflowData.data); }, @@ -887,7 +947,7 @@ define(function(require){ accountId: self.accountId }; - if(nextStartKey) { + if (nextStartKey) { $.extend(true, apiData, { filters: { 'start_key': encodeURIComponent(nextStartKey) @@ -895,7 +955,7 @@ define(function(require){ }); } - if(!self.appFlags.showAllCallflows) { + if (!self.appFlags.showAllCallflows) { $.extend(true, apiData, { filters: { 'filter_not_ui_metadata.origin': [ @@ -906,7 +966,7 @@ define(function(require){ }); } - if(searchValue) { + if (searchValue) { apiResource = 'callflow.searchByNameAndNumber'; apiData.value = encodeURIComponent(searchValue); } @@ -946,7 +1006,7 @@ define(function(require){ listSpareNumbers = []; _.each(numbers, function(numberData, phoneNumber) { - if(!numberData.hasOwnProperty('used_by') || numberData.used_by === '') { + if (!numberData.hasOwnProperty('used_by') || numberData.used_by === '') { numberData.phoneNumber = phoneNumber; listSpareNumbers.push(numberData); } @@ -960,7 +1020,9 @@ define(function(require){ _.each(data.data, function(callflow) { var formattedNumbers = _.map(callflow.numbers || '-', function(number) { - return monster.util.formatPhoneNumber(number); + return _.startsWith('+', number) + ? monster.util.formatPhoneNumber(number) + : number; }), listNumbers = formattedNumbers.toString(), isFeatureCode = callflow.featurecode !== false && !_.isEmpty(callflow.featurecode); @@ -992,10 +1054,11 @@ define(function(require){ delete self.original_flow; // clear original_flow $('.js-callflow-intro').hide(); + $('#callflow-view .callflow_help').hide(); self.resetFlow(); - if(data && data.id) { + if (data && data.id) { self.callApi({ resource: 'callflow.get', data: { @@ -1013,7 +1076,7 @@ define(function(require){ self.flow.contact_list = { exclude: 'contact_list' in callflow ? callflow.contact_list.exclude || false : false }; self.flow.caption_map = callflow.metadata; - if(callflow.flow.module != undefined) { + if (callflow.flow.module !== undefined) { self.flow.root = self.buildFlow(callflow.flow, self.flow.root, 0, '_'); } @@ -1022,8 +1085,7 @@ define(function(require){ self.repaintFlow(); } }); - } - else { + } else { self.resetFlow(); self.dataCallflow = {}; self.repaintFlow(); @@ -1035,21 +1097,22 @@ define(function(require){ renderButtons: function() { var self = this, - buttons = $(monster.template(self, 'buttons')); + buttons = $(self.getTemplate({ + name: 'buttons' + })); $('.buttons').empty(); $('.save', buttons).click(function() { - if(self.flow.numbers && self.flow.numbers.length > 0) { + if (self.flow.numbers && self.flow.numbers.length > 0) { self.save(); - } - else { + } else { monster.ui.alert(self.i18n.active().oldCallflows.invalid_number + '

    ' + self.i18n.active().oldCallflows.please_select_valid_number); } }); $('.delete', buttons).click(function() { - if(self.flow.id) { + if (self.flow.id) { monster.ui.confirm(self.i18n.active().oldCallflows.are_you_sure, function() { self.callApi({ resource: 'callflow.delete', @@ -1061,7 +1124,7 @@ define(function(require){ $('#ws_cf_flow').empty(); $('.buttons').empty(); $('#ws_cf_tools').empty(); - $('#hidden_callflow_warning').hide() + $('#hidden_callflow_warning').hide(); self.repaintList(); self.resetFlow(); @@ -1070,8 +1133,7 @@ define(function(require){ self.show_pending_change(false); }); - } - else { + } else { monster.ui.alert(self.i18n.active().oldCallflows.this_callflow_has_not_been_created); } }); @@ -1080,21 +1142,22 @@ define(function(require){ }, // Callflow JS code - buildFlow: function (json, parent, id, key) { + buildFlow: function(json, parent, id, key) { var self = this, branch = self.branch(self.construct_action(json)); - branch.data.data = ('data' in json) ? json.data : {}; + branch.data.data = _.get(json, 'data', {}); branch.id = ++id; branch.key = key; + branch.disabled = _.get(json, 'data.skip_module'); branch.caption = self.actions.hasOwnProperty(branch.actionName) ? self.actions[branch.actionName].caption(branch, self.flow.caption_map) : ''; - if(self.actions.hasOwnProperty(parent.actionName) && self.actions[parent.actionName].hasOwnProperty('key_caption')) { + if (self.actions.hasOwnProperty(parent.actionName) && self.actions[parent.actionName].hasOwnProperty('key_caption')) { branch.key_caption = self.actions[parent.actionName].key_caption(branch, self.flow.caption_map); } - if(json.hasOwnProperty('children')) { + if (json.hasOwnProperty('children')) { $.each(json.children, function(key, child) { branch = self.buildFlow(child, branch, id, key); }); @@ -1108,20 +1171,19 @@ define(function(require){ construct_action: function(json) { var action = ''; - if('data' in json) { - if('id' in json.data) { + if ('data' in json) { + if ('id' in json.data) { action = 'id=*,'; } - if('action' in json.data) { + if ('action' in json.data) { action += 'action=' + json.data.action + ','; } } - if(action != '') { + if (action !== '') { action = '[' + action.replace(/,$/, ']'); - } - else { + } else { action = '[]'; } @@ -1150,7 +1212,7 @@ define(function(require){ branch: function(actionName) { var self = this; - function branch(actionName) { + function Branch(actionName) { var that = this, action = self.actions[actionName] || {}; @@ -1169,61 +1231,56 @@ define(function(require){ this.potentialChildren = function() { var list = []; - for(var i in self.actions) { - if(self.actions[i].isUsable) { + for (var i in self.actions) { + if (self.actions[i].isUsable) { list[i] = i; } } - for(var i in action.rules) { + for (var i in action.rules) { var rule = action.rules[i]; - switch (rule.type) { - case 'quantity': - if(this.children.length >= rule.maxSize) { - list = []; - } - break; + if (rule.type === 'quantity' && this.children.length >= rule.maxSize) { + list = []; } } return list; - } + }; this.contains = function(branch) { var toCheck = branch; - while(toCheck.parent) { - if(this.id == toCheck.id) { + while (toCheck.parent) { + if (this.id === toCheck.id) { return true; - } - else { + } else { toCheck = toCheck.parent; } } return false; - } + }; this.removeChild = function(branch) { $.each(this.children, function(i, child) { - if(child.id == branch.id) { - that.children.splice(i,1); + if (child.id === branch.id) { + that.children.splice(i, 1); return false; } }); - } + }; this.addChild = function(branch) { - if(!(branch.actionName in this.potentialChildren())) { + if (!(branch.actionName in this.potentialChildren())) { return false; } - if(branch.contains(this)) { + if (branch.contains(this)) { return false; } - if(branch.parent) { + if (branch.parent) { branch.parent.removeChild(branch); } @@ -1232,43 +1289,43 @@ define(function(require){ this.children.push(branch); return true; - } + }; - this.getMetadata = function(key) { + this.getMetadata = function(key, defaultValue) { var value; - if('data' in this.data && key in this.data.data) { + if (_.has(this.data, ['data', key])) { value = this.data.data[key]; - return (value == 'null') ? null : value; + return (value === 'null') ? null : value; } - return false; - } + return _.isUndefined(defaultValue) ? false : defaultValue; + }; this.setMetadata = function(key, value) { - if(!('data' in this.data)) { + if (!('data' in this.data)) { this.data.data = {}; } this.data.data[key] = (value == null) ? 'null' : value; - } + }; this.deleteMetadata = function(key) { - if('data' in this.data && key in this.data.data) { + if ('data' in this.data && key in this.data.data) { delete this.data.data[key]; } - } + }; - this.index = function (index) { + this.index = function(index) { this.id = index; $.each(this.children, function() { - index = this.index(index+1); + index = this.index(index + 1); }); return index; - } + }; this.nodes = function() { var nodes = {}; @@ -1284,9 +1341,9 @@ define(function(require){ }); return nodes; - } + }; - this.serialize = function () { + this.serialize = function() { var json = $.extend(true, {}, this.data); json.module = this.module; @@ -1298,17 +1355,17 @@ define(function(require){ }); return json; - } + }; } - return new branch(actionName); + return new Branch(actionName); }, repaintFlow: function() { var self = this; // Let it there for now, if we need to save callflows automatically again. - /*if('savable' in THIS.flow) { + /*if ('savable' in THIS.flow) { THIS.save_callflow_no_loading(); }*/ @@ -1328,14 +1385,14 @@ define(function(require){ } var metadata = self.dataCallflow.hasOwnProperty('ui_metadata') ? self.dataCallflow.ui_metadata : false, - isHiddenCallflow = metadata && metadata.hasOwnProperty('origin') && _.includes(['voip','migration','mobile', 'callqueues'], metadata.origin); + isHiddenCallflow = metadata && metadata.hasOwnProperty('origin') && _.includes(['voip', 'migration', 'mobile', 'callqueues'], metadata.origin); isHiddenCallflow ? $('#hidden_callflow_warning').show() : $('#hidden_callflow_warning').hide(); }, show_pending_change: function(pending_change) { var self = this; - if(pending_change) { + if (pending_change) { $('#pending_change', '#ws_callflow').show(); $('.save', '#ws_callflow').addClass('pulse-box'); } else { @@ -1373,13 +1430,13 @@ define(function(require){ var self = this, s_flow = flow.id + '|' + (!flow.name ? 'undefined' : flow.name), first_iteration; - s_flow += "|NUMBERS"; + s_flow += '|NUMBERS'; $.each(flow.numbers, function(key, value) { - s_flow += "|" + value; + s_flow += '|' + value; }); - s_flow += "|NODES"; + s_flow += '|NODES'; $.each(flow.nodes, function(key, value) { - s_flow += "|" + key + "::"; + s_flow += '|' + key + '::'; first_iteration = true; $.each(value.data.data, function(k, v) { @@ -1400,6 +1457,88 @@ define(function(require){ return s_flow; }, + getCallflowPreview: function(data, callback) { + var self = this, + layout; + + self.callApi({ + resource: 'callflow.get', + data: { + accountId: self.accountId, + callflowId: data.id + }, + success: function(callflow) { + var callflow = callflow.data, + flow = {}; + + flow.root = self.branch('root'); + flow.root.key = 'flow'; + flow.numbers = []; + flow.caption_map = {}; + flow.root.index(0); + flow.nodes = flow.root.nodes(); + + flow.id = callflow.id; + flow.name = callflow.name; + flow.contact_list = { exclude: 'contact_list' in callflow ? callflow.contact_list.exclude || false : false }; + flow.caption_map = callflow.metadata; + + if (callflow.flow.module !== undefined) { + flow.root = self.buildFlow(callflow.flow, flow.root, 0, '_'); + } + + flow.nodes = flow.root.nodes(); + flow.numbers = callflow.numbers || []; + + //prepare html from callflow + + layout = self.renderBranch(flow.root); + callback && callback(layout); + + $('.node', layout).each(function() { + var node = flow.nodes[$(this).attr('id')], + $node = $(this), + node_html; + + if (node.actionName === 'root') { + $node.removeClass('icons_black root'); + node_html = $(self.getTemplate({ + name: 'root', + data: { + name: flow.name || 'Callflow' + } + })); + + for (var counter, size = flow.numbers.length, j = Math.floor((size) / 2) + 1, i = 0; i < j; i++) { + counter = i * 2; + + var numbers = flow.numbers.slice(counter, (counter + 2 < size) ? counter + 2 : size), + row = $(self.getTemplate({ + name: 'rowNumber', + data: { + numbers: numbers + } + })); + + node_html + .find('.content') + .append(row); + } + } else { + node_html = $(self.getTemplate({ + name: 'node', + data: { + node: node, + callflow: self.actions[node.actionName] + } + })); + } + $(this).append(node_html); + }); + } + }); + }, + getUIFlow: function() { var self = this; @@ -1408,41 +1547,46 @@ define(function(require){ var layout = self.renderBranch(self.flow.root); $('.node', layout).hover(function() { - $(this).addClass('over'); - }, - function() { - $(this).removeClass('over'); - } - ); + $(this).addClass('over'); + }, function() { + $(this).removeClass('over'); + }); $('.node', layout).each(function() { var node = self.flow.nodes[$(this).attr('id')], $node = $(this), node_html; - if (node.actionName == 'root') { + if (node.actionName === 'root') { $node.removeClass('icons_black root'); - node_html = $(monster.template(self, 'root', { name: self.flow.name || 'Callflow' })); + node_html = $(self.getTemplate({ + name: 'root', + data: { + name: self.flow.name || 'Callflow' + } + })); $('.edit_icon', node_html).click(function() { - self.flow = $.extend(true, { contact_list: { exclude: false }} , self.flow); + self.flow = $.extend(true, { contact_list: { exclude: false } }, self.flow); - var dialogTemplate = monster.template(self, 'editName', { - name: self.flow.name, - exclude: self.flow.contact_list.exclude, - ui_is_main_number_cf: self.dataCallflow.hasOwnProperty('ui_is_main_number_cf') ? self.dataCallflow.ui_is_main_number_cf : false - }), + var dialogTemplate = $(self.getTemplate({ + name: 'editName', + data: { + name: self.flow.name, + exclude: self.flow.contact_list.exclude, + ui_is_main_number_cf: self.dataCallflow.hasOwnProperty('ui_is_main_number_cf') ? self.dataCallflow.ui_is_main_number_cf : false + } + })), popup = monster.ui.dialog(dialogTemplate, { - title: self.i18n.active().oldCallflows.popup_title - }); + title: self.i18n.active().oldCallflows.popup_title + }); $('#add', popup).click(function() { var $callflow_name = $('#callflow_name', popup); - if($callflow_name.val() != '') { + if ($callflow_name.val() !== '') { self.flow.name = $callflow_name.val(); $('.root .top_bar .name', layout).html(self.flow.name); - } - else { + } else { self.flow.name = ''; $('.root .top_bar .name', layout).html('Callflow'); } @@ -1456,59 +1600,71 @@ define(function(require){ }); }); - $('.tooltip', node_html).click(function() { - monster.ui.dialog(monster.template(self, 'help_callflow')); - }); - - for(var x, size = self.flow.numbers.length, j = Math.floor((size) / 2) + 1, i = 0; i < j; i++) { - x = i * 2; + for (var counter, size = self.flow.numbers.length, j = Math.floor((size) / 2) + 1, i = 0; i < j; i++) { + counter = i * 2; - var numbers = self.flow.numbers.slice(x, (x + 2 < size) ? x + 2 : size), - row = monster.template(self, 'rowNumber', { numbers: numbers }); + var numbers = self.flow.numbers.slice(counter, (counter + 2 < size) ? counter + 2 : size), + row = $(self.getTemplate({ + name: 'rowNumber', + data: { + numbers: _.map(numbers, function(number) { + return _.startsWith('+', number) + ? monster.util.formatPhoneNumber(number) + : number; + }) + } + })); - node_html.find('.content') - .append(row); + node_html + .find('.content') + .append(row); } $('.number_column.empty', node_html).click(function() { - if(self.tour) { + if (self.tour) { self.tour.end(); } self.listNumbers(function(phoneNumbers) { var parsedNumbers = []; _.each(phoneNumbers, function(number) { - if($.inArray(number.phoneNumber,self.flow.numbers) < 0) { + if ($.inArray(number.phoneNumber, self.flow.numbers) < 0) { parsedNumbers.push(number); } }); - var popup_html = $(monster.template(self, 'addNumber', { phoneNumbers: parsedNumbers })), + var popup_html = $(self.getTemplate({ + name: 'addNumber', + data: { + phoneNumbers: parsedNumbers + } + })), popup = monster.ui.dialog(popup_html, { title: self.i18n.active().oldCallflows.add_number }); - popup_html.find('#list_numbers').chosen({ search_contains: true, width: '160px' }); + monster.ui.chosen(popup_html.find('#list_numbers'), { + width: '160px' + }); // Have to do that so that the chosen dropdown isn't hidden. popup_html.parent().css('overflow', 'visible'); - if(parsedNumbers.length === 0) { + if (parsedNumbers.length === 0) { $('#list_numbers', popup_html).attr('disabled', 'disabled'); $('').appendTo($('#list_numbers', popup_html)); } var refresh_numbers = function() { - self.listNumbers(function(refreshedNumbers) { + self.listNumbers(function(refreshedNumbers) { $('#list_numbers', popup).empty(); - if(refreshedNumbers.length === 0) { + if (refreshedNumbers.length === 0) { $('#list_numbers', popup).attr('disabled', 'disabled'); $('').appendTo($('#list_numbers', popup)); - } - else { + } else { $('#list_numbers', popup).removeAttr('disabled'); $.each(refreshedNumbers, function(k, v) { - $('').appendTo($('#list_numbers', popup)); + $('').appendTo($('#list_numbers', popup)); }); } }); @@ -1517,11 +1673,10 @@ define(function(require){ $('.extensions_content', popup).hide(); $('input[name="number_type"]', popup).click(function() { - if($(this).val() === 'your_numbers') { + if ($(this).val() === 'your_numbers') { $('.list_numbers_content', popup).show(); $('.extensions_content', popup).hide(); - } - else { + } else { $('.extensions_content', popup).show(); $('.list_numbers_content', popup).hide(); } @@ -1558,23 +1713,22 @@ define(function(require){ event.preventDefault(); var number = $('input[name="number_type"]:checked', popup).val() === 'your_numbers' ? $('#list_numbers option:selected', popup).val() : $('#add_number_text', popup).val(); - if(number !== 'select_none' && number !== '') { + if (number !== 'select_none' && number !== '') { self.flow.numbers.push(number); popup.dialog('close'); self.repaintFlow(); - if(self.tour + if (self.tour && $('#ws_callflow .number_column').not('.js-add-number').length === 1) { - if(self.tour.ended()) { + if (self.tour.ended()) { self.tour.restart(); } - if(self.tour.getCurrentStep() !== 2) { + if (self.tour.getCurrentStep() !== 2) { self.tour.goTo(2); } } - } - else { + } else { monster.ui.alert(self.i18n.active().oldCallflows.you_didnt_select); } }); @@ -1585,53 +1739,104 @@ define(function(require){ var number = $(this).parent('.number_column').data('number') + '', index = $.inArray(number, self.flow.numbers); - if(index >= 0) { + if (index >= 0) { self.flow.numbers.splice(index, 1); } self.repaintFlow(); }); - - } - else { - node_html = $(monster.template(self, 'node', { - node: node, - callflow: self.actions[node.actionName] + } else { + node_html = $(self.getTemplate({ + name: 'node', + data: { + node: node, + callflow: self.actions[node.actionName] + } })); // If an API request takes some time, the user can try to re-click on the element, we do not want to let that re-fire a request to the back-end. - // So we set a 500ms timer that will prevent any other interaction with the callflow element. - var isAlreadyClicked = false; + // So we set a 500ms debounce wait that will prevent any other interaction with the callflow element. + node_html.find('.module').on('click', _.debounce(function() { + monster.waterfall([ + function(waterfallCallback) { + if (node.disabled) { + monster.ui.confirm(self.i18n.active().callflowsApp.editor.confirmDialog.enableModule.text, + function() { + waterfallCallback(null, false); + }, + function() { + waterfallCallback(null, true); + }, { + cancelButtonText: self.i18n.active().callflowsApp.editor.confirmDialog.enableModule.cancel, + confirmButtonText: self.i18n.active().callflowsApp.editor.confirmDialog.enableModule.ok + }); + } else { + waterfallCallback(null, null); + } + } + ], function(err, disabled) { + if (!_.isNull(disabled)) { + node.disabled = disabled; + if (_.has(node, 'data.data.skip_module')) { + node.data.data.skip_module = disabled; + } + + if (!disabled) { + node_html.closest('.node').removeClass('disabled'); + } + } - node_html.find('.module').on('click', function() { - if(!isAlreadyClicked) { self.actions[node.actionName].edit(node, function() { self.repaintFlow(); }); + }); + }, 500, { + leading: true, + trailing: false + })); + } - isAlreadyClicked = true; - - setTimeout(function() { - isAlreadyClicked = false; - }, 500); - } + //make names of callflow nodes clickable + $('.details a', node_html).click(function(event) { + event.stopPropagation(); + var previewCallflowId = self.flow.nodes[$(node_html).find('.delete').attr('id')].data.data.id, + dialogTemplate = $(self.getTemplate({ + name: 'callflows-callflowElementDetails', + data: { + id: previewCallflowId + } + })), + popup; + self.getCallflowPreview({id: previewCallflowId}, function(callflowPreview) { + popup = monster.ui.dialog(dialogTemplate, { + position: ['top', 20], // put preview near top of screen to have lots of space for it + title: self.i18n.active().oldCallflows.callflow_preview_title, + width: '650px' + }); + popup.find('.callflow-preview-section.callflow').append(callflowPreview); + $('#callflow_jump').click(function() { + self.editCallflow({id: previewCallflowId}); + popup.dialog('close').remove(); + }); }); - } + }); $(this).append(node_html); $(this).droppable({ - drop: function (event, ui) { + drop: function(event, ui) { var target = self.flow.nodes[$(this).attr('id')], - action; + action, + branch; if (ui.draggable.hasClass('action')) { action = ui.draggable.attr('name'); + branch = self.branch(action); branch.caption = self.actions[action].caption(branch, self.flow.caption_map); if (target.addChild(branch)) { - if(branch.parent && ('key_caption' in self.actions[branch.parent.actionName])) { + if (branch.parent && ('key_caption' in self.actions[branch.parent.actionName])) { branch.key_caption = self.actions[branch.parent.actionName].key_caption(branch, self.flow.caption_map); self.actions[branch.parent.actionName].key_edit(branch, function() { @@ -1639,8 +1844,7 @@ define(function(require){ self.repaintFlow(); }); }); - } - else { + } else { self.actions[action].edit(branch, function() { self.repaintFlow(); }); @@ -1658,7 +1862,7 @@ define(function(require){ // If we move a node, destroy its key branch.key = '_'; - if(branch.parent && ('key_caption' in self.actions[branch.parent.actionName])) { + if (branch.parent && ('key_caption' in self.actions[branch.parent.actionName])) { branch.key_caption = self.actions[branch.parent.actionName].key_caption(branch, self.flow.caption_map); } @@ -1670,25 +1874,25 @@ define(function(require){ }); // dragging the whole branch - if($(this).attr('name') != 'root') { + if ($(this).attr('name') !== 'root') { $(this).draggable({ - start: function () { + start: function() { var children = $(this).next(), - t = children.offset().top - $(this).offset().top, - l = children.offset().left - $(this).offset().left; + top = children.offset().top - $(this).offset().top, + left = children.offset().left - $(this).offset().left; self.enableDestinations($(this)); - $(this).attr('t', t); $(this).attr('l', l); + $(this).attr('t', top); $(this).attr('l', left); }, - drag: function () { + drag: function() { var children = $(this).next(), - t = $(this).offset().top + parseInt($(this).attr('t')), - l = $(this).offset().left + parseInt($(this).attr('l')); + top = $(this).offset().top + parseInt($(this).attr('t')), + left = $(this).offset().left + parseInt($(this).attr('l')); - children.offset({ top: t, left: l }); + children.offset({ top: top, left: left }); }, - stop: function () { + stop: function() { self.disableDestinations(); self.repaintFlow(); @@ -1708,24 +1912,26 @@ define(function(require){ }); $('.node-options .jump', layout).click(function() { - - var $this = $(this), - callflowId = $this.attr('id'); - self.editCallflow({ id: callflowId }); - }); + var $this = $(this), + callflowId = $this.attr('id'); + self.editCallflow({ id: callflowId }); + }); return layout; }, renderBranch: function(branch) { var self = this, - flow = $(monster.template(self, 'branch', { - node: branch, - display_key: branch.parent && ('key_caption' in self.actions[branch.parent.actionName]) + flow = $(self.getTemplate({ + name: 'branch', + data: { + node: branch, + display_key: branch.parent && ('key_caption' in self.actions[branch.parent.actionName]) + } })), children; - if(branch.parent && ('key_edit' in self.actions[branch.parent.actionName])) { + if (branch.parent && ('key_edit' in self.actions[branch.parent.actionName])) { $('.div_option', flow).click(function() { self.actions[branch.parent.actionName].key_edit(branch, function() { self.repaintFlow(); @@ -1756,7 +1962,7 @@ define(function(require){ categories[advanced_cat] = []; $.each(self.actions, function(i, data) { - if('category' in data && (!data.hasOwnProperty('isListed') || data.isListed)) { + if ('category' in data && (!data.hasOwnProperty('isListed') || data.isListed)) { data.category in categories ? true : categories[data.category] = []; data.key = i; categories[data.category].push(data); @@ -1769,45 +1975,44 @@ define(function(require){ } }); - dataTemplate.categories.sort(function(a, b){ + dataTemplate.categories.sort(function(a, b) { return a.key < b.key ? 1 : -1; }); dataTemplate.categories.unshift({ - key: basic_cat, - actions: categories[basic_cat] - }, - { - key: advanced_cat, - actions: categories[advanced_cat] - } - ); + key: basic_cat, + actions: categories[basic_cat] + }, { + key: advanced_cat, + actions: categories[advanced_cat] + }); $.each(categories, function(idx, val) { - val.sort(function(a, b){ + val.sort(function(a, b) { if (a.hasOwnProperty('weight')) { return a.weight > b.weight ? 1 : -1; } }); }); - tools = $(monster.template(self, 'tools', dataTemplate)); - - $('.tooltip', tools).click(function() { - monster.ui.dialog(monster.template(self, 'help_callflow')); - }); + tools = $(self.getTemplate({ + name: 'tools', + data: dataTemplate + })); // Set the basic drawer to open $('#Basic', tools).removeClass('inactive').addClass('active'); - $('.category .open', tools).click(function () { - tools.find('.category') - .removeClass('active') - .addClass('inactive'); + $('.category .open', tools).click(function() { + tools + .find('.category') + .removeClass('active') + .addClass('inactive'); - $(this).parent('.category') - .removeClass('inactive') - .addClass('active'); + $(this) + .parent('.category') + .removeClass('inactive') + .addClass('active'); }); var help_box = $('.callflow_helpbox_wrapper', '#callflow-view').first(), @@ -1854,24 +2059,24 @@ define(function(require){ tools.find('.callflow_helpbox_wrapper').css('top', $this.offset().top).css('left', $('#ws_cf_tools').offset().left - 162).show(); } }, - function () { + function() { tools.find('.callflow_helpbox_wrapper').hide(); } ); - function action (el) { + function action(el) { el.draggable({ - start: function () { + start: function() { self.enableDestinations($(this)); $(this).addClass('inactive'); }, - drag: function () { - if(self.tour) { + drag: function() { + if (self.tour) { self.tour.end(); } $('.callflow_helpbox_wrapper', '#callflow-view').hide(); }, - stop: function () { + stop: function() { self.disableDestinations(); $(this).removeClass('inactive'); }, @@ -1880,8 +2085,6 @@ define(function(require){ }); } - - $('.action', tools).each(function() { action($(this)); }); @@ -1895,7 +2098,7 @@ define(function(require){ enableDestinations: function(el) { var self = this; - $('.node').each(function () { + $('.node').each(function() { var activate = true, target = self.flow.nodes[$(this).attr('id')]; @@ -1903,15 +2106,13 @@ define(function(require){ if (el.hasClass('node') && self.flow.nodes[el.attr('id')].contains(target)) { activate = false; } - } - else { + } else { activate = false; } if (activate) { $(this).addClass('active'); - } - else { + } else { $(this).addClass('inactive'); $(this).droppable('disable'); } @@ -1919,7 +2120,7 @@ define(function(require){ }, disableDestinations: function() { - $('.node').each(function () { + $('.node').each(function() { $(this).removeClass('active'); $(this).removeClass('inactive'); $(this).droppable('enable'); @@ -1931,21 +2132,20 @@ define(function(require){ save: function() { var self = this; - if(self.flow.numbers && self.flow.numbers.length > 0) { + if (self.flow.numbers && self.flow.numbers.length > 0) { var data_request = { - numbers: self.flow.numbers, - flow: (self.flow.root.children[0] == undefined) ? {} : self.flow.root.children[0].serialize() - }; + numbers: self.flow.numbers, + flow: (self.flow.root.children[0] === undefined) ? {} : self.flow.root.children[0].serialize() + }; - if(self.flow.name !== '') { + if (self.flow.name !== '') { data_request.name = self.flow.name; - } - else { + } else { delete data_request.name; delete self.dataCallflow.name; } - if('contact_list' in self.flow) { + if ('contact_list' in self.flow) { data_request.contact_list = { exclude: self.flow.contact_list.exclude || false }; } @@ -1955,7 +2155,7 @@ define(function(require){ data_request = $.extend(true, {}, self.dataCallflow, data_request); delete data_request.metadata; - if(self.flow.id) { + if (self.flow.id) { self.callApi({ resource: 'callflow.update', data: { @@ -1964,12 +2164,11 @@ define(function(require){ data: data_request }, success: function(json) { - self.repaintList(); - self.editCallflow({id: json.data.id}); + self.repaintList({ id: json.data.id }); + self.editCallflow({ id: json.data.id }); } }); - } - else { + } else { self.callApi({ resource: 'callflow.create', data: { @@ -1977,13 +2176,12 @@ define(function(require){ data: data_request }, success: function(json) { - self.repaintList(); - self.editCallflow({id: json.data.id}); + self.repaintList({ id: json.data.id }); + self.editCallflow({ id: json.data.id }); } }); } - } - else { + } else { monster.ui.alert(self.i18n.active().oldCallflows.you_need_to_select_a_number); } }, @@ -1992,26 +2190,26 @@ define(function(require){ var buttons = template.find('.view-buttons'), tabs = template.find('.tabs'); - if(advanced) { + if (advanced) { buttons.find('.btn').removeClass('activate'); buttons.find('.advanced').addClass('activate'); } else { - if(monster.config.advancedView) { + if (monster.config.advancedView) { buttons.find('.btn').removeClass('activate'); buttons.find('.advanced').addClass('activate'); } else { - tabs.hide('blind'); + tabs.hide('blind'); } } - if(tabs.find('li').length < 2){ + if (tabs.find('li').length < 2) { buttons.hide(); } - buttons.find('.basic').on('click', function(){ + buttons.find('.basic').on('click', function() { var $this = $(this); - if(!$this.hasClass('activate')){ + if (!$this.hasClass('activate')) { buttons.find('.btn').removeClass('activate'); $this.addClass('activate'); tabs.find('li:first-child > a').trigger('click'); @@ -2019,10 +2217,10 @@ define(function(require){ } }); - buttons.find('.advanced').click(function(){ + buttons.find('.advanced').click(function() { var $this = $(this); - if(!$this.hasClass('activate')){ + if (!$this.hasClass('activate')) { buttons.find('.btn').removeClass('activate'); $this.addClass('activate'); tabs.show('blind'); @@ -2052,26 +2250,25 @@ define(function(require){ id = input.attr('id'), input_fields = $('input[name="' + name + '"]', html); - if(input_fields.size() > 1) { - if(type == 'checkbox'){ - input_fields = input_fields.filter('[value='+value+']'); + if (input_fields.size() > 1) { + if (type === 'checkbox') { + input_fields = input_fields.filter('[value=' + value + ']'); (input.attr('checked')) ? input_fields.attr('checked', 'checked') : input_fields.removeAttr('checked'); - } - else { + } else { $.each(input_fields, function(k, v) { var element = $(v); - if(element.attr('id') !== id) { + if (element.attr('id') !== id) { element.val(value); } }); } - } - else { + } else { input.unbind('.link'); } }); }, + getAll: function(callApiData, startKey, continueData) { // Warning! Method works for listed data only! // -- Usage: @@ -2087,7 +2284,7 @@ define(function(require){ continueData = continueData || { data:[] }; var self = this; - if(typeof(callApiData.resource) === 'undefined') { + if (typeof (callApiData.resource) === 'undefined') { self.log('Error! Api keyword is undefined'); return; } @@ -2097,32 +2294,48 @@ define(function(require){ generateError: false }, callApiData.data || {}); - if(typeof(startKey) !== 'undefined') { + if (typeof (startKey) !== 'undefined') { requestData.startKey = startKey; } var newRequestData = { resource: callApiData.resource, data: requestData, - success: function(response){ + success: function(response) { response.data = $.merge(continueData.data, response.data); - if(response.next_start_key && startKey !== response.next_start_key) { + if (response.next_start_key && startKey !== response.next_start_key) { self.getAll(callApiData, response.next_start_key, response); return; } - if(typeof(callApiData.success) === 'function') { + if (typeof (callApiData.success) === 'function') { callApiData.success(response); } }, - error: callApiData.error || function(){} + error: callApiData.error || function() {} }; - if(self.requests.hasOwnProperty(callApiData.resource)) { + if (self.requests.hasOwnProperty(callApiData.resource)) { monster.request(newRequestData); } else { self.callApi(newRequestData); } + }, + + /** + * Recursively unsets `obj`'s empty properties by mutating it + * @param {Object} obj Object to compact + */ + compactObject: function(obj) { + var self = this; + _.each(obj, function(value, key) { + if (_.isPlainObject(value)) { + self.compactObject(value); + } + if (_.isEmpty(value)) { + _.unset(obj, key); + } + }); } }; diff --git a/src/apps/callflows/i18n/en-US.json b/src/apps/callflows/i18n/en-US.json index dcce5b1..4da5a86 100644 --- a/src/apps/callflows/i18n/en-US.json +++ b/src/apps/callflows/i18n/en-US.json @@ -1,6 +1,22 @@ { + "callflowsApp": { + "editor": { + "confirmDialog": { + "enableModule": { + "text": "This action is currently disabled, do you want to enable it?", + "cancel": "No", + "ok": "Yes" + } + }, + "moduleBox": { + "tooltip": { + "disabled": "Disabled" + } + } + } + }, "callflows": { - "addCallflow": "Add Callfow", + "addCallflow": "Add Callflow", "searchDatabase": "Search Database", "buyNumbers": "Buy Numbers", "buyLocal": "Local", @@ -152,8 +168,6 @@ "caller_id_number_data_content3": "Define the Caller ID Number of this Device for Emergency Calls.", "music_on_hold": "Music on Hold", "music_on_hold_data_content": "Select the media file that you want to be played by default when it's not set on a user or a device.", - "peer_to_peer_audio": "Peer to Peer Audio", - "peer_to_peer_audio_data_content": "Select the kind of Peer-to-Peer that you would like to set on this device", "secure_rtp": "Secure RTP", "none": "None", "srtp": "SRTP", @@ -216,6 +230,19 @@ "mediaWebrtc": { "content": "If checked, forces a WebRTC compatible SDP on the INVITE.", "label": "WebRTC" + }, + "asserted": "Asserted Identity", + "caller_id_name_data_content4": "Define the Caller ID Name of this Device, to be used for P-Asserted-Identity header (max. 30 chars).", + "caller_id_number_data_content4": "Define the Caller ID Number of this Device, to be used for P-Asserted-Identity header.", + "caller_id_realm": "Caller ID Realm", + "caller_id_realm_placeholder": "Realm", + "caller_id_realm_data_content4": "Define the Caller ID Realm of this Device, to be used for P-Asserted-Identity header.", + "validation": { + "caller_id": { + "name": "Please only enter alphanumeric characters, space or comma", + "number": "Please enter a valid phone number", + "realm": "Please enter a valid realm" + } } }, "disa": { @@ -321,6 +348,7 @@ "caller_id": "Caller ID", "caller_id_placeholder": "Caller ID", "caller_id_data_content": "Caller ID for this fax box", + "caller_id_no_selected": "- No caller ID -", "fax_header": "Fax header", "fax_header_placeholder": "Fax header", "fax_header_data_content": "Information imprinted on the fax", @@ -425,7 +453,8 @@ "__version": "4.1", "shoutcastURL": "Stream URL", "shoutcastURLHelp": "You can type any URL including :// (http, https, shout...)", - "silence": "Silence" + "silence": "Silence", + "shoutcastURLWarning": "WARNING: If the stream selected here attempts to be played, and is unavailable, the call may fail completely. Please make sure the stream you use is available 24/7." }, "menu": { "menu": "Menu", @@ -466,7 +495,7 @@ "timeout_for_dialing_data_content": "Number of seconds allowed without pressing any key.", "extension_number_length": "Extension Number Length", "length": "Length", - "extension_number_length_data_content": "The maximum length of an extension. By default, it is set to the Record PIN number length.", + "extension_number_length_data_content": "The maximum length of an extension. You can not set a length shorter than the length of the PIN set on this menu (ie: if you set this field to \"2\" but the PIN is set to \"1234\" then the system will automatically set this field to \"4\").", "allow_outside_recording": "Allow outside recording", "allow_outside_recording_data_content": "This option allows someone to dial into a menu from an outside number (i.e. their cell phone, landline, etc.) and enter the PIN for the menu to be able to re-record it.", "suppress_playing_of_invalid_entry": "Suppress playing of Invalid Entry", @@ -572,6 +601,11 @@ "add_time_of_day_label": "Add Time of Day", "all_other_times": "All other times", "name_regex": "/^[a-zA-Z0-9\\s_']+$/", + "toastr": { + "warning": { + "missingDay": "Please select at least one day of the week" + } + }, "__comment": "UI-1929: adding time of day sets to options in time of days", "__version": "4.1", "types": { @@ -599,7 +633,7 @@ "add_user": "Add a user", "ring_this_users_devices_for": "Ring this user's devices for", "seconds": "seconds", - "allow_this_user_to_call_himself": "Allow this user to call himself.", + "allow_this_user_to_call_themselves": "Allow this user to call themselves.", "when_you_check_this_box": "When you check this box, calls from the user's own extension to themselves will ring the extension. If this box isn't checked, calls from the user's own extension to themselves will go to their voicemail.", "select_user": "Select User", "create_user": "Create User", @@ -631,8 +665,6 @@ "email_notifications": "Email Notifications", "voicemail": "Voicemail", "voicemail_data_content": "By checking this option, an email will be sent to the specified e-mail address each time this user gets a voicemail.", - "fax": "Fax", - "fax_data_content": "By checking this option, an email will be sent to the specified e-mail address each time you get a Fax.", "in_house_calls": "In-House Calls", "caller_id_name": "Caller ID Name", "caller_id_name_placeholder": "Name", @@ -731,13 +763,23 @@ }, "caller_id": { "name": "Please only enter alphanumeric characters, space or comma", - "number": "Please enter a valid phone number" + "number": "Please enter a valid phone number", + "realm": "Please enter a valid realm" } }, "__version": "4.0", "__comment": "UI-2475: add a failover option to callforward", "failover_callforward": "Failover", - "failover_callforward_content": "When checked, if all this user's devices are unregistered, then the system will automatically call-forward (even if the Enable Call-Forward setting isn't enabled)" + "failover_callforward_content": "When checked, if all this user's devices are unregistered, then the system will automatically call-forward (even if the Enable Call-Forward setting isn't enabled)", + "__comment": "UI-2921: adding way to impersonate users", + "__version": "4.2", + "impersonate": "Impersonate", + "asserted": "Asserted Identity", + "caller_id_name_data_content4": "Define the Caller ID Name of this User, to be used for P-Asserted-Identity header (max. 30 chars).", + "caller_id_number_data_content4": "Define the Caller ID Number of this User, to be used for P-Asserted-Identity header.", + "caller_id_realm": "Caller ID Realm", + "caller_id_realm_placeholder": "Realm", + "caller_id_realm_data_content4": "Define the Caller ID Realm of this User, to be used for P-Asserted-Identity header." }, "vmbox": { "voicemail": "Voicemail", @@ -783,6 +825,10 @@ "delete_after_notification_data_content": "Delete the voicemail after the notification has been sent", "not_configurable": "Configurable via menu?", "not_configurable_data_content": " If unchecked, it will disallow the user to configure voicemail via the menu", + "fast_forward_rewind": "Enable fast-forward and rewind?", + "fast_forward_rewind_data_content": "If enabled, it will allow the user to fast forward and rewind their voicemail messages", + "oldest_message_first": "Sort voicemail box by oldest message first", + "oldest_message_first_data_content": "If enabled, voicemails will be played in order from oldest to newest", "delete": "Delete", "save": "Save", "voicemail_boxes_label": "Voicemail Boxes", @@ -803,19 +849,27 @@ "mp3": "mp3", "mp4": "mp4", "wav": "wav", - "default": "Account Default" + "default": "Account Default", + "__comment": "UI-3040: add temporary greeting", + "temporary_unavailable_message": "Temporary Message", + "temporary_unavailable_message_data_content": "Select the Temporary Unavailable message that you want to use for this this device. If you set this field, it will take precedence over the Unavailable message, but if you select - Not set -, then the Unavailable message will be played instead." }, "__comment": "UI-1493: Adding accountSettings to advanced callflows app", "__version": "3.22", "accountSettings": { "title": "Account Settings", "callerId": { - "titleOutbound": "Account's Outbound Caller ID", - "titleInbound": "Account's Inbound Caller ID", + "titleOutbound": "Account's External/Off-net Caller ID", + "titleInbound": "Account's Internal/On-net Caller ID", "titleEmergency": "Account's Emergency Caller ID", + "titleAsserted": "Account's Asserted ID", "nameLabel": "Caller ID Name:", "numberLabel": "Caller ID Number:", - "defaultNumber": "Default" + "realmLabel": "Caller ID Realm:", + "defaultNumber": "Default", + "messages": { + "invalidNumber": "Please enter a valid number" + } }, "musicOnHold": { "title": "Account's Music on Hold", @@ -828,7 +882,8 @@ "__comment": "UI-2654: Allow shoutcast URL for MoH", "__version": "v4.1", "shoutcastURL": "Stream URL", - "shoutcastURLHelp": "You can type any URL including :// (http, https, shout...)" + "shoutcastURLHelp": "You can type any URL including :// (http, https, shout...)", + "shoutcastURLWarning": "WARNING: If the stream selected here attempts to be played, and is unavailable, the call may fail completely. Please make sure the stream you use is available 24/7." }, "blacklist": { "title": "Blacklists" @@ -860,6 +915,7 @@ "star_data_content": "The star is mandatory for any feature code, that's why it has been added by default.", "feature_codes_label": "Feature Codes", "nothing_to_save": "Nothing to save", + "directed_ext_pickup": "Directed Extension Pickup", "enable_call_forward": "Enable Call-Forward", "call_forward_cat": "Call-Forward", "disable_call_forward": "Disable Call-Forward", @@ -978,6 +1034,15 @@ "selectedUsers": "Selected Users" }, + "setCav": { + "title": "Set CAV", + "popupTitle": "Setting custom application vars", + "tip": "Set Custom Application Var ", + "help": "This feature allows you to set custom application variables providing key/value", + "key": "Key", + "value": "Value" + }, + "__comment": "UI-2646: adding ring group togle to adv. callflows", "__version": "v4.1", "ringGroupToggle": { @@ -1139,6 +1204,48 @@ "dragAndDropAction": "Drag actions from the actions panel to the callflow box. You can customize a callflow by adding more actions.
    ", "nextBtnText": "Next »", "endTourBtnText": "Close" + }, + + "__comment": "UI-3210: Add Set Ringtone callflow element", + "setAlertInfo": { + "name": "Distinctive Ring", + "title": "Set Distinctive Ring", + "label": "\"Alert-Info\" Header", + "tip": "Set distinctive ring for incoming call" + }, + + "webhook": { + "help": "This feature allows you to trigger a webhook call at any level of the callflow, to get \"real time\" info on how the callflow is behaving.", + "popupTitle": "Trigger Webhook", + "title": "Webhook", + "tip": "Trigger a webhook at any level in a callflow to get \"real time\" info on how the callflow is behaving.", + "uri": { + "label": "URL", + "help": "The HTTP URI to send the request", + "errorMessages": { + "url": "Invalid URL" + } + }, + "httpVerb": { + "label": "Request Type", + "help": "HTTP method to use when sending the request" + }, + "format": { + "label": "Body Format", + "help": "Format to use when sending the webhook ", + "options": { + "formData": "FORM-DATA", + "json": "JSON" + } + }, + "retries": { + "label": "Re-try attempts", + "help": "How many times to retry the request if the host isn't available" + }, + "customData": { + "label": "Custom data (optional)", + "help": "These properties will be added to the event and will overwrite existing values" + } } }, "oldCallflows": { @@ -1147,7 +1254,6 @@ "advanced_cat": "Advanced", "call_recording_cat": "Call Recording", "caller_id_cat": "Caller-ID", - "integrations_cat": "Integrations", "delete_callflow": "Delete callflow", "save_changes": "Save changes", "invalid_number": "Invalid number!", @@ -1161,6 +1267,7 @@ "hide_from_contact_list": "Hide from Contact List", "giving_a_name_to_a_callflow": "Giving a name to a callflow isn't mandatory. Leave the field blank and the callflow will be displayed in the left listing as the list of numbers used in this callflow.", "popup_title": "Edit Callflow Name", + "callflow_preview_title": "Callflow Preview", "add_number": "Add number", "add_a_number": "Add a number", "available_numbers": "Spare Numbers", @@ -1269,7 +1376,7 @@ "callflow_module_label": "Callflow Module", "add_callflow_label": "Add Callflow", "the_owner_of_this_device_is_already": "The owner of this device is already in the ring group. By adding this device, you will remove the User from this ring group. Would you like to continue anyway?", - "this_user_has_already_some_devices": "This user has already some devices belonging to him in this ring group. By adding him to the ring group, you will remove devices that were already in the ring group. Would you like to continue anyway?", + "this_user_has_already_some_devices": "This user has already some devices belonging to them in this ring group. By adding them to the ring group, you will remove devices that were already in the ring group. Would you like to continue anyway?", "undefined_device": "Undefined Device", "ring_group_val": "Ring Group - ", "not_setting_a_pin": "Not setting a PIN is a security risk, are you sure you don\\'t want to set a PIN?", @@ -1296,19 +1403,7 @@ "current": "Current", "original": "Original" } - }, - "check_cid": "Match caller number", - "check_cid_tip": "Branch in a callflow based on the A number", - "check_cid_match": "Match", - "check_cid_nomatch": "No match", - "check_cid_matchnomatch": "Match or no match?", - "regex": "Regex", - "webhook": "Send webhook", - "webhook_tip": "Send a webhook to an external webservice when this callflow node is hit", - "webhook_title": "Send a HTTP webhook", - "webhook_uri": "URI", - "webhook_method": "HTTP method", - "webhook_retry": "# retries" + } }, "__comment": "UI-1260: created common control for carrier selection", "__version": "v3.20_s2", @@ -1324,5 +1419,9 @@ "title": "Show All Callflows", "help": "As an admin, you're allowed to see all the existing callflows in this page. This include \"Applications\" Callflows that are created by other apps, but that you don't necesserarily want to update. If you wish to reduce clutter, you can switch this off to hide these callflows." } + }, + "node": { + "disabled": "Node disabled", + "confirmEnable": "This node is disabled. Do you want to enable it?" } } diff --git a/src/apps/callflows/metadata/app.json b/src/apps/callflows/metadata/app.json index 09eb561..bd4e8ed 100644 --- a/src/apps/callflows/metadata/app.json +++ b/src/apps/callflows/metadata/app.json @@ -3,8 +3,8 @@ "i18n": { "en-US": { "label": "Callflows", - "description": "The Callflow Manager allows you manage Callflows as well as various VOIP entities.", - "extended_description": "Advanced Callflows features a drag and drop interface which allows users to select from over 50 items in our “call handling toolbox” to chain together. These chains, known as callflows, allow you to manipulate the flow a call takes as a caller traverses various features, menus and call routing decisions in the system. Use the Advanced Callflow editor to configure every step a caller can take when calling a phone number or extension. Route calls to menus, ring groups, voicemails, conference bridges, call queues, call recordings and more.", + "description": "The Callflows allows you manage Callflows as well as various VOIP entities.", + "extended_description": "The Callflows app features a drag and drop interface which allows users to select from over 50 items in our “call handling toolbox” to chain together. These chains, known as callflows, allow you to manipulate the flow a call takes as a caller traverses various features, menus and call routing decisions in the system. Use the Callflows app editor to configure every step a caller can take when calling a phone number or extension. Route calls to menus, ring groups, voicemails, conference bridges, call queues, call recordings and more.", "features": [ "Drag and drop management", "50+ call handling actions such as: Time of Day Routing, Device/User Routing, Menus/IVRs, Call Pickup, BLF/Presence Manipulation, Outbound Call Routing...", @@ -13,7 +13,9 @@ ] } }, - "tags": [], + "tags": [ + "admin" + ], "icon": "Callflows_app.png", "api_url": "http://10.26.0.41:8000/v2", "author": "2600Hz", @@ -29,5 +31,6 @@ "documentation": "{documentation_url}", "howto": "{howto_video_url}" }, + "phase": "gold", "pvt_type": "app" } diff --git a/src/apps/callflows/style/app.css b/src/apps/callflows/style/app.css index e6bbef1..adac798 100644 --- a/src/apps/callflows/style/app.css +++ b/src/apps/callflows/style/app.css @@ -16,22 +16,27 @@ float: left; width: 85%; } -#ws_callflow .callflow .root { + +#ws_callflow .callflow .root, +.callflow-preview .callflow .root { width: 322px; } -#ws_callflow .callflow .root > .top_bar { +#ws_callflow .callflow .root > .top_bar, +.callflow-preview .callflow .root > .top_bar { background: #0081D6; height: 25px; text-align: left; border-radius: 6px 6px 0 0; } -#ws_callflow .callflow .root > .top_bar > span { +#ws_callflow .callflow .root > .top_bar > span, +.callflow-preview .callflow .root > .top_bar > span { line-height: 25px; } -#ws_callflow .callflow .root > .top_bar .name { +#ws_callflow .callflow .root > .top_bar .name, +.callflow-preview .callflow .root > .top_bar .name { float: left; margin-left: 10px; font-weight: normal; @@ -39,22 +44,31 @@ cursor: default; } -#ws_callflow .callflow .root > .top_bar .add_number { +#ws_callflow .callflow .root > .top_bar .add_number, +.callflow-preview .callflow .root > .top_bar .add_number { float: right; } -#ws_callflow .callflow .root > .content .number_row { +#ws_callflow .callflow .root > .content .number_row, +.callflow-preview .callflow .root > .content .number_row { height: 30px; background: #0081D6; - border-top: 1px solid white; + border-top: 1px solid white } #ws_callflow .callflow .root > .content .number_row:last-child { + background: none; + background-color: #0081D6; height: 30px; border-radius: 0px 0px 2px 2px; } -#ws_callflow .callflow .root > .content .number_column { +.callflow-preview .callflow .root > .content .number_row:last-child:not(:first-child) { + display: none !important; +} + +#ws_callflow .callflow .root > .content .number_column, +.callflow-preview .callflow .root > .content .number_column { float: left; height: 30px; line-height: 30px; @@ -65,31 +79,37 @@ color: white; } -#ws_callflow .callflow .root > .content .number_column.full { +#ws_callflow .callflow .root > .content .number_column.full, +.callflow-preview .callflow .root > .content .number_column.full { width: 100%; text-align: center; } -#ws_callflow .callflow .root > .content .number_column.second { +#ws_callflow .callflow .root > .content .number_column.second, +.callflow-preview .callflow .root > .content .number_column.second { width: 162px; border-left: 1px solid white; } -#ws_callflow .callflow .root > .content .number_column.first { +#ws_callflow .callflow .root > .content .number_column.first, +.callflow-preview .callflow .root > .content .number_column.first { width: 159px; } -#ws_callflow .callflow .root > .content .number_column.empty { +#ws_callflow .callflow .root > .content .number_column.empty, +.callflow-preview .callflow .root > .content .number_column.empty { color: white; cursor: default; } -#ws_callflow .callflow .root > .content .number_column.add-number { - cursor: pointer; +#ws_callflow .callflow .root > .content .number_column.add-number, +.callflow-preview .callflow .root > .content .number_column.add-number { + cursor: pointer; background: #22A5FF; } -#ws_callflow .callflow .root > .content .number_column .delete { +#ws_callflow .callflow .root > .content .number_column .delete, +.callflow-preview .callflow .root > .content .number_column .delete { background-image: url(static/images/btn_delete.png); background-repeat: no-repeat; background-position: center; @@ -103,18 +123,37 @@ cursor: pointer; } -#ws_callflow .callflow .node { +#ws_callflow .callflow .root > .content .number_column .delete:hover, +.callflow-preview .callflow .root > .content .number_column .delete:hover { + background-image: url(static/images/btn_delete_blue.png); +} + +.callflow-preview span.delete, +.callflow-preview .number_column.empty, +.callflow-preview span.edit_icon { + display: none !important; +} + +#ws_callflow .callflow .node, +.callflow-preview .callflow .node { display: inline-block; cursor: -moz-grab; cursor: -webkit-grab; cursor: grab; } -#ws_callflow .callflow .node[name="root"] { +#ws_callflow .callflow .node.disabled, +.callflow-preview .callflow .node.disabled { + opacity: 0.6; +} + +#ws_callflow .callflow .node[name="root"], +.callflow-preview .callflow .node[name="root"] { cursor: default; } -#ws_callflow .callflow .node .node-options .delete { +#ws_callflow .callflow .node .node-options .delete, +.callflow-preview .callflow .node .node-options .delete { background-image: url(static/images/btn_delete.png); background-repeat: no-repeat; background-position: center; @@ -128,12 +167,20 @@ color: #555; } -#ws_callflow .tool .fa { +#ws_callflow .callflow .node .node-options .delete:hover, +.callflow-preview .callflow .node .node-options .delete:hover { + background-image: url(static/images/btn_delete_blue.png); +} + +#ws_callflow .tool .fa, +.callflow-preview .tool .fa { margin: 2px 2px 5px; color: white; + display: inline-block; } -#ws_callflow .tools .category { +#ws_callflow .tools .category, +.callflow-preview .tools .category { text-align: center; background: #0081D6; background-position: top center; @@ -141,13 +188,15 @@ border-bottom: 1px solid white; } -#ws_callflow .tools .category .content { +#ws_callflow .tools .category .content, +.callflow-preview .tools .category .content { background-color: white; border: 1px solid #0081D6; padding: 1px 0px 3px; } -#ws_callflow .tools .open { +#ws_callflow .tools .open, +.callflow-preview .tools .open { font-size: 12px; height: 26px; line-height: 26px; @@ -155,12 +204,14 @@ background-position: 5px center; } -#ws_callflow .tools .active .open { +#ws_callflow .tools .active .open, +.callflow-preview .tools .active .open { color: white; position: relative; } -#ws_callflow .tools .active .open::before { +#ws_callflow .tools .active .open::before, +.callflow-preview .tools .active .open::before { content: '\f078'; font: normal normal normal 14px/1 FontAwesome; display: inline-block; @@ -173,17 +224,20 @@ color: white; } -#ws_callflow .tools .inactive .open { +#ws_callflow .tools .inactive .open, +.callflow-preview .tools .inactive .open { color: white; position: relative; cursor: pointer; } -#ws_callflow .tools .inactive .open:hover { +#ws_callflow .tools .inactive .open:hover, +.callflow-preview .tools .inactive .open:hover { background: #22A5FF; } -#ws_callflow .tools .inactive .open::before { +#ws_callflow .tools .inactive .open::before, +.callflow-preview .tools .inactive .open::before { content: '\f054'; font: normal normal normal 14px/1 FontAwesome; display: inline-block; @@ -196,7 +250,8 @@ color: white; } -#ws_callflow .tools .tool { +#ws_callflow .tools .tool, +.callflow-preview .tools .tool { background: white; float: left; width: 78px; @@ -208,12 +263,14 @@ margin: 1px 1px 1px 2px; } -#ws_callflow .destination { +#ws_callflow .destination, +.callflow-preview .destination { border-radius: 2px; border: 3px solid #22A5FF; } -#ws_callflow .tools .tool .action { +#ws_callflow .tools .tool .action, +.callflow-preview .tools .tool .action { z-index: 19; height: 53px; border-radius: 6px; @@ -224,31 +281,38 @@ width: 76px; } -#ws_callflow .tools .tool .action:hover { +#ws_callflow .tools .tool .action:hover, +.callflow-preview .tools .tool .action:hover { background: #22A5FF; border: 1px solid #22A5FF; } -#ws_callflow .tools .app_list_nav { + +#ws_callflow .tools .app_list_nav, +.callflow-preview .tools .app_list_nav { background: white; } -#ws_callflow .callflow .icons_black.node { +#ws_callflow .callflow .icons_black.node, +.callflow-preview .callflow .icons_black.node { width: 132px; height: 84px; background: #0081D6; border-radius: 6px; } -#ws_callflow #ws_cf_flow .children .child:last-child:not(:first-child) { +.callflow-preview .children .child:last-child:not(:first-child), + #ws_cf_flow .children .child:last-child:not(:first-child) { padding-right: 10px; } +.callflow-preview .children .child:first-child:not(:last-child), #ws_callflow #ws_cf_flow .children .child:first-child:not(:last-child) { padding-left: 10px; } -#ws_callflow .children > .child > .div_line { +#ws_callflow .children > .child > .div_line, +.callflow-preview .children > .child > .div_line { display: inline-block; height: 6px; width: 100%; @@ -260,20 +324,24 @@ padding: 0px; float: left; } -#ws_callflow .children > .child:first-child > .div_line { +#ws_callflow #ws_cf_flow .children > .child:first-child > .div_line, +.callflow-preview .children > .child:first-child > .div_line { width: 50%; float: right; } +.callflow-preview .children > .child:last-child > .div_line, #ws_callflow .children > .child:last-child > .div_line { width: 50%; float: left; } -#ws_callflow .children > .child:first-child:last-child > .div_line { +#ws_callflow .children > .child:first-child:last-child > .div_line, +.callflow-preview .children > .child:first-child:last-child > .div_line { display: none; } -#ws_callflow .children > .child > .span_arrow { +#ws_callflow .children > .child > .span_arrow, +.callflow-preview .children > .child > .span_arrow { display: inline-block; width: 145px; background-repeat: no-repeat; @@ -283,43 +351,51 @@ position: relative; } -#ws_callflow .children > .child > .span_arrow.small { +#ws_callflow .children > .child > .span_arrow.small, +.callflow-preview .children > .child > .span_arrow.small { height: 31px; background-image: url(static/images/center_arrow.png); } -#ws_callflow .children > .child:first-child > .span_arrow.small { +#ws_callflow .children > .child:first-child > .span_arrow.small, +.callflow-preview .children > .child:first-child > .span_arrow.small { background-image: url(static/images/left_arrow.png); } -#ws_callflow .children > .child:last-child > .span_arrow.small { +#ws_callflow .children > .child:last-child > .span_arrow.small, +.callflow-preview .children > .child:last-child > .span_arrow.small { background-image: url(static/images/right_arrow.png); } -#ws_callflow .children > .child:first-child:last-child > .span_arrow.small { +#ws_callflow .children > .child:first-child:last-child > .span_arrow.small, +.callflow-preview .children > .child:first-child:last-child > .span_arrow.small { background-image: url(static/images/small_arrow.png); } -#ws_callflow .children > .child > .span_arrow.large { +#ws_callflow .children > .child > .span_arrow.large, +.callflow-preview .children > .child > .span_arrow.large { float: none; height: 48px; background-image: url(static/images/tall_arrow.png); } -#ws_callflow .children > .child > .fa { +#ws_callflow .children > .child > .fa, +.callflow-preview .children > .child > .fa { font-size: 48px; color: #303039; margin: 9px 0 7px; } -#ws_callflow .a_link_option { +#ws_callflow .a_link_option, +.callflow-preview .a_link_option { color: white; font-size: 17px; display: block; padding: 2px 0; } -#ws_callflow .div_option { +#ws_callflow .div_option, +.callflow-preview .div_option { display: inline-block; line-height: 1; width: 131px; @@ -330,26 +406,30 @@ border-radius: 2px; } -#ws_callflow .div_icon { +#ws_callflow .div_icon, +.callflow-preview .div_icon { height: 46px; padding: 0 10px; } -#ws_callflow .div_icon > .fa { +#ws_callflow .div_icon > .fa, +.callflow-preview .div_icon > .fa { font-size: 23px; margin-right: 7px; color: white; vertical-align: top; } -#ws_callflow .module { +#ws_callflow .module, +.callflow-preview .module { font-size: 13px; height: 49px; margin-top: 15px; cursor: default; } -#ws_callflow .div_icon .module_name { +#ws_callflow .div_icon .module_name, +.callflow-preview .div_icon .module_name { text-transform: uppercase; text-align: center; vertical-align: top; @@ -360,12 +440,26 @@ color: white; } -#ws_callflow .details { +#ws_callflow .details, +.callflow-preview .details { font-size: 10px; overflow: hidden; color: white; } +.dialog_popup.callflow-preview { + padding-left: 0px; + padding-right: 0px; +} + +.callflow-preview .details a { + color: #22A5FF; +} + +.callflow-preview * { + cursor: default !important; /* Only a preview, cannot click */ +} + /* Add number and Edit name popups */ .dialog_popup_new { padding: 15px; @@ -455,7 +549,8 @@ cursor: grabbing !important; } -#ws_callflow .root .top_bar .edit_icon { +#ws_callflow .root .top_bar .edit_icon, +.callflow-preview .root .top_bar .edit_icon { cursor: pointer; display: inline-block; margin: 3px 0 0 7px; @@ -464,7 +559,8 @@ color: white; } -#ws_callflow .root .top_bar .edit_icon i { +#ws_callflow .root .top_bar .edit_icon i, +.callflow-preview .root .top_bar .edit_icon i { color: white; } @@ -496,11 +592,24 @@ font-size: 23px; } +#callflow_container .callflow-help, .popup_help .callflow-help { + background: url(static/images/callflow_help.gif) no-repeat center; + height: 644px; + width: 847px; + margin: 20px auto auto; + border-radius: 10px; +} + +#callflow_container .callflow-content.edition-mode .callflow-help { + display: none; +} + #callflow_container .callflow-content.listing-mode #ws_callflow { display: none; } -#ws_callflow { +#ws_callflow, +.callflow-preview { width: 100%; } @@ -514,88 +623,112 @@ width: 50%; } -#ws_callflow #callflow_header { +#ws_callflow #callflow_header, +.callflow-preview #callflow_header { height: 30px; margin-top: 15px; width: 100%; } -#ws_callflow #callflow_header #pending_change { +#ws_callflow #callflow_header #pending_change, +.callflow-preview #callflow_header #pending_change { text-align: center; display: none; } -#ws_callflow #callflow_header #pending_change span { +#ws_callflow #callflow_header #pending_change span, +.callflow-preview #callflow_header #pending_change span { color: #22A5FF; + font-weight: lighter; font-style: italic; } -#ws_callflow #ws_cf_flow { +#ws_callflow #ws_cf_flow, +.callflow-preview #ws_cf_flow { width: 100%; overflow-x: auto; padding-top: 10px; text-align: center; } -#ws_callflow span.flow { +#ws_callflow .callflow-preview, +.callflow-preview .callflow-preview { + width: 100%; + overflow-x: auto; + padding-top: 10px; + text-align: center; +} + +#ws_callflow span.flow, +.callflow-preview span.flow { width: 80%; } -#ws_callflow .child { +#ws_callflow .child, +.callflow-preview .child { display: inline-block; vertical-align: top; text-align: center; white-space: normal; } -#ws_callflow .branch { +#ws_callflow .branch, +.callflow-preview .branch { display: block; text-align: center; } -#ws_callflow .node.active { +#ws_callflow .node.active, +.callflow-preview .node.active { background-color: #fff; border-radius: 2px; border: 3px solid #22A5FF; } -#ws_callflow .node.inactive { +#ws_callflow .node.inactive, +.callflow-preview .node.inactive { filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.5; } -#ws_callflow .children { +#ws_callflow .children, +.callflow-preview .children { display: block; white-space: pre; } -#ws_callflow .flowchart { +#ws_callflow .flowchart, +.callflow-preview .flowchart { margin-right: 180px; overflow: auto; } -#ws_callflow .tools { +#ws_callflow .tools, +.callflow-preview .tools { float: right; overflow-y: auto; overflow-x: hidden; } -#ws_callflow .tools #ws_cf_tools { +#ws_callflow .tools #ws_cf_tools, +.callflow-preview .tools #ws_cf_tools { padding-right: 10px; padding-top: 10px; padding-bottom:30px; width: 168px; } -#ws_callflow .tools .search-box { +#ws_callflow .tools .search-box, +.callflow-preview .tools .search-box { border-left: 1px solid #0081D6; border-right: 1px solid #0081D6; position: relative; } -#ws_callflow .tools .search-box input { +#ws_callflow .tools .search-box input, +.callflow-preview .tools .search-box input { width: 120px; height: 15px; margin-top: 3px; @@ -605,29 +738,35 @@ box-shadow: none; } -#ws_callflow .tool { +#ws_callflow .tool, +.callflow-preview .tool { text-align: center; vertical-align: middle; } -#ws_callflow .tool_name { +#ws_callflow .tool_name, +.callflow-preview .tool_name { font-size: 11px; line-height: 11px; } -#ws_callflow .tools .category.inactive .content { +#ws_callflow .tools .category.inactive .content, +.callflow-preview .tools .category.inactive .content { display: none; } -#ws_callflow .tool .action.inactive { +#ws_callflow .tool .action.inactive, +.callflow-preview .tool .action.inactive { display: none; } -#ws_callflow .tool .action.active { +#ws_callflow .tool .action.active, +.callflow-preview .tool .action.active { z-index: 10000; } -#ws_callflow .title { +#ws_callflow .title, +.callflow-preview .title { background: #0081D6; font-size: 15px; height: 25px; @@ -638,7 +777,8 @@ font-weight: normal; } -#callflow_container .wrapper_callflow_buttons { +#callflow_container .wrapper_callflow_buttons, +.callflow-preview .wrapper_callflow_buttons { display: block; width: 100%; text-align: center; @@ -646,18 +786,21 @@ margin-bottom: 5px; } -#callflow_container .wrapper_callflow_buttons .monster-button { +#callflow_container .wrapper_callflow_buttons .monster-button, +.callflow-preview .wrapper_callflow_buttons .monster-button { width: 114px; text-align: center; display: inline-block; margin-left: 0; } -#callflow_container .wrapper_callflow_buttons .monster-button:first-child { +#callflow_container .wrapper_callflow_buttons .monster-button:first-child, +.callflow-preview .wrapper_callflow_buttons .monster-button:first-child { margin-right: 10px; } -#callflow_container .callflow_helpbox_wrapper { +#callflow_container .callflow_helpbox_wrapper, +.callflow-preview .callflow_helpbox_wrapper { position: absolute; right: 185px; width: 160px; @@ -666,7 +809,8 @@ z-index: 100; } -#callflow_container .callflow_helpbox_wrapper .tip_box { +#callflow_container .callflow_helpbox_wrapper .tip_box, +.callflow_preview .callflow_helpbox_wrapper .tip_box { background-color: #3D3D3D; border: 1px solid #333333; border-radius: 2px; @@ -678,13 +822,15 @@ color: white; } -#callflow_container .tooltip { +#callflow_container .tooltip, +.callflow_preview .tooltip { float: right; margin-top: 6px; cursor: pointer; } -#callflow_container .pulse-box { +#callflow_container .pulse-box, +.callflow-preview .pulse-box { -webkit-animation: "pulse-box" 1s ease-in-out 0 infinite alternate; animation-name: pulse-box; @@ -706,7 +852,8 @@ } /* JR's customization */ -#callflow_container { +#callflow_container, +.callflow-preview .callflow { min-height: 100%; } @@ -718,6 +865,11 @@ overflow-y: auto; } +.callflow-preview.callflow { + background-color: #fff; + overflow-y: auto; +} + #callflow_container .left-bar-container { float: left; background-color: #F3F3F3; @@ -870,6 +1022,10 @@ white-space: nowrap; } +.callflow-preview #callflow_jump { + margin-bottom: 10px; +} + /* Popups.css */ .dialog_popup { padding: 10px 20px; @@ -980,7 +1136,7 @@ .callflows-port .reset_border { border:0; - background-color:none; + background-color: transparent; } .callflows-port .gradient_strong { @@ -1116,6 +1272,9 @@ margin-left:20px; display:inline; } +.callflows-port .pill-content .edit_create a { + color: #EEE; +} .callflows-port .pill-content .edit_create > a:not(:first-child) { margin-left: 15px; @@ -1147,9 +1306,6 @@ border-color: #22A5FF; color: white; background: #22A5FF; - /*box-shadow:inset 0 0 10px 1px #000; - -moz-box-shadow:inset 0 0 10px 1px #000; - -webkit-box-shadow:inset 0 0 10px 1px #000;*/ } .callflows-port .btn.black:hover { @@ -1317,7 +1473,7 @@ .callflows-port .tabs { list-style: none; padding: 0; - background-color:none; + background-color: transparent; } .callflows-port .tabs > li { @@ -1352,6 +1508,14 @@ text-decoration: none; } +.callflows-port .tabs > li:first-child.active { + border-left:1px solid #22A5FF; +} + +.callflows-port .tabs > li:last-child.active { + border-right:0; +} + .callflows-port .tabs > li > a > .fa { margin-right: 5px; } @@ -1441,7 +1605,7 @@ text-align: center; width: 120px; height: 120px; - padding: 0px; + padding: 0; font-size: 20px; cursor: pointer; border: solid 1px #303039; @@ -1484,8 +1648,7 @@ width: 800px; /* Arbitrary width if calc not supported */ width: -webkit-calc(100% - 241px); width: -moz-calc(100% - 241px); - width: -o-calc(100% - 241px); - width: calc(100%-241px); + width: calc(100% - 241px); } @@ -1702,7 +1865,6 @@ text-align: right; } - .callflows-port .callflow-panel { background: #22A5FF; display: inline-block; @@ -1758,4 +1920,4 @@ .tour-backdrop { opacity: 0.6; -} \ No newline at end of file +} diff --git a/src/apps/callflows/style/static/images/callflow_help.gif b/src/apps/callflows/style/static/images/callflow_help.gif new file mode 100644 index 0000000..73747f7 Binary files /dev/null and b/src/apps/callflows/style/static/images/callflow_help.gif differ diff --git a/src/apps/callflows/submodules/blacklist/blacklist.css b/src/apps/callflows/submodules/blacklist/blacklist.css index e74845c..36660a1 100644 --- a/src/apps/callflows/submodules/blacklist/blacklist.css +++ b/src/apps/callflows/submodules/blacklist/blacklist.css @@ -90,4 +90,4 @@ color: #22A5FF; margin-right: 10px; margin-top :15px; -} \ No newline at end of file +} diff --git a/src/apps/callflows/submodules/blacklist/blacklist.js b/src/apps/callflows/submodules/blacklist/blacklist.js index 32c4cc3..8d20a30 100644 --- a/src/apps/callflows/submodules/blacklist/blacklist.js +++ b/src/apps/callflows/submodules/blacklist/blacklist.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -8,7 +8,7 @@ define(function(require){ subscribe: { 'callflows.blacklist.edit': 'blacklistEdit', - 'callflows.fetchActions': 'blacklistDefineActions', + 'callflows.fetchActions': 'blacklistDefineActions' }, blacklistDefineActions: function(args) { @@ -24,7 +24,9 @@ define(function(require){ resource: 'blacklist.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -40,18 +42,30 @@ define(function(require){ blacklistEdit: function(args) { var self = this, afterGetData = function(data) { - var template = $(monster.template(self, 'blacklist-edit', {data: data})), + var template = $(self.getTemplate({ + name: 'edit', + data: { + data: data + }, + submodule: 'blacklist' + })), blacklistForm = template.find('#blacklist-form'), $listNumbers = template.find('.saved-numbers'); monster.ui.validate(blacklistForm, { rules: { - 'name': { required: true }, + 'name': { required: true } } }); _.each(data.numbers, function(v, number) { - $listNumbers.append(monster.template(self, 'blacklist-addNumber', {number: number})); + $listNumbers.append($(self.getTemplate({ + name: 'addNumber', + data: { + number: number + }, + submodule: 'blacklist' + }))); }); self.blacklistBindEvents(data, template, args.callbacks); @@ -61,12 +75,11 @@ define(function(require){ .append(template); }; - if(args.data.id) { + if (args.data.id) { self.blacklistGet(args.data.id, function(data) { afterGetData(data); }); - } - else { + } else { afterGetData({}); } }, @@ -77,7 +90,14 @@ define(function(require){ var number = template.find('#number_value').val(); if (number) { - $('.list-numbers .saved-numbers', template).prepend(monster.template(self, 'blacklist-addNumber', { number: number })); + $('.list-numbers .saved-numbers', template) + .prepend($(self.getTemplate({ + name: 'addNumber', + data: { + number: number + }, + submodule: 'blacklist' + }))); $('#number_value', template).val(''); } @@ -141,14 +161,20 @@ define(function(require){ }); },*/ - blacklistBindEvents: function(data, template, callbacks) { var self = this, addNumber = function(e) { var number = template.find('#number_value').val(); - if(number) { - $('.list-numbers .saved-numbers', template).prepend(monster.template(self,'blacklist-addNumber', { number: number })); + if (number) { + $('.list-numbers .saved-numbers', template) + .prepend($(self.getTemplate({ + name: 'addNumber', + data: { + number: number + }, + submodule: 'blacklist' + }))); $('#number_value', template).val(''); } @@ -170,7 +196,7 @@ define(function(require){ $('.add-number', template).bind('keypress', function(e) { var code = e.keyCode || e.which; - if(code === 13) {; + if (code === 13) { addNumber(e); } }); @@ -187,7 +213,7 @@ define(function(require){ }); $('.blacklist-save', template).click(function() { - var formData = form2object('blacklist-form'), + var formData = monster.ui.getFormData('blacklist-form'), cleanData = self.blacklistCleanFormData(formData), mapNumbers = {}; @@ -198,7 +224,7 @@ define(function(require){ cleanData.numbers = mapNumbers; - if(data.id) { + if (data.id) { cleanData.id = data.id; } @@ -221,10 +247,9 @@ define(function(require){ blacklistSave: function(data, callback) { var self = this; - if(data.id) { + if (data.id) { self.blacklistUpdate(data, callback); - } - else { + } else { self.blacklistCreate(data, callback); } }, @@ -236,7 +261,9 @@ define(function(require){ resource: 'blacklist.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); diff --git a/src/apps/callflows/views/blacklist-addNumber.html b/src/apps/callflows/submodules/blacklist/views/addNumber.html similarity index 96% rename from src/apps/callflows/views/blacklist-addNumber.html rename to src/apps/callflows/submodules/blacklist/views/addNumber.html index c3b0d6d..a3bf4a9 100644 --- a/src/apps/callflows/views/blacklist-addNumber.html +++ b/src/apps/callflows/submodules/blacklist/views/addNumber.html @@ -6,4 +6,4 @@ - \ No newline at end of file + diff --git a/src/apps/callflows/views/blacklist-edit.html b/src/apps/callflows/submodules/blacklist/views/edit.html similarity index 100% rename from src/apps/callflows/views/blacklist-edit.html rename to src/apps/callflows/submodules/blacklist/views/edit.html diff --git a/src/apps/callflows/submodules/callcenter/callcenter.js b/src/apps/callflows/submodules/callcenter/callcenter.js index c5c8ef8..d4feac3 100644 --- a/src/apps/callflows/submodules/callcenter/callcenter.js +++ b/src/apps/callflows/submodules/callcenter/callcenter.js @@ -1,9 +1,8 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), toastr = require('toastr'), - monster = require('monster'), - timezone = require('monster-timezone'); + monster = require('monster'); var app = { requests: { @@ -87,7 +86,7 @@ define(function(require){ callcenterDefineActions: function(args) { var self = this, - callflow_nodes= args.actions, + callflow_nodes = args.actions, i18nApp = self.i18n.active().callflows.callcenter; $.extend(callflow_nodes, { @@ -112,7 +111,7 @@ define(function(require){ var id = node.getMetadata('id'), returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } @@ -122,21 +121,24 @@ define(function(require){ self.getQueuesList(function(queues) { var popup, popup_html; - popup_html = $(monster.template(self, 'callcenter-queue-callflow' , { - i18n: self.i18n.active(), - objects: { - items: queues, - selected: node.getMetadata('id') || '' - } + popup_html = $(self.getTemplate({ + name: 'queue-callflow', + data: { + i18n: self.i18n.active(), + objects: { + items: queues, + selected: node.getMetadata('id') || '' + } + }, + submodule: 'callcenter' })); - if($('#queue_selector option:selected', popup_html).val() == undefined) { + if ($('#queue_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#queue_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#queue_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -155,14 +157,13 @@ define(function(require){ node.setMetadata('id', $('#queue_selector', popup).val()); node.caption = $('#queue_selector option:selected', popup).text(); popup.dialog('close'); - }); popup = monster.ui.dialog(popup_html, { title: self.i18n.active().callflows.callcenter.selectQueue, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -203,7 +204,7 @@ define(function(require){ return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -229,7 +230,7 @@ define(function(require){ return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -255,7 +256,7 @@ define(function(require){ return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -281,7 +282,7 @@ define(function(require){ return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -307,7 +308,7 @@ define(function(require){ return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -336,14 +337,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -406,24 +407,24 @@ define(function(require){ self.getUsersList(function(users) { defaults.field_data.users = users; - if(typeof data == 'object' && data.id) { - self.queueGet(data.id, function (queueData) { + if (typeof data === 'object' && data.id) { + self.queueGet(data.id, function(queueData) { var render_data = $.extend(true, defaults, queueData); render_data.field_data.old_list = []; - if('agents' in queueData.data) { + if ('agents' in queueData.data) { render_data.field_data.old_list = queueData.data.agents; } self.queueRender(render_data, target, callbacks); - if(typeof(callbacks.after_render) === 'function') { + if (typeof (callbacks.after_render) === 'function') { callbacks.after_render(); } }); } else { self.queueRender(defaults, target, callbacks); - if(typeof(callbacks.after_render) === 'function') { + if (typeof (callbacks.after_render) === 'function') { callbacks.after_render(); } } @@ -447,7 +448,7 @@ define(function(require){ }); }, - queueRenderList: function(_parent, callback){ + queueRenderList: function(_parent, callback) { var self = this, parent = _parent || $('#queue-content'), i18nApp = self.i18n.active().callflows.callcenter; @@ -456,7 +457,7 @@ define(function(require){ var map_crossbar_data = function(data) { var new_list = []; - if(data.length > 0) { + if (data.length > 0) { $.each(data, function(key, val) { new_list.push({ id: val.id, @@ -484,7 +485,7 @@ define(function(require){ accountId: self.accountId, generateError: false }, - success: function (data) { + success: function(data) { callback && callback(data.data); } }); @@ -499,19 +500,22 @@ define(function(require){ queuesId: queueId, generateError: false }, - success: function (_data) { - if(typeof(callback) === 'function') { + success: function(_data) { + if (typeof (callback) === 'function') { callback(_data); } } }); }, - queueRender: function(data, target, callbacks) { var self = this; data.i18nApp = self.i18n.active().callflows.callcenter; - var queue_html = $(monster.template(self, 'callcenter-queue-edit' , data)); + var queue_html = $(self.getTemplate({ + name: 'queue-edit', + data: data, + submodule: 'callcenter' + })); self.userListRender(data, queue_html); @@ -528,7 +532,7 @@ define(function(require){ $('.queue-save', queue_html).click(function(ev) { ev.preventDefault(); - if(monster.ui.valid($form)) { + if (monster.ui.valid($form)) { var form_data = monster.ui.getFormData($form[0]); var agentsList = []; @@ -543,7 +547,6 @@ define(function(require){ }; self.queueSave(form_data, data, callbacks.save_success, callbacks.save_error); - } else { toastr.error(self.i18n.active().callflows.callcenter.formHasErrorsMessage); } @@ -552,7 +555,6 @@ define(function(require){ $('.queue-delete', queue_html).click(function(ev) { ev.preventDefault(); - monster.ui.confirm(self.i18n.active().callflows.callcenter.deleteConfirmMessage, function() { self.queueDelete(data, callbacks.delete_success, callbacks.delete_error); }); @@ -563,19 +565,25 @@ define(function(require){ var $userSelect = $('#users-list', queue_html); - if($userSelect.val() != 'empty_option_user') { + if ($userSelect.val() !== 'empty_option_user') { var user_id = $userSelect.val(), user_data = { user_id: user_id, user_name: $('#option_user_' + user_id, queue_html).text() }; - if($('#row_no_data', queue_html).size() > 0) { + if ($('#row_no_data', queue_html).size() > 0) { $('#row_no_data', queue_html).remove(); } - $('.js-user-table-body', queue_html).prepend($(monster.template(self, 'callcenter-user-row' , user_data))); - $('#option_user_'+user_id, queue_html).hide(); + $('.js-user-table-body', queue_html).prepend( + $(self.getTemplate({ + name: 'user-row', + data: user_data, + submodule: 'callcenter' + })) + ); + $('#option_user_' + user_id, queue_html).hide(); $userSelect.val('empty_option_user'); } @@ -602,11 +610,17 @@ define(function(require){ $('#row_user_' + user_id, queue_html).remove(); //re-add it to the dropdown - $('#option_user_'+user_id, queue_html).show(); + $('#option_user_' + user_id, queue_html).show(); //if grid empty, add no data line - if($('.js-user-table-body .js-user-table-item', queue_html).size() == 0) { - $('.js-user-table-body', queue_html).append($(monster.template(self, 'callcenter-user-row'))); + if ($('.js-user-table-body .js-user-table-item', queue_html).size() === 0) { + $('.js-user-table-body', queue_html).append( + $(self.getTemplate({ + name: 'user-row', + data: {}, + submodule: 'callcenter' + })) + ); } }); @@ -625,7 +639,7 @@ define(function(require){ data: agentsIdList }, success: function(data) { - if(typeof(callback) === 'function' && data.data) { + if (typeof (callback) === 'function' && data.data) { callback(data.data); } } @@ -635,7 +649,7 @@ define(function(require){ queueDelete: function(data, success, error) { var self = this; - if(typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { monster.request({ resource: 'callcenter.queues.delete', data: { @@ -644,12 +658,12 @@ define(function(require){ generateError: false }, success: function(_data, status) { - if(typeof success == 'function') { + if (typeof success === 'function') { success(_data, status); } }, error: function(_data, status) { - if(typeof error == 'function') { + if (typeof error === 'function') { error(_data, status); } } @@ -660,14 +674,18 @@ define(function(require){ userListRender: function(data, parent) { var self = this; - if(data.data.id) { - if('agents' in data.data && data.data.agents.length > 0) { + if (data.data.id) { + if ('agents' in data.data && data.data.agents.length > 0) { var user_item; $.each(data.field_data.users, function(k, v) { - if(data.data.agents.indexOf(v.id) >= 0) { - var html = $(monster.template(self, 'callcenter-user-row' , { - user_id: v.id, - user_name: v.first_name + ' ' + v.last_name + if (data.data.agents.indexOf(v.id) >= 0) { + var html = $(self.getTemplate({ + name: 'user-row', + data: { + user_id: v.id, + user_name: v.first_name + ' ' + v.last_name + }, + submodule: 'callcenter' })); $('.js-user-table-body', parent).append(html); @@ -676,11 +694,23 @@ define(function(require){ }); } else { $('.js-user-table-body', parent).empty() - .append($(monster.template(self, 'callcenter-user-row'))); + .append( + $(self.getTemplate({ + name: 'user-row', + data: {}, + submodule: 'callcenter' + })) + ); } } else { $('.js-user-table-body', parent).empty() - .append($(monster.template(self, 'callcenter-user-row'))); + .append( + $(self.getTemplate({ + name: 'user-row', + data: {}, + submodule: 'callcenter' + })) + ); } }, @@ -688,21 +718,21 @@ define(function(require){ var self = this, normalized_data = self.normalizeData($.extend(true, {}, data.data, form_data)); - if(typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { var queueId = data.data.id; self.queueUpdate(queueId, normalized_data, function(queueData) { self.agentsSave(queueId, data.field_data.user_list.new_list, function(agentsData) { queueData.agents = agentsData.agents; - if(typeof(success) === 'function') { + if (typeof (success) === 'function') { success(queueData); } }); }); } else { - self.queueCreate(normalized_data, function(queueData){ + self.queueCreate(normalized_data, function(queueData) { self.agentsSave(queueData.id, data.field_data.user_list.new_list, function(agentsData) { queueData.agents = agentsData.agents; - if(typeof(success) === 'function') { + if (typeof (success) === 'function') { success(queueData); } }); @@ -721,20 +751,20 @@ define(function(require){ generateError: false, data: data }, - success: function (data) { - if(typeof(success) === 'function' && data.data) { + success: function(data) { + if (typeof (success) === 'function' && data.data) { success(data.data); } }, error: function(data) { - if(typeof(error) === 'function') { + if (typeof (error) === 'function') { error(data); } } }); }, - queueCreate: function(data, success, error){ + queueCreate: function(data, success, error) { var self = this; monster.request({ @@ -744,13 +774,13 @@ define(function(require){ generateError: false, data: data }, - success: function (_data) { - if(typeof(success) === 'function') { + success: function(_data) { + if (typeof (success) === 'function') { success(_data.data); } }, error: function(_data) { - if(typeof(error) === 'function') { + if (typeof (error) === 'function') { error(_data); } } diff --git a/src/apps/callflows/views/callcenter-queue-callflow.html b/src/apps/callflows/submodules/callcenter/views/queue-callflow.html similarity index 100% rename from src/apps/callflows/views/callcenter-queue-callflow.html rename to src/apps/callflows/submodules/callcenter/views/queue-callflow.html diff --git a/src/apps/callflows/views/callcenter-queue-edit.html b/src/apps/callflows/submodules/callcenter/views/queue-edit.html similarity index 100% rename from src/apps/callflows/views/callcenter-queue-edit.html rename to src/apps/callflows/submodules/callcenter/views/queue-edit.html diff --git a/src/apps/callflows/views/callcenter-queue.html b/src/apps/callflows/submodules/callcenter/views/queue.html similarity index 100% rename from src/apps/callflows/views/callcenter-queue.html rename to src/apps/callflows/submodules/callcenter/views/queue.html diff --git a/src/apps/callflows/views/callcenter-user-row.html b/src/apps/callflows/submodules/callcenter/views/user-row.html similarity index 100% rename from src/apps/callflows/views/callcenter-user-row.html rename to src/apps/callflows/submodules/callcenter/views/user-row.html diff --git a/src/apps/callflows/submodules/conference/conference.js b/src/apps/callflows/submodules/conference/conference.js index bafd935..7653c5a 100644 --- a/src/apps/callflows/submodules/conference/conference.js +++ b/src/apps/callflows/submodules/conference/conference.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -38,7 +38,7 @@ define(function(require){ var id = node.getMetadata('id'), returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } @@ -46,18 +46,22 @@ define(function(require){ }, edit: function(node, callback) { self.conferenceList(function(data, status) { - var popup_html = $(monster.template(self, 'conference-callflowEdit', { - items: _.sortBy(data, 'name'), - selected: node.getMetadata('id') || '' + var popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { + items: _.sortBy(data, 'name'), + selected: node.getMetadata('id') || '' + }, + submodule: 'conference' })), popup; - if($('#conference_selector option:selected', popup_html).val() == undefined) { + if ($('#conference_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? { id: $('#conference_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#conference_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -82,7 +86,7 @@ define(function(require){ title: self.i18n.active().callflows.conference.conference, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -94,7 +98,7 @@ define(function(require){ resource: 'conference.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { paginate: false } }, success: function(data, status) { callback && callback(data.data); @@ -123,7 +127,7 @@ define(function(require){ return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -140,14 +144,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -180,7 +184,7 @@ define(function(require){ save_error: _callbacks.save_error, delete_success: _callbacks.delete_success || function() { - target.empty(), + target.empty(); self.conferenceRenderList(parent); }, @@ -201,66 +205,69 @@ define(function(require){ }; monster.parallel({ - user_list: function(callback) { - self.callApi({ - resource: 'user.list', - data: { - accountId: self.accountId, - filters: { paginate:false } - }, - success: function(_data, status) { - _data.data.unshift({ - id: '', - first_name: '- No', - last_name: 'owner -' - }); - - defaults.field_data.users = _data.data; - - callback(null, _data); + user_list: function(callback) { + self.callApi({ + resource: 'user.list', + data: { + accountId: self.accountId, + filters: { + paginate: false } - }); - }, - get_conference: function(callback) { - if(typeof data == 'object' && data.id) { - self.conferenceGet(data.id, function(_data, status) { - self.conferenceMigrateData(_data); + }, + success: function(_data, status) { + _data.data.unshift({ + id: '', + first_name: '- No', + last_name: 'owner -' + }); - self.conferenceFormatData(_data); + defaults.field_data.users = _data.data; - callback(null, _data); - }); + callback(null, _data); } - else { - callback(null, {}); - } - } + }); }, - function(err, results) { - var render_data = defaults; + get_conference: function(callback) { + if (typeof data === 'object' && data.id) { + self.conferenceGet(data.id, function(_data, status) { + self.conferenceMigrateData(_data); - if(typeof data === 'object' && data.id) { - render_data = $.extend(true, defaults, { data: results.get_conference }); + self.conferenceFormatData(_data); + + callback(null, _data); + }); + } else { + callback(null, {}); } + } + }, function(err, results) { + var render_data = defaults; - self.conferenceRender(render_data, target, callbacks); + if (typeof data === 'object' && data.id) { + render_data = $.extend(true, defaults, { data: results.get_conference }); + } - if(typeof callbacks.after_render == 'function') { - callbacks.after_render(); - } + self.conferenceRender(render_data, target, callbacks); + + if (typeof callbacks.after_render === 'function') { + callbacks.after_render(); } - ); + }); }, - conferenceRender: function(data, target, callbacks){ + conferenceRender: function(data, target, callbacks) { var self = this, - conference_html = $(monster.template(self, 'conference-edit', data)), + conference_html = $(self.getTemplate({ + name: 'edit', + data: data, + submodule: 'conference' + })), conference_form = conference_html.find('#conference_form'); monster.ui.validate(conference_form, { rules: { name: { - required: true, + required: true }, 'member.pins_string': { regex: /^[a-z0-9A-Z,\s]*$/ @@ -285,7 +292,7 @@ define(function(require){ self.winkstartTabs(conference_html); - if(!$('#owner_id', conference_html).val()) { + if (!$('#owner_id', conference_html).val()) { $('#edit_link', conference_html).hide(); } @@ -294,7 +301,7 @@ define(function(require){ }); $('.inline_action', conference_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? { id: $('#owner_id', conference_html).val() } : {}, + var _data = ($(this).data('action') === 'edit') ? { id: $('#owner_id', conference_html).val() } : {}, _id = _data.id; ev.preventDefault(); @@ -303,19 +310,17 @@ define(function(require){ data: _data, callback: function(_data) { /* Create */ - if(!_id) { - $('#owner_id', conference_html).append(''); + if (!_id) { + $('#owner_id', conference_html).append(''); $('#owner_id', conference_html).val(_data.id); $('#edit_link', conference_html).show(); - } - else { + } else { /* Update */ - if('id' in _data) { - $('#owner_id #'+_data.id, conference_html).text(_data.first_name + ' ' + _data.last_name); - } + if ('id' in _data) { + $('#owner_id #' + _data.id, conference_html).text(_data.first_name + ' ' + _data.last_name); /* Delete */ - else { - $('#owner_id #'+_id, conference_html).remove(); + } else { + $('#owner_id #' + _id, conference_html).remove(); $('#edit_link', conference_html).hide(); } } @@ -327,7 +332,7 @@ define(function(require){ ev.preventDefault(); var $this = $(this); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { $this.addClass('disabled'); if (monster.ui.valid(conference_form)) { var form_data = monster.ui.getFormData('conference_form'); @@ -336,7 +341,7 @@ define(function(require){ data.data.member.pins = form_data.member.pins; - if('field_data' in data) { + if ('field_data' in data) { delete data.field_data; } @@ -344,8 +349,7 @@ define(function(require){ $this.removeClass('disabled'); callbacks && callbacks.hasOwnProperty('save_error') && callbacks.save_error(data); }); - } - else { + } else { $this.removeClass('disabled'); monster.ui.alert(self.i18n.active().callflows.conference.there_were_errors_on_the_form); }; @@ -370,23 +374,23 @@ define(function(require){ self.conferenceList(function(data, status) { var map_crossbar_data = function(data) { - var new_list = []; + var new_list = []; - if(data.length > 0) { - $.each(data, function(key, val) { - new_list.push({ - id: val.id, - title: val.name || self.i18n.active().callflows.conference.name - }); + if (data.length > 0) { + $.each(data, function(key, val) { + new_list.push({ + id: val.id, + title: val.name || self.i18n.active().callflows.conference.name }); - } - - new_list.sort(function(a, b) { - return a.title.toLowerCase() < b.title.toLowerCase() ? -1 : 1; }); + } - return new_list; - }; + new_list.sort(function(a, b) { + return a.title.toLowerCase() < b.title.toLowerCase() ? -1 : 1; + }); + + return new_list; + }; // $('#conference-listpanel', parent) // .empty() @@ -404,24 +408,24 @@ define(function(require){ }, conferenceMigrateData: function(data) { - if(data.member_play_name) { - if(data.play_name_on_join == undefined) { + if (data.member_play_name) { + if (data.play_name_on_join === undefined) { data.play_name_on_join = data.member_play_name; } delete data.member_play_name; } - if(data.member_join_muted) { - if(data.member.join_muted == undefined) { + if (data.member_join_muted) { + if (data.member.join_muted === undefined) { data.member.join_muted = data.member_join_muted; } delete data.member_join_muted; } - if(data.member_join_deaf) { - if(data.member.join_deaf == undefined) { + if (data.member_join_deaf) { + if (data.member.join_deaf === undefined) { data.member.join_deaf = data.member_join_deaf; } @@ -432,12 +436,12 @@ define(function(require){ }, conferenceFormatData: function(data) { - if(typeof data.member == 'object') { - if($.isArray(data.member.pins)) { + if (typeof data.member === 'object') { + if ($.isArray(data.member.pins)) { data.member.pins_string = data.member.pins.join(', '); } - if($.isArray(data.conference_numbers)) { + if ($.isArray(data.conference_numbers)) { data.conference_numbers_string = data.conference_numbers.join(', '); } } @@ -445,17 +449,16 @@ define(function(require){ return data; }, - conferenceCleanFormData: function(form_data){ + conferenceCleanFormData: function(form_data) { var self = this; form_data.member.pins_string = self.conferenceLettersToNumbers(form_data.member.pins_string); form_data.member.pins = $.map(form_data.member.pins_string.split(','), function(val) { var pin = $.trim(val); - if(pin != '') { + if (pin !== '') { return pin; - } - else { + } else { return null; } }); @@ -463,10 +466,9 @@ define(function(require){ form_data.conference_numbers = $.map(form_data.conference_numbers_string.split(','), function(val) { var number = $.trim(val); - if(number != '') { + if (number !== '') { return number; - } - else { + } else { return null; } }); @@ -478,31 +480,23 @@ define(function(require){ var result = ''; $.each(string.split(''), function(index, value) { - if(value.match(/^[aAbBcC]$/)) { + if (value.match(/^[aAbBcC]$/)) { result += '2'; - } - else if(value.match(/^[dDeEfF]$/)) { + } else if (value.match(/^[dDeEfF]$/)) { result += '3'; - } - else if(value.match(/^[gGhHiI]$/)) { + } else if (value.match(/^[gGhHiI]$/)) { result += '4'; - } - else if(value.match(/^[jJkKlL]$/)) { + } else if (value.match(/^[jJkKlL]$/)) { result += '5'; - } - else if(value.match(/^[mMnNoO]$/)) { + } else if (value.match(/^[mMnNoO]$/)) { result += '6'; - } - else if(value.match(/^[pPqQrRsS]$/)) { + } else if (value.match(/^[pPqQrRsS]$/)) { result += '7'; - } - else if(value.match(/^[tTuUvV]$/)) { + } else if (value.match(/^[tTuUvV]$/)) { result += '8'; - } - else if(value.match(/^[wWxXyYzZ]$/)) { + } else if (value.match(/^[wWxXyYzZ]$/)) { result += '9'; - } - else { + } else { result += value; } }); @@ -514,31 +508,26 @@ define(function(require){ var self = this, normalized_data = self.conferenceFixArrays(self.conferenceNormalizeData($.extend(true, {}, data.data, form_data)), form_data); - if(typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { self.conferenceUpdate(normalized_data, function(_data, status) { - if(typeof success == 'function') { - success(_data, status, 'update'); - } - }, - function(_data, status) { - if(typeof error == 'function') { - error(_data, status, 'update'); - } + if (typeof success === 'function') { + success(_data, status, 'update'); } - ); - } - else { + }, function(_data, status) { + if (typeof error === 'function') { + error(_data, status, 'update'); + } + }); + } else { self.conferenceCreate(normalized_data, function(_data, status) { - if(typeof success == 'function') { - success(_data, status, 'create'); - } - }, - function(_data, status) { - if(typeof error == 'function') { - error(_data, status, 'create'); - } + if (typeof success === 'function') { + success(_data, status, 'create'); + } + }, function(_data, status) { + if (typeof error === 'function') { + error(_data, status, 'create'); } - ); + }); } }, @@ -546,7 +535,7 @@ define(function(require){ conferenceFixArrays: function(merged_data, form_data) { var self = this; - if('conference_numbers' in form_data) { + if ('conference_numbers' in form_data) { merged_data.conference_numbers = form_data.conference_numbers; } @@ -554,15 +543,15 @@ define(function(require){ }, conferenceNormalizeData: function(data) { - if(!data.member.pins.length) { + if (!data.member.pins.length) { delete data.member.pins; } - if(data.hasOwnProperty('member') && data.member.hasOwnProperty('numbers') && !data.member.numbers.length) { + if (data.hasOwnProperty('member') && data.member.hasOwnProperty('numbers') && !data.member.numbers.length) { delete data.member.numbers; } - if(!data.owner_id) { + if (!data.owner_id) { delete data.owner_id; } @@ -572,7 +561,6 @@ define(function(require){ return data; }, - conferenceList: function(callback) { var self = this; @@ -580,7 +568,9 @@ define(function(require){ resource: 'conference.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); diff --git a/src/apps/callflows/views/conference-callflowEdit.html b/src/apps/callflows/submodules/conference/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/conference-callflowEdit.html rename to src/apps/callflows/submodules/conference/views/callflowEdit.html diff --git a/src/apps/callflows/views/conference-edit.html b/src/apps/callflows/submodules/conference/views/edit.html similarity index 100% rename from src/apps/callflows/views/conference-edit.html rename to src/apps/callflows/submodules/conference/views/edit.html diff --git a/src/apps/callflows/submodules/device/device.js b/src/apps/callflows/submodules/device/device.js index 4ce5f6f..717b0fc 100644 --- a/src/apps/callflows/submodules/device/device.js +++ b/src/apps/callflows/submodules/device/device.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -35,14 +35,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -68,7 +68,7 @@ define(function(require){ callbacks = { save_success: _callbacks.save_success, save_error: _callbacks.save_error || function(_data, status, type) { - if(status == 200 && type == 'mac_address') { + if (status === 200 && type === 'mac_address') { monster.ui.alert(self.i18n.active().callflows.device.this_mac_address_is_already_in_use); } }, @@ -89,7 +89,6 @@ define(function(require){ call_restriction: { closed_groups: 'inherit' }, media: { secure_rtp: 'none', - peer_to_peer: 'auto', audio: { codecs: ['PCMU', 'PCMA'] }, @@ -141,11 +140,6 @@ define(function(require){ 'zrtp': self.i18n.active().callflows.device.zrtp } }, - peer_to_peer_options: { - 'auto': self.i18n.active().callflows.device.automatic, - 'true': self.i18n.active().callflows.device.always, - 'false': self.i18n.active().callflows.device.never - }, fax: { options: { 'auto': self.i18n.active().callflows.device.auto_detect, @@ -164,8 +158,8 @@ define(function(require){ 'speex@16000h': 'Speex @ 16khz', 'PCMU': 'G711u / PCMU - 64kbps (North America)', 'PCMA': 'G711a / PCMA - 64kbps (Elsewhere)', - 'G729':'G729 - 8kbps (Requires License)', - 'GSM':'GSM', + 'G729': 'G729 - 8kbps (Requires License)', + 'GSM': 'GSM', 'CELT@48000h': 'Siren (HD) @ 48kHz', 'CELT@64000h': 'Siren (HD) @ 64kHz' } @@ -180,28 +174,31 @@ define(function(require){ } }, hide_owner: data.hide_owner || false, - outbound_flags: data.outbound_flags ? data.outbound_flags.join(", ") : data.outbound_flags + outbound_flags: data.outbound_flags ? data.outbound_flags.join(', ') : data.outbound_flags }, functions: { inArray: function(value, array) { - if(array) { - return ($.inArray(value, array) == -1) ? false : true; + if (array) { + return ($.inArray(value, array) === -1) ? false : true; + } else { + return false; } - else return false; } } }, - parallelRequests = function (deviceData) { + parallelRequests = function(deviceData) { monster.parallel({ - list_classifier: function(callback){ + list_classifier: function(callback) { self.callApi({ resource: 'numbers.listClassifiers', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(_data_classifiers) { - if('data' in _data_classifiers) { + if ('data' in _data_classifiers) { $.each(_data_classifiers.data, function(k, v) { defaults.field_data.call_restriction[k] = { friendly_name: v.friendly_name @@ -214,7 +211,7 @@ define(function(require){ } }); }, - account: function(callback){ + account: function(callback) { self.callApi({ resource: 'account.get', data: { @@ -222,7 +219,7 @@ define(function(require){ }, success: function(_data, status) { $.extend(defaults.field_data.sip, { - realm: _data.data.realm, + realm: _data.data.realm }); callback(null, _data); @@ -234,7 +231,9 @@ define(function(require){ resource: 'user.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(_data, status) { _data.data.sort(function(a, b) { @@ -244,23 +243,21 @@ define(function(require){ _data.data.unshift({ id: '', first_name: '- No', - last_name: 'owner -', + last_name: 'owner -' }); if (deviceData.hasOwnProperty('device_type') && deviceData.device_type === 'mobile') { - var userData = _.find(_data.data, function(user, idx) { return user.id === deviceData.owner_id; }); + var userData = _.find(_data.data, function(user) { return user.id === deviceData.owner_id; }); if (userData) { defaults.field_data.users = userData; - } - else { + } else { defaults.field_data.users = { first_name: '- No', last_name: 'owner -' }; } - } - else { + } else { defaults.field_data.users = _data.data; } @@ -273,7 +270,9 @@ define(function(require){ resource: 'media.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(_data, status) { _data.data.unshift( @@ -298,38 +297,37 @@ define(function(require){ }); }, provisionerData: function(callback) { - if(monster.config.api.hasOwnProperty('provisioner') && monster.config.api.provisioner) { + if (monster.config.api.hasOwnProperty('provisioner') && monster.config.api.provisioner) { self.deviceGetDataProvisoner(function(data) { callback(null, data); }); - } - else { + } else { callback(null, {}); } } }, - function(err, results){ + function(err, results) { var render_data = self.devicePrepareDataForTemplate(data, defaults, $.extend(true, results, { - get_device: deviceData - })); + get_device: deviceData + })); self.deviceRender(render_data, target, callbacks); - if(typeof callbacks.after_render == 'function') { + if (typeof callbacks.after_render === 'function') { callbacks.after_render(); } }); }; - if(typeof data == 'object' && data.id) { + if (typeof data === 'object' && data.id) { self.deviceGet(data.id, function(_data, status) { defaults.data.device_type = 'sip_device'; - if('media' in _data && 'encryption' in _data.media) { + if ('media' in _data && 'encryption' in _data.media) { defaults.field_data.media.secure_rtp.value = _data.media.encryption.enforce_security ? _data.media.encryption.methods[0] : 'none'; } - if('sip' in _data && 'realm' in _data.sip) { + if ('sip' in _data && 'realm' in _data.sip) { defaults.field_data.sip.realm = _data.sip.realm; } @@ -337,8 +335,7 @@ define(function(require){ parallelRequests(_data); }); - } - else { + } else { parallelRequests(defaults); } }, @@ -348,18 +345,18 @@ define(function(require){ dataDevice = results.get_device, dataProvisioner = results.provisionerData; - if(typeof data === 'object' && data.id) { + if (typeof data === 'object' && data.id) { dataGlobal = $.extend(true, dataGlobal, { data: dataDevice }); } - if(dataDevice.hasOwnProperty('media') && dataDevice.media.hasOwnProperty('audio')) { + if (dataDevice.hasOwnProperty('media') && dataDevice.media.hasOwnProperty('audio')) { // If the codecs property is defined, override the defaults with it. Indeed, when an empty array is set as the // list of codecs, it gets overwritten by the extend function otherwise. - if(dataDevice.media.audio.hasOwnProperty('codecs')) { + if (dataDevice.media.audio.hasOwnProperty('codecs')) { dataGlobal.data.media.audio.codecs = dataDevice.media.audio.codecs; } - if(dataDevice.media.video.hasOwnProperty('codecs')) { + if (dataDevice.media.video.hasOwnProperty('codecs')) { dataGlobal.data.media.video.codecs = dataDevice.media.video.codecs; } } @@ -371,7 +368,7 @@ define(function(require){ dataGlobal.field_data.provisioner = dataProvisioner; dataGlobal.field_data.provisioner.isEnabled = !_.isEmpty(dataProvisioner); - if(dataGlobal.field_data.provisioner.isEnabled) { + if (dataGlobal.field_data.provisioner.isEnabled) { var default_provision_data = { voicemail_beep: 1, //ie enabled time_format: '12', @@ -381,7 +378,7 @@ define(function(require){ number: '' }, date_format: 'middle-endian' - } + }; dataGlobal.data.provision = $.extend(true, {}, default_provision_data, dataGlobal.data.provision); } @@ -405,74 +402,178 @@ define(function(require){ }, deviceGetValidationByDeviceType: function(deviceType) { - var validation = { - sip_uri: {}, - sip_device : { - 'mac_address': { mac: true }, - 'sip_expire_seconds': { digits: true }, - 'extra.shoutcastUrl': { protocol: true } - }, - fax : { - 'mac_address': { mac: true }, - 'sip_expire_seconds': { digits: true } - }, - cellphone: {}, - smartphone: { - 'sip_expire_seconds': { digits: true } - }, - landline: {}, - softphone: { - 'sip_expire_seconds': { digits: true }, - 'extra.shoutcastUrl': { protocol: true } + var self = this, + i18n = self.i18n.active(), + validation = { + ata: { + 'sip.ip': { + required: true, + ipv4: true + } + }, + sip_uri: {}, + sip_device: { + 'mac_address': { mac: true }, + 'sip_expire_seconds': { digits: true }, + 'sip.ip': { + ipv4: true, + required: true + }, + 'extra.shoutcastUrl': { protocol: true } + }, + fax: { + 'mac_address': { mac: true }, + 'sip_expire_seconds': { digits: true }, + 'sip.ip': { + ipv4: true, + required: true + } + }, + cellphone: {}, + smartphone: { + 'sip_expire_seconds': { digits: true }, + 'sip.ip': { + ipv4: true, + required: true + } + }, + landline: {}, + softphone: { + 'sip_expire_seconds': { digits: true }, + 'extra.shoutcastUrl': { protocol: true } + }, + mobile: { + 'mdn': { digits: true }, + 'sip_expire_seconds': { digits: true }, + 'extra.shoutcastUrl': { protocol: true } + } }, - mobile: { - 'mdn': { digits: true }, - 'sip_expire_seconds': { digits: true }, - 'extra.shoutcastUrl': { protocol: true } - } - }; + deviceTypeValidation = { + rules: validation[deviceType] + }; + + if (_.includes(['ata', 'fax', 'mobile', 'sip_device', 'softphone'], deviceType)) { + _.merge(deviceTypeValidation, { + rules: { + 'caller_id.asserted.name': { regex: /^[0-9A-Za-z ,]{0,30}$/ }, + 'caller_id.asserted.number': { phoneNumber: true }, + 'caller_id.asserted.realm': { realm: true } + }, + messages: { + 'caller_id.asserted.name': { regex: i18n.callflows.device.validation.caller_id.name }, + 'caller_id.asserted.number': { regex: i18n.callflows.device.validation.caller_id.number }, + 'caller_id.asserted.realm': { regex: i18n.callflows.device.validation.caller_id.realm } + } + }); + } - return { rules: validation[deviceType] }; + return deviceTypeValidation; }, - deviceRender: function(data, target, callbacks){ + deviceRender: function(data, target, callbacks) { var self = this, - device_html, - render; + device_html; - if('media' in data.data && 'fax_option' in data.data.media) { + if ('media' in data.data && 'fax_option' in data.data.media) { data.data.media.fax_option = (data.data.media.fax_option === 'auto' || data.data.media.fax_option === true); } - if(typeof data.data == 'object' && data.data.device_type) { - device_html = $(monster.template(self, 'device-' + data.data.device_type, data)); + if (typeof data.data === 'object' && data.data.device_type) { + device_html = $(self.getTemplate({ + name: 'device-' + data.data.device_type, + data: _.merge({ + showPAssertedIdentity: monster.config.whitelabel.showPAssertedIdentity + }, data), + submodule: 'device' + })); var deviceForm = device_html.find('#device-form'); - if(monster.config.api.hasOwnProperty('provisioner') && monster.config.api.provisioner) { + if (monster.config.api.hasOwnProperty('provisioner') && monster.config.api.provisioner) { self.deviceSetProvisionerStuff(device_html, data); } /* Do device type specific things here */ - if($.inArray(data.data.device_type, ['fax', 'softphone', 'sip_device', 'smartphone', 'mobile', 'ata']) > -1) { + if ($.inArray(data.data.device_type, ['fax', 'softphone', 'sip_device', 'smartphone', 'mobile', 'ata']) > -1) { monster.ui.protectField(device_html.find('#sip_password'), device_html); } monster.ui.validate(deviceForm, self.deviceGetValidationByDeviceType(data.data.device_type)); - if(!$('#owner_id', device_html).val()) { + if (!$('#owner_id', device_html).val()) { $('#edit_link', device_html).hide(); } + device_html.find('input[data-mask]').each(function() { + var $this = $(this); + monster.ui.mask($this, $this.data('mask')); + }); + + if (!$('#music_on_hold_media_id', device_html).val()) { + $('#edit_link_media', device_html).hide(); + } + + if (data.data.sip && data.data.sip.method === 'ip') { + $('#username_block', device_html).hide(); + } else { + $('#ip_block', device_html).hide(); + } + } else { + device_html = $(self.getTemplate({ + name: 'general_edit', + submodule: 'device' + })); + + $('.media_pane', device_html).hide(); + } + + $('*[rel=popover]:not([type="text"])', device_html).popover({ + trigger: 'hover' + }); + + $('*[rel=popover][type="text"]', device_html).popover({ + trigger: 'focus' + }); - monster.ui.mask(device_html.find('#mac_address'), 'macAddress'); + self.winkstartTabs(device_html); + + self.deviceBindEvents({ + data: data, + template: device_html, + callbacks: callbacks + }); + + (target) + .empty() + .append(device_html); + + $('.media_tabs .buttons[device_type="sip_device"]', device_html).trigger('click'); + }, + + /** + * Bind events for the device edit template + * @param {Object} args + * @param {Object} args.data + * @param {Object} args.template + * @param {Object} args.callbacks + * @param {Function} args.callbacks.save_success + * @param {Function} args.callbacks.delete_success + */ + deviceBindEvents: function(args) { + var self = this, + data = args.data, + callbacks = args.callbacks, + device_html = args.template; + + if (typeof data.data === 'object' && data.data.device_type) { + var deviceForm = device_html.find('#device-form'); $('#owner_id', device_html).change(function() { !$('#owner_id option:selected', device_html).val() ? $('#edit_link', device_html).hide() : $('#edit_link', device_html).show(); }); $('.inline_action', device_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? { id: $('#owner_id', device_html).val() } : {}, + var _data = ($(this).data('action') === 'edit') ? { id: $('#owner_id', device_html).val() } : {}, _id = _data.id; ev.preventDefault(); @@ -481,19 +582,17 @@ define(function(require){ data: _data, callback: function(user) { /* Create */ - if(!_id) { - $('#owner_id', device_html).append(''); + if (!_id) { + $('#owner_id', device_html).append(''); $('#owner_id', device_html).val(user.id); $('#edit_link', device_html).show(); - } - else { + } else { /* Update */ - if(_data.hasOwnProperty('id')) { - $('#owner_id #'+user.id, device_html).text(user.first_name + ' ' + user.last_name); - } + if (_data.hasOwnProperty('id')) { + $('#owner_id #' + user.id, device_html).text(user.first_name + ' ' + user.last_name); /* Delete */ - else { - $('#owner_id #'+_id, device_html).remove(); + } else { + $('#owner_id #' + _id, device_html).remove(); $('#edit_link', device_html).hide(); } } @@ -506,9 +605,9 @@ define(function(require){ var $this = $(this); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { $this.addClass('disabled'); - if(monster.ui.valid(deviceForm)) { + if (monster.ui.valid(deviceForm)) { var form_data = monster.ui.getFormData('device-form'); if (form_data.hasOwnProperty('music_on_hold') && form_data.music_on_hold.media_id === 'shoutcast') { @@ -517,15 +616,18 @@ define(function(require){ self.deviceCleanFormData(form_data); - if(form_data.hasOwnProperty('provision') && form_data.provision.hasOwnProperty('endpoint_brand') && form_data.provision.endpoint_brand !== 'none') { + if (form_data.hasOwnProperty('provision') && form_data.provision.hasOwnProperty('endpoint_brand') && form_data.provision.endpoint_brand !== 'none') { + var modelArray = $('.dropdown_family[data-brand="' + form_data.provision.endpoint_brand + '"]', device_html).val().split('.'), + endpoint_family = modelArray[0], + endpoint_model = modelArray[1]; + // We have to set this manually since we have 3 dropdown with the same name we don't know which selected one is the correct one.. - form_data.provision.endpoint_model = $('.dropdown_family[data-brand="'+form_data.provision.endpoint_brand+'"]', device_html).val(); - form_data.provision.endpoint_family = $('#'+form_data.provision.endpoint_model, device_html).parents('optgroup').data('family'); + form_data.provision.endpoint_model = endpoint_model; + form_data.provision.endpoint_family = endpoint_family; } self.deviceSave(form_data, data, callbacks.save_success); - } - else { + } else { $this.removeClass('disabled'); monster.ui.alert('error', self.i18n.active().callflows.device.there_were_errors_on_the_form); } @@ -542,23 +644,11 @@ define(function(require){ }); } - if(!$('#music_on_hold_media_id', device_html).val()) { - $('#edit_link_media', device_html).hide(); - } - - if(data.data.sip && data.data.sip.method === 'ip') { - $('#username_block', device_html).hide(); - } - else { - $('#ip_block', device_html).hide(); - } - device_html.find('#sip_method').on('change', function() { - if($('#sip_method option:selected', device_html).val() === 'ip') { + if ($('#sip_method option:selected', device_html).val() === 'ip') { $('#ip_block', device_html).slideDown(); $('#username_block', device_html).slideUp(); - } - else { + } else { $('#username_block', device_html).slideDown(); $('#ip_block', device_html).slideUp(); } @@ -571,7 +661,7 @@ define(function(require){ }); $('.inline_action_media', device_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? { id: $('#music_on_hold_media_id', device_html).val() } : {}, + var _data = ($(this).data('action') === 'edit') ? { id: $('#music_on_hold_media_id', device_html).val() } : {}, _id = _data.id; ev.preventDefault(); @@ -580,36 +670,30 @@ define(function(require){ data: _data, callback: function(media) { /* Create */ - if(!_id) { - $('#music_on_hold_media_id', device_html).append(''); + if (!_id) { + $('#music_on_hold_media_id', device_html).append(''); $('#music_on_hold_media_id', device_html).val(media.id); $('#edit_link_media', device_html).show(); - } - else { + } else { /* Update */ - if(media.hasOwnProperty('id')) { - $('#music_on_hold_media_id #'+ media.id, device_html).text(media.name); - } + if (media.hasOwnProperty('id')) { + $('#music_on_hold_media_id #' + media.id, device_html).text(media.name); /* Delete */ - else { - $('#music_on_hold_media_id #'+_id, device_html).remove(); + } else { + $('#music_on_hold_media_id #' + _id, device_html).remove(); $('#edit_link_media', device_html).hide(); } } } }); }); - } - else { - device_html = $(monster.template(self, 'device-general_edit')); - - $('.media_pane', device_html).hide(); + } else { $('.media_tabs .buttons', device_html).click(function() { var $this = $(this); $('.media_pane', device_html).show(); - if(!$this.hasClass('current')) { + if (!$this.hasClass('current')) { $('.media_tabs .buttons').removeClass('current'); $this.addClass('current'); @@ -621,86 +705,72 @@ define(function(require){ } }); } - - $('*[rel=popover]:not([type="text"])', device_html).popover({ - trigger: 'hover' - }); - - $('*[rel=popover][type="text"]', device_html).popover({ - trigger: 'focus' - }); - - self.winkstartTabs(device_html); - - (target) - .empty() - .append(device_html); - - $('.media_tabs .buttons[device_type="sip_device"]', device_html).trigger('click'); }, deviceSetProvisionerStuff: function(device_html, data) { var self = this, - set_value = function(brand_name, model_name) { + set_value = function(brand_name, model_family, model_name) { device_html.find('.dropdown_family').hide(); - if(brand_name in data.field_data.provisioner.brands) { + if (brand_name in data.field_data.provisioner.brands) { device_html.find('#dropdown_brand').val(brand_name); - device_html.find('.dropdown_family[data-brand="'+brand_name+'"]').show() - .val(model_name); + device_html + .find('.dropdown_family[data-brand="' + brand_name + '"]') + .show() + .val(model_family + '.' + model_name); } }, provisionData = data.data.provision, regex_brands = { - "00085d": "aastra", - "0010bc": "aastra", - "00036b": "cisco", - "00000c": "cisco", - "000142": "cisco", - "000143": "cisco", - "000163": "cisco", - "000164": "cisco", - "000196": "cisco", - "000197": "cisco", - "0001c7": "cisco", - "0001c9": "cisco", - "000f23": "cisco", - "0013c4": "cisco", - "0016c8": "cisco", - "001818": "cisco", - "00175a": "cisco", - "001795": "cisco", - "001A2f": "cisco", - "001c58": "cisco", - "001dA2": "cisco", - "002155": "cisco", - "000e84": "cisco", - "000e38": "cisco", - "00070e": "cisco", - "001bd4": "cisco", - "001930": "cisco", - "0019aa": "cisco", - "001d45": "cisco", - "001ef7": "cisco", - "000e08": "cisco", - "1cdf0f": "cisco", - "e05fb9": "cisco", - "5475d0": "cisco", - "c46413": "cisco", - "000Ffd3": "digium", - "000b82": "grandstream", - "08000f": "mitel", - "1045bE": "norphonic", - "0050c2": "norphonic", - "0004f2": "polycom", - "00907a": "polycom", - "000413": "snom", - "001f9f": "thomson", - "00147f": "thomson", - "642400": "xorcom", - "001565": "yealink" + '00085d': 'aastra', + '0010bc': 'aastra', + '00036b': 'cisco', + '00000c': 'cisco', + '000142': 'cisco', + '000143': 'cisco', + '000163': 'cisco', + '000164': 'cisco', + '000196': 'cisco', + '000197': 'cisco', + '0001c7': 'cisco', + '0001c9': 'cisco', + '000f23': 'cisco', + '0013c4': 'cisco', + '0016c8': 'cisco', + '001818': 'cisco', + '00175a': 'cisco', + '001795': 'cisco', + '001A2f': 'cisco', + '001c58': 'cisco', + '001dA2': 'cisco', + '002155': 'cisco', + '000e84': 'cisco', + '000e38': 'cisco', + '00070e': 'cisco', + '001bd4': 'cisco', + '001930': 'cisco', + '0019aa': 'cisco', + '001d45': 'cisco', + '001ef7': 'cisco', + '000e08': 'cisco', + '1cdf0f': 'cisco', + 'e05fb9': 'cisco', + '5475d0': 'cisco', + 'c46413': 'cisco', + '000Ffd3': 'digium', + '000b82': 'grandstream', + '08000f': 'mitel', + '1045bE': 'norphonic', + '0050c2': 'norphonic', + '0004f2': 'polycom', + '00907a': 'polycom', + '000413': 'snom', + '001f9f': 'thomson', + '00147f': 'thomson', + '642400': 'xorcom', + '001565': 'yealink' }; - set_value(provisionData.endpoint_brand, provisionData.endpoint_model); + set_value(provisionData.endpoint_brand, provisionData.endpoint_family, provisionData.endpoint_model); device_html.find('#dropdown_brand').on('change', function() { set_value($(this).val()); @@ -709,43 +779,41 @@ define(function(require){ device_html.find('#mac_address').on('keyup', function() { var mac_address = $(this).val().replace(/[^0-9a-fA-F]/g, ''); - if(mac_address in regex_brands) { + if (mac_address in regex_brands) { set_value(regex_brands[mac_address]); } }); }, deviceFormatData: function(data) { - if(data.data.device_type === 'smartphone' || data.data.device_type === 'landline' || data.data.device_type === 'cellphone') { + if (data.data.device_type === 'smartphone' || data.data.device_type === 'landline' || data.data.device_type === 'cellphone') { data.data.call_forward = { enabled: true, require_keypress: true, keep_caller_id: true }; - } - else { + } else { data.data.call_forward = { enabled: false }; } - if(data.data.device_type === 'sip_uri') { + if (data.data.device_type === 'sip_uri') { data.data.sip.invite_format = 'route'; } - if(data.data.device_type === 'mobile') { - if(!('mobile' in data.data)) { + if (data.data.device_type === 'mobile') { + if (!('mobile' in data.data)) { data.data.mobile = { mdn: '' }; } } - if(data.data.device_type === 'fax') { + if (data.data.device_type === 'fax') { data.data.media.fax_option = true; data.data.media.fax.option = 'true'; - } - else { + } else { data.data.media.fax_option = false; data.data.media.fax.option = 'false'; } @@ -754,7 +822,7 @@ define(function(require){ deviceMigrateData: function(data) { var self = this; - if(data.hasOwnProperty('media') && data.media.hasOwnProperty('audio') && data.media.audio.hasOwnProperty('codecs')) { + if (data.hasOwnProperty('media') && data.media.hasOwnProperty('audio') && data.media.audio.hasOwnProperty('codecs')) { var mapMigrateCodec = { 'Speex': 'speex@16000h', 'G722_16': 'G7221@16000h', @@ -771,20 +839,20 @@ define(function(require){ data.media.audio.codecs = newCodecList; } - if(data.device_type == 'cell_phone') { + if (data.device_type === 'cell_phone') { data.device_type = 'cellphone'; } - if(typeof data.media == 'object' && typeof data.media.fax == 'object' && 'codecs' in data.media.fax) { + if (typeof data.media === 'object' && typeof data.media.fax === 'object' && 'codecs' in data.media.fax) { delete data.media.fax.codecs; } - if('status' in data) { + if ('status' in data) { data.enabled = data.status; delete data.status; } - if(data.hasOwnProperty('ignore_complete_elsewhere')) { + if (data.hasOwnProperty('ignore_complete_elsewhere')) { data.ignore_completed_elsewhere = data.ignore_complete_elsewhere; delete data.ignore_complete_elsewhere; @@ -794,90 +862,85 @@ define(function(require){ }, deviceNormalizeData: function(data) { - if(data.hasOwnProperty('provision')) { - if(data.provision.endpoint_brand === 'none') { + var self = this; + + if (data.hasOwnProperty('provision')) { + if (data.provision.endpoint_brand === 'none') { delete data.provision; - } - else { - if(data.provision.voicemail_beep !== 0) { + } else { + if (data.provision.voicemail_beep !== 0) { delete data.provision.voicemail_beep; } } } - if(data.hasOwnProperty('media') && data.media.hasOwnProperty('fax_option') && data.media.fax_option === 'auto') { + if (data.hasOwnProperty('media') && data.media.hasOwnProperty('fax_option') && data.media.fax_option === 'auto') { delete data.media.fax_option; } - if('media' in data && 'fax' in data.media && 'fax_option' in data.media) { + if ('media' in data && 'fax' in data.media && 'fax_option' in data.media) { data.media.fax.option = data.media.fax_option.toString(); } - if('media' in data && 'secure_rtp' in data.media) { + if ('media' in data && 'secure_rtp' in data.media) { delete data.media.secure_rtp; } - if('media' in data && 'bypass_media' in data.media) { + if ('media' in data && 'bypass_media' in data.media) { delete data.media.bypass_media; } - if(data.caller_id.internal.number == '' && data.caller_id.internal.name == '') { - delete data.caller_id.internal; - } - - if(data.caller_id.external.number == '' && data.caller_id.external.name == '') { - delete data.caller_id.external; - } + self.compactObject(data.caller_id); - if(data.caller_id.emergency.number == '' && data.caller_id.emergency.name == '') { - delete data.caller_id.emergency; + if (_.isEmpty(data.caller_id)) { + delete data.caller_id; } - if(!data.music_on_hold.media_id) { + if (!data.music_on_hold.media_id) { delete data.music_on_hold.media_id; } - if(!data.owner_id) { + if (!data.owner_id) { delete data.owner_id; } - if($.isEmptyObject(data.call_forward)) { + if ($.isEmptyObject(data.call_forward)) { delete data.call_forward; } - if(!data.mac_address) { + if (!data.mac_address) { delete data.mac_address; } - if(data.sip.method != 'ip') { + if (data.sip.method !== 'ip') { delete data.sip.ip; } - if(typeof data.outbound_flags == "string") { + if (typeof data.outbound_flags === 'string') { data.outbound_flags = data.outbound_flags.split(/,/); /* Get rid of empty string */ var new_flags = []; $.each(data.outbound_flags, function(k, v) { - if(v.replace(/\s/g, '') !== '') { + if (v.replace(/\s/g, '') !== '') { new_flags.push(v); } }); data.outbound_flags = new_flags; } - if(data.device_type === 'fax') { - if(!('outbound_flags' in data)) { + if (data.device_type === 'fax') { + if (!('outbound_flags' in data)) { data.outbound_flags = ['fax']; - } else if(data.outbound_flags.indexOf('fax') < 0) { - data.outbound_flags.splice(0,0,'fax'); + } else if (data.outbound_flags.indexOf('fax') < 0) { + data.outbound_flags.splice(0, 0, 'fax'); } } - if(data.ringtones && 'internal' in data.ringtones && data.ringtones.internal === '') { + if (data.ringtones && 'internal' in data.ringtones && data.ringtones.internal === '') { delete data.ringtones.internal; } - if(data.ringtones && 'external' in data.ringtones && data.ringtones.external === '') { + if (data.ringtones && 'external' in data.ringtones && data.ringtones.external === '') { delete data.ringtones.external; } @@ -890,7 +953,7 @@ define(function(require){ delete data.call_restriction; } - if(data.hasOwnProperty('presence_id') && data.presence_id === '') { + if (data.hasOwnProperty('presence_id') && data.presence_id === '') { delete data.presence_id; } @@ -898,60 +961,60 @@ define(function(require){ }, deviceCleanFormData: function(form_data) { - if('provision' in form_data && form_data.provision.voicemail_beep === true) { + if ('provision' in form_data && form_data.provision.voicemail_beep === true) { form_data.provision.voicemail_beep = 0; } - if(form_data.mac_address) { + if (form_data.mac_address) { form_data.mac_address = form_data.mac_address.toLowerCase(); - if(form_data.mac_address.match(/^(((\d|([a-f]|[A-F])){2}-){5}(\d|([a-f]|[A-F])){2})$/)) { - form_data.mac_address = form_data.mac_address.replace(/-/g,':'); - } - else if(form_data.mac_address.match(/^(((\d|([a-f]|[A-F])){2}){5}(\d|([a-f]|[A-F])){2})$/)) { - form_data.mac_address = form_data.mac_address.replace(/(.{2})/g,'$1:').slice(0, -1); + if (form_data.mac_address.match(/^(((\d|([a-f]|[A-F])) {2}-) {5}(\d|([a-f]|[A-F])) {2})$/)) { + form_data.mac_address = form_data.mac_address.replace(/-/g, ':'); + } else if (form_data.mac_address.match(/^(((\d|([a-f]|[A-F])) {2}) {5}(\d|([a-f]|[A-F])) {2})$/)) { + form_data.mac_address = form_data.mac_address.replace(/(.{2})/g, '$1:').slice(0, -1); } } - if(form_data.caller_id) { - form_data.caller_id.internal.number = form_data.caller_id.internal.number.replace(/\s|\(|\)|\-|\./g,''); - form_data.caller_id.external.number = form_data.caller_id.external.number.replace(/\s|\(|\)|\-|\./g,''); - form_data.caller_id.emergency.number = form_data.caller_id.emergency.number.replace(/\s|\(|\)|\-|\./g,''); + if (form_data.caller_id) { + form_data.caller_id.internal.number = form_data.caller_id.internal.number.replace(/\s|\(|\)|-|\./g, ''); + form_data.caller_id.external.number = form_data.caller_id.external.number.replace(/\s|\(|\)|-|\./g, ''); + form_data.caller_id.emergency.number = form_data.caller_id.emergency.number.replace(/\s|\(|\)|-|\./g, ''); + form_data.caller_id.asserted.number = _.isEmpty(form_data.caller_id.asserted.number) + ? '' // Need to keep the empty string so the new value is not lost when merging the form data with the original data + : monster.util.getFormatPhoneNumber(form_data.caller_id.asserted.number).e164Number; } - if('media' in form_data && 'audio' in form_data.media) { - form_data.media.audio.codecs = $.map(form_data.media.audio.codecs, function(val) { return (val) ? val : null }); + if ('media' in form_data && 'audio' in form_data.media) { + form_data.media.audio.codecs = $.map(form_data.media.audio.codecs, function(val) { return (val) ? val : null; }); } - if('media' in form_data && 'video' in form_data.media) { - form_data.media.video.codecs = $.map(form_data.media.video.codecs, function(val) { return (val) ? val : null }); + if ('media' in form_data && 'video' in form_data.media) { + form_data.media.video.codecs = $.map(form_data.media.video.codecs, function(val) { return (val) ? val : null; }); } - if(form_data.device_type == 'smartphone' || form_data.device_type == 'landline' || form_data.device_type == 'cellphone') { - form_data.call_forward.number = form_data.call_forward.number.replace(/\s|\(|\)|\-|\./g,''); + if (form_data.device_type === 'smartphone' || form_data.device_type === 'landline' || form_data.device_type === 'cellphone') { + form_data.call_forward.number = form_data.call_forward.number.replace(/\s|\(|\)|-|\./g, ''); form_data.enabled = form_data.call_forward.enabled; } - if('extra' in form_data && form_data.extra.notify_unregister === true) { + if ('extra' in form_data && form_data.extra.notify_unregister === true) { form_data.suppress_unregister_notifications = false; - } - else { + } else { form_data.suppress_unregister_notifications = true; } - if('extra' in form_data && 'closed_groups' in form_data.extra) { + if ('extra' in form_data && 'closed_groups' in form_data.extra) { form_data.call_restriction.closed_groups = { action: form_data.extra.closed_groups ? 'deny' : 'inherit' }; } - if($.inArray(form_data.device_type, ['sip_device', 'mobile', 'softphone']) > -1) { - if('extra' in form_data) { + if ($.inArray(form_data.device_type, ['sip_device', 'mobile', 'softphone']) > -1) { + if ('extra' in form_data) { form_data.media.encryption = form_data.media.encryption || {}; - if($.inArray(form_data.extra.encryptionMethod, ['srtp', 'zrtp']) > -1) { + if ($.inArray(form_data.extra.encryptionMethod, ['srtp', 'zrtp']) > -1) { form_data.media.encryption.enforce_security = true; form_data.media.encryption.methods = [form_data.extra.encryptionMethod]; - } - else { + } else { form_data.media.encryption.methods = []; form_data.media.encryption.enforce_security = false; } @@ -964,12 +1027,12 @@ define(function(require){ }, deviceFixArrays: function(data, data2) { - if(typeof data.media == 'object' && typeof data2.media == 'object') { + if (typeof data.media === 'object' && typeof data2.media === 'object') { (data.media.audio || {}).codecs = (data2.media.audio || {}).codecs; (data.media.video || {}).codecs = (data2.media.video || {}).codecs; } - if('media' in data2 && 'encryption' in data2.media && 'methods' in data2.media.encryption) { + if ('media' in data2 && 'encryption' in data2.media && 'methods' in data2.media.encryption) { data.media.encryption = data.media.encryption || {}; data.media.encryption.methods = data2.media.encryption.methods; } @@ -979,15 +1042,14 @@ define(function(require){ deviceSave: function(form_data, data, success) { var self = this, - id = (typeof data.data == 'object' && data.data.id) ? data.data.id : undefined, + id = (typeof data.data === 'object' && data.data.id) ? data.data.id : undefined, normalized_data = self.deviceFixArrays(self.deviceNormalizeData($.extend(true, {}, data.data, form_data)), form_data); - if(id) { + if (id) { self.deviceUpdate(normalized_data, function(_data, status) { success && success(_data, status, 'update'); }); - } - else { + } else { self.deviceCreate(normalized_data, function(_data, status) { success && success(_data, status, 'create'); }); @@ -1001,7 +1063,9 @@ define(function(require){ resource: 'device.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); @@ -1080,7 +1144,7 @@ define(function(require){ success: function(data) { data = self.deviceFormatDataProvisioner(data.data); - callback && callback(data) + callback && callback(data); } }); }, @@ -1120,7 +1184,7 @@ define(function(require){ var id = node.getMetadata('id'), returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } @@ -1132,25 +1196,28 @@ define(function(require){ self.deviceList(function(devices) { var popup, popup_html; - popup_html = $(monster.template(self, 'device-callflowEdit', { - can_call_self: node.getMetadata('can_call_self') || false, - parameter: { - name: 'timeout (s)', - value: node.getMetadata('timeout') || '20' + popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { + can_call_self: node.getMetadata('can_call_self') || false, + parameter: { + name: 'timeout (s)', + value: node.getMetadata('timeout') || '20' + }, + objects: { + items: _.sortBy(devices, 'name'), + selected: node.getMetadata('id') || '' + } }, - objects: { - items: _.sortBy(devices, 'name'), - selected: node.getMetadata('id') || '' - } + submodule: 'device' })); - if($('#device_selector option:selected', popup_html).val() == undefined) { + if ($('#device_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') === 'edit') ? - { id: $('#device_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#device_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -1181,8 +1248,8 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().callflows.device.device_title, beforeClose: function() { - if(typeof callback == 'function') { - callback(); + if (typeof callback === 'function') { + callback(); } } }); @@ -1240,7 +1307,12 @@ define(function(require){ deviceIcon: deviceIcons.hasOwnProperty(device.device_type) ? deviceIcons[device.device_type] : deviceIcons.unknown, isRegistered: device.enabled ? (['sip_device', 'smartphone', 'softphone', 'fax', 'ata'].indexOf(device.device_type) >= 0 ? registeredDevices.indexOf(device.id) >= 0 : true) : false }; - device.customEntityTemplate = monster.template(self, 'device-entity-element', dataTemplate); + // no jQuery wrapper since this template will be inserted directly with Handlebars + device.customEntityTemplate = self.getTemplate({ + name: 'entity-element', + data: dataTemplate, + submodule: 'device' + }); }); callback && callback(results.device); diff --git a/src/apps/callflows/views/device-callflowEdit.html b/src/apps/callflows/submodules/device/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/device-callflowEdit.html rename to src/apps/callflows/submodules/device/views/callflowEdit.html diff --git a/src/apps/callflows/views/device-ata.html b/src/apps/callflows/submodules/device/views/device-ata.html similarity index 84% rename from src/apps/callflows/views/device-ata.html rename to src/apps/callflows/submodules/device/views/device-ata.html index f76a1b4..be0ef27 100644 --- a/src/apps/callflows/views/device-ata.html +++ b/src/apps/callflows/submodules/device/views/device-ata.html @@ -54,7 +54,7 @@
    - +
    @@ -94,7 +94,7 @@
    - +

    @@ -110,7 +110,7 @@
    - +

    @@ -126,9 +126,34 @@
    - +
    +
    + + {{#if showPAssertedIdentity}} +

    {{ i18n.callflows.device.asserted }}

    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + {{/if}} @@ -221,6 +246,21 @@ + +
    +
    + +
    +
    diff --git a/src/apps/callflows/views/device-cellphone.html b/src/apps/callflows/submodules/device/views/device-cellphone.html similarity index 100% rename from src/apps/callflows/views/device-cellphone.html rename to src/apps/callflows/submodules/device/views/device-cellphone.html diff --git a/src/apps/callflows/views/device-fax.html b/src/apps/callflows/submodules/device/views/device-fax.html similarity index 87% rename from src/apps/callflows/views/device-fax.html rename to src/apps/callflows/submodules/device/views/device-fax.html index 65475c7..b07802e 100644 --- a/src/apps/callflows/views/device-fax.html +++ b/src/apps/callflows/submodules/device/views/device-fax.html @@ -54,7 +54,7 @@
    - +
    @@ -109,7 +109,7 @@
    - +

    @@ -125,7 +125,7 @@
    - +

    @@ -141,9 +141,34 @@
    - +
    +
    + + {{#if showPAssertedIdentity}} +

    {{ i18n.callflows.device.asserted }}

    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + {{/if}}
    diff --git a/src/apps/callflows/views/device-landline.html b/src/apps/callflows/submodules/device/views/device-landline.html similarity index 100% rename from src/apps/callflows/views/device-landline.html rename to src/apps/callflows/submodules/device/views/device-landline.html diff --git a/src/apps/callflows/views/device-mobile.html b/src/apps/callflows/submodules/device/views/device-mobile.html similarity index 88% rename from src/apps/callflows/views/device-mobile.html rename to src/apps/callflows/submodules/device/views/device-mobile.html index fa6dace..27a3147 100644 --- a/src/apps/callflows/views/device-mobile.html +++ b/src/apps/callflows/submodules/device/views/device-mobile.html @@ -98,7 +98,7 @@
    - +

    @@ -114,7 +114,7 @@
    - +
    @@ -128,9 +128,34 @@ +
    + + {{#if showPAssertedIdentity}} +

    {{ i18n.callflows.device.asserted }}

    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + {{/if}}
    @@ -195,6 +220,11 @@
    +
    + {{#monsterText 'warning'}} + {{ i18n.callflows.accountSettings.musicOnHold.shoutcastURLWarning }} + {{/monsterText}} +
    @@ -336,7 +366,7 @@
    -
    +
    diff --git a/src/apps/callflows/views/device-sip_device.html b/src/apps/callflows/submodules/device/views/device-sip_device.html similarity index 84% rename from src/apps/callflows/views/device-sip_device.html rename to src/apps/callflows/submodules/device/views/device-sip_device.html index 50282b2..3979e63 100644 --- a/src/apps/callflows/views/device-sip_device.html +++ b/src/apps/callflows/submodules/device/views/device-sip_device.html @@ -55,7 +55,7 @@
    - + {{#if field_data.provisioner.isEnabled}}
    @@ -72,15 +72,13 @@ {{#each field_data.provisioner.brands}} {{/each}} @@ -133,14 +131,14 @@
    - +
    - +

    @@ -149,14 +147,14 @@
    - +
    - +

    @@ -165,16 +163,41 @@
    - +
    - +
    +
    + + {{#if showPAssertedIdentity}} +

    {{ i18n.callflows.device.asserted }}

    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + {{/if}}
    @@ -276,18 +299,10 @@
    -
    - -
    - -
    - +
    + {{#monsterText 'warning'}} + {{ i18n.callflows.accountSettings.musicOnHold.shoutcastURLWarning }} + {{/monsterText}}
    @@ -310,7 +325,7 @@
    • @@ -327,7 +342,7 @@
      • diff --git a/src/apps/callflows/views/device-sip_uri.html b/src/apps/callflows/submodules/device/views/device-sip_uri.html similarity index 100% rename from src/apps/callflows/views/device-sip_uri.html rename to src/apps/callflows/submodules/device/views/device-sip_uri.html diff --git a/src/apps/callflows/views/device-smartphone.html b/src/apps/callflows/submodules/device/views/device-smartphone.html similarity index 95% rename from src/apps/callflows/views/device-smartphone.html rename to src/apps/callflows/submodules/device/views/device-smartphone.html index 6bb9ccc..90a6514 100644 --- a/src/apps/callflows/views/device-smartphone.html +++ b/src/apps/callflows/submodules/device/views/device-smartphone.html @@ -187,6 +187,13 @@
    + +
    + +
    + +
    +
    diff --git a/src/apps/callflows/views/device-softphone.html b/src/apps/callflows/submodules/device/views/device-softphone.html similarity index 85% rename from src/apps/callflows/views/device-softphone.html rename to src/apps/callflows/submodules/device/views/device-softphone.html index f7ebae2..fefa362 100644 --- a/src/apps/callflows/views/device-softphone.html +++ b/src/apps/callflows/submodules/device/views/device-softphone.html @@ -110,7 +110,7 @@
    - +

    @@ -119,14 +119,14 @@
    - +
    - +
    @@ -136,16 +136,41 @@
    - +
    - +
    +
    + + {{#if showPAssertedIdentity}} +

    {{ i18n.callflows.device.asserted }}

    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + {{/if}}
    @@ -181,6 +206,13 @@
    + +
    + +
    + +
    +
    @@ -208,18 +240,10 @@
    -
    - -
    - -
    - +
    + {{#monsterText 'warning'}} + {{ i18n.callflows.accountSettings.musicOnHold.shoutcastURLWarning }} + {{/monsterText}}
    diff --git a/src/apps/callflows/views/device-entity-element.html b/src/apps/callflows/submodules/device/views/entity-element.html similarity index 100% rename from src/apps/callflows/views/device-entity-element.html rename to src/apps/callflows/submodules/device/views/entity-element.html diff --git a/src/apps/callflows/views/device-general_edit.html b/src/apps/callflows/submodules/device/views/general_edit.html similarity index 100% rename from src/apps/callflows/views/device-general_edit.html rename to src/apps/callflows/submodules/device/views/general_edit.html diff --git a/src/apps/callflows/submodules/directory/directory.css b/src/apps/callflows/submodules/directory/directory.css index 0344a17..eb974a8 100644 --- a/src/apps/callflows/submodules/directory/directory.css +++ b/src/apps/callflows/submodules/directory/directory.css @@ -171,4 +171,4 @@ .callflows-port #directory-form #basic .add_user .add_user_div:hover .add_user_icon { background-position: 0 -24px; cursor: pointer; -} \ No newline at end of file +} diff --git a/src/apps/callflows/submodules/directory/directory.js b/src/apps/callflows/submodules/directory/directory.js index fdf6067..67382a6 100644 --- a/src/apps/callflows/submodules/directory/directory.js +++ b/src/apps/callflows/submodules/directory/directory.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -11,9 +11,13 @@ define(function(require){ 'callflows.directory.edit': '_directoryEdit' }, - directoryRender: function(data, target, callbacks){ + directoryRender: function(data, target, callbacks) { var self = this, - directory_html = $(monster.template(self, 'directory-edit', data)), + directory_html = $(self.getTemplate({ + name: 'edit', + data: data, + submodule: 'directory' + })), directoryForm = directory_html.find('#directory-form'); self.directoryRenderUserList(data, directory_html); @@ -83,31 +87,35 @@ define(function(require){ var $user = $('#select_user_id', directory_html); var $callflow = $('#callflow_id', directory_html); - if($user.val() != 'empty_option_user' && $callflow.val() != 'empty_option_callflow') { + if ($user.val() !== 'empty_option_user' && $callflow.val() !== 'empty_option_callflow') { var user_id = $user.val(), user_data = { user_id: user_id, - user_name: $('#option_user_'+user_id, directory_html).text(), + user_name: $('#option_user_' + user_id, directory_html).text(), callflow_id: $callflow.val(), field_data: { callflows: data.field_data.callflows }, - _t: function(param){ - return window.translate['directory'][param]; + _t: function(param) { + return window.translate.directory[param]; } }; - if($('#row_no_data', directory_html).size() > 0) { + if ($('#row_no_data', directory_html).size() > 0) { $('#row_no_data', directory_html).remove(); } - $('.rows', directory_html).prepend(monster.template(self, 'directory-userRow', user_data)); - $('#option_user_'+user_id, directory_html).hide(); + $('.rows', directory_html) + .prepend($(self.getTemplate({ + name: 'userRow', + data: user_data, + submodule: 'directory' + }))); + $('#option_user_' + user_id, directory_html).hide(); $user.val('empty_option_user'); $callflow.val('empty_option_callflow'); - } - else { + } else { monster.ui.alert('warning', self.i18n.active().callflows.directory.noDataSelected); } }); @@ -115,12 +123,16 @@ define(function(require){ $(directory_html).delegate('.action_user.delete', 'click', function() { var user_id = $(this).data('id'); //removes it from the grid - $('#row_user_'+user_id, directory_html).remove(); + $('#row_user_' + user_id, directory_html).remove(); //re-add it to the dropdown - $('#option_user_'+user_id, directory_html).show(); + $('#option_user_' + user_id, directory_html).show(); //if grid empty, add no data line - if($('.rows .row', directory_html).size() == 0) { - $('.rows', directory_html).append(monster.template(self, 'directory-userRow')); + if ($('.rows .row', directory_html).size() === 0) { + $('.rows', directory_html) + .append($(self.getTemplate({ + name: 'userRow', + submodule: 'directory' + }))); } }); @@ -132,11 +144,11 @@ define(function(require){ directoryRenderUserList: function(data, parent) { var self = this; - if(data.data.id) { - if('users' in data.data && data.data.users.length > 0) { + if (data.data.id) { + if ('users' in data.data && data.data.users.length > 0) { var user_item; $.each(data.field_data.users, function(k, v) { - if(v.id in data.field_data.old_list) { + if (v.id in data.field_data.old_list) { user_item = { user_id: v.id, user_name: v.first_name + ' ' + v.last_name, @@ -146,19 +158,30 @@ define(function(require){ } }; - $('.rows', parent).append(monster.template(self, 'directory-userRow', user_item)); - $('#option_user_'+v.id, parent).hide(); + $('.rows', parent) + .append($(self.getTemplate({ + name: 'userRow', + data: user_item, + submodule: 'directory' + }))); + $('#option_user_' + v.id, parent).hide(); } }); + } else { + $('.rows', parent) + .empty() + .append($(self.getTemplate({ + name: 'userRow', + submodule: 'directory' + }))); } - else { - $('.rows', parent).empty() - .append(monster.template(self, 'directory-userRow')); - } - } - else { - $('.rows', parent).empty() - .append(monster.template(self,'directory-userRow')); + } else { + $('.rows', parent) + .empty() + .append($(self.getTemplate({ + name: 'userRow', + submodule: 'directory' + }))); } }, @@ -168,7 +191,7 @@ define(function(require){ self.directoryEdit(args.data, args.parent, args.target, args.callbacks, args.data_defaults); }, - directoryEdit: function(data, _parent, _target, _callbacks, data_defaults){ + directoryEdit: function(data, _parent, _target, _callbacks, data_defaults) { var self = this, parent = _parent || $('#directory-content'), target = _target || $('#directory-view', parent), @@ -196,93 +219,89 @@ define(function(require){ }; monster.parallel({ - callflow_list: function(callback) { - self.callApi({ - resource: 'callflow.list', - data: { - accountId: self.accountId, - filters: { - paginate: 'false' + callflow_list: function(callback) { + self.callApi({ + resource: 'callflow.list', + data: { + accountId: self.accountId, + filters: { + paginate: 'false' + } + }, + success: function(callflows) { + var list_callflows = []; + $.each(callflows.data, function() { + if (this.featurecode === false) { + list_callflows.push(this); } - }, - success: function(callflows) { - var list_callflows = []; - $.each(callflows.data, function() { - if(this.featurecode == false) { - list_callflows.push(this); - } - }); + }); - list_callflows.sort(function(a, b) { - var aName = (a.name || (a.numbers[0] + '')).toLowerCase(), - bName = (b.name || (b.numbers[0] + '')).toLowerCase(); + list_callflows.sort(function(a, b) { + var aName = (a.name || (a.numbers[0] + '')).toLowerCase(), + bName = (b.name || (b.numbers[0] + '')).toLowerCase(); - return aName > bName ? 1 : -1; - }); + return aName > bName ? 1 : -1; + }); - defaults.field_data.callflows = list_callflows; + defaults.field_data.callflows = list_callflows; - callback(null, callflows); + callback(null, callflows); + } + }); + }, + user_list: function(callback) { + self.callApi({ + resource: 'user.list', + data: { + accountId: self.accountId, + filters: { + paginate: 'false' } - }); - }, - user_list: function(callback) { - self.callApi({ - resource: 'user.list', - data: { - accountId: self.accountId, - filters: { - paginate: 'false' - } - }, - success: function(users) { - users.data.sort(function(a,b) { - var aName = (a.first_name + ' ' + a.last_name).toLowerCase(), - bName = (b.first_name + ' ' + b.last_name).toLowerCase(); - - return aName > bName ? 1 : -1; - }); + }, + success: function(users) { + users.data.sort(function(a, b) { + var aName = (a.first_name + ' ' + a.last_name).toLowerCase(), + bName = (b.first_name + ' ' + b.last_name).toLowerCase(); - defaults.field_data.users = users.data; + return aName > bName ? 1 : -1; + }); - callback(null, users); - } - }); - }, - directory_get: function(callback) { - if(typeof data === 'object' && data.id) { - self.directoryGet(data.id, function(directory, status) { - defaults.field_data.old_list = {}; - - if('users' in directory) { - $.each(directory.users, function(k, v) { - defaults.field_data.old_list[v.user_id] = v.callflow_id; - }); - } + defaults.field_data.users = users.data; - callback(null, directory); - } - ); + callback(null, users); } - else { - callback(null, {}); - } - } + }); }, - function(err, results) { - var render_data = defaults; + directory_get: function(callback) { + if (typeof data === 'object' && data.id) { + self.directoryGet(data.id, function(directory, status) { + defaults.field_data.old_list = {}; + + if ('users' in directory) { + $.each(directory.users, function(k, v) { + defaults.field_data.old_list[v.user_id] = v.callflow_id; + }); + } - if(typeof data === 'object' && data.id) { - render_data = $.extend(true, defaults, { data: results.directory_get }); + callback(null, directory); + }); + } else { + callback(null, {}); } + } + }, function(err, results) { + var render_data = defaults; - self.directoryRender(render_data, target, callbacks); + if (typeof data === 'object' && data.id) { + render_data = $.extend(true, defaults, { data: results.directory_get }); + } - if(typeof callbacks.after_render == 'function') { - callbacks.after_render(); - } + self.directoryRender(render_data, target, callbacks); + + if (typeof callbacks.after_render === 'function') { + callbacks.after_render(); } - ); + }); }, directoryPopupEdit: function(args) { @@ -299,14 +318,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -324,7 +343,7 @@ define(function(require){ }, directoryCleanFormData: function(form_data) { - if(!(form_data.max_dtmf > 0)) { + if (!(form_data.max_dtmf > 0)) { delete form_data.max_dtmf; } @@ -337,14 +356,13 @@ define(function(require){ var self = this, normalized_data = self.directoryNormalizeData($.extend(true, {}, data.data, form_data)); - if (typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { self.directoryUpdate(normalized_data, function(_data, status) { self.directoryUpdateUsers(data.field_data.user_list, _data.id, function() { success && success(_data, status, 'update'); }); - }) - } - else { + }); + } else { self.directoryCreate(normalized_data, function(_data, status) { self.directoryUpdateUsers(data.field_data.user_list, _data.id, function() { success && success(_data, status, 'create'); @@ -363,13 +381,12 @@ define(function(require){ userId: user_id }, success: function(_data, status) { - if(callflow_id) { - if(!_data.data.directories || $.isArray(_data.data.directories)) { + if (callflow_id) { + if (!_data.data.directories || $.isArray(_data.data.directories)) { _data.data.directories = {}; } _data.data.directories[directory_id] = callflow_id; - } - else { + } else { delete _data.data.directories[directory_id]; } @@ -394,14 +411,14 @@ define(function(require){ users_count = 0, callback = function() { users_updated_count++; - if(users_updated_count >= users_count) { + if (users_updated_count >= users_count) { success(); } }; - if(old_directory_user_list) { - $.each(old_directory_user_list, function(k, v) { - if(!(k in new_directory_user_list)) { + if (old_directory_user_list) { + $.each(old_directory_user_list, function(k) { + if (!(k in new_directory_user_list)) { //Request to update user without this directory. users_count++; self.directoryUpdateSingleUser(k, directory_id, undefined, callback); @@ -409,22 +426,20 @@ define(function(require){ }); $.each(new_directory_user_list, function(k, v) { - if(k in old_directory_user_list) { - if(old_directory_user_list[k] != v) { + if (k in old_directory_user_list) { + if (old_directory_user_list[k] !== v) { //Request to update user users_count++; self.directoryUpdateSingleUser(k, directory_id, v, callback); } //else it has not been updated - } - else { + } else { users_count++; self.directoryUpdateSingleUser(k, directory_id, v, callback); } }); - } - else { - if(new_directory_user_list) { + } else { + if (new_directory_user_list) { $.each(new_directory_user_list, function(k, v) { users_count++; self.directoryUpdateSingleUser(k, directory_id, v, callback); @@ -432,7 +447,7 @@ define(function(require){ } } - if(users_count === 0) { + if (users_count === 0) { success(); } }, @@ -463,7 +478,7 @@ define(function(require){ var id = node.getMetadata('id'), returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } @@ -475,18 +490,21 @@ define(function(require){ self.directoryList(function(directories) { var popup, popup_html; - popup_html = $(monster.template(self, 'directory-callflowEdit', { - items: _.sortBy(directories, 'name'), - selected: node.getMetadata('id') || '' + popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { + items: _.sortBy(directories, 'name'), + selected: node.getMetadata('id') || '' + }, + submodule: 'directory' })); - if($('#directory_selector option:selected', popup_html).val() == undefined) { + if ($('#directory_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#directory_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#directory_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -513,7 +531,7 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().callflows.directory.directory_title, beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -525,7 +543,9 @@ define(function(require){ resource: 'directory.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -544,7 +564,9 @@ define(function(require){ resource: 'directory.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); @@ -559,7 +581,10 @@ define(function(require){ resource: 'directory.get', data: { accountId: self.accountId, - directoryId: directoryId + directoryId: directoryId, + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); diff --git a/src/apps/callflows/views/directory-callflowEdit.html b/src/apps/callflows/submodules/directory/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/directory-callflowEdit.html rename to src/apps/callflows/submodules/directory/views/callflowEdit.html diff --git a/src/apps/callflows/views/directory-edit.html b/src/apps/callflows/submodules/directory/views/edit.html similarity index 75% rename from src/apps/callflows/views/directory-edit.html rename to src/apps/callflows/submodules/directory/views/edit.html index 08dcc3f..8e45afa 100644 --- a/src/apps/callflows/views/directory-edit.html +++ b/src/apps/callflows/submodules/directory/views/edit.html @@ -28,43 +28,6 @@
    -
    -
    {{ i18n.callflows.directory.add_user }}
    -
    -
    -
    - - -
    -
    - - -
    -
    - -
    -
    -
    @@ -79,7 +42,51 @@ {{ i18n.callflows.directory.remove }}
    -
    +
    +
    + +
    +
    {{ i18n.callflows.directory.add_user }}
    +
    +
    +
      +
      +
    • + + +
    • +
      +
      +
    • + + + +
    • +
      +
    +
    +
    diff --git a/src/apps/callflows/views/directory-userRow.html b/src/apps/callflows/submodules/directory/views/userRow.html similarity index 100% rename from src/apps/callflows/views/directory-userRow.html rename to src/apps/callflows/submodules/directory/views/userRow.html diff --git a/src/apps/callflows/submodules/faxbox/faxbox.css b/src/apps/callflows/submodules/faxbox/faxbox.css index 7c0a6a3..a5c05cc 100644 --- a/src/apps/callflows/submodules/faxbox/faxbox.css +++ b/src/apps/callflows/submodules/faxbox/faxbox.css @@ -15,4 +15,4 @@ font-size: 13px; font-weight: bold; line-height: 30px; -} \ No newline at end of file +} diff --git a/src/apps/callflows/submodules/faxbox/faxbox.js b/src/apps/callflows/submodules/faxbox/faxbox.js index fa363ba..fb5078a 100644 --- a/src/apps/callflows/submodules/faxbox/faxbox.js +++ b/src/apps/callflows/submodules/faxbox/faxbox.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'), @@ -37,7 +37,7 @@ define(function(require){ var id = node.getMetadata('id'), returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } @@ -47,19 +47,22 @@ define(function(require){ var _this = this; self.faxboxList(function(data, status) { - var popup_html = $(monster.template(self, 'faxbox-callflowEdit', { - items: _.sortBy(data, 'name'), - selected: node.getMetadata('id') || '' + var popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { + items: _.sortBy(data, 'name'), + selected: node.getMetadata('id') || '' + }, + submodule: 'faxbox' })), popup; - if($('#faxbox_selector option:selected', popup_html).val() == undefined) { + if ($('#faxbox_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#faxbox_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#faxbox_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -87,7 +90,7 @@ define(function(require){ title: self.i18n.active().callflows.faxbox.voicemail_title, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -99,7 +102,9 @@ define(function(require){ resource: 'faxbox.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -123,14 +128,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if ( typeof callback == 'function' ) { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if ( typeof callback == 'function' ) { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -155,9 +160,9 @@ define(function(require){ _callbacks = _callbacks || {}, callbacks = { save_success: _callbacks.save_success || function(_data) { - self.faxboxRenderList(parent); + self.faxboxRenderList(parent); - self.faxboxEdit({ id: _data.id }, parent, target, callbacks); + self.faxboxEdit({ id: _data.id }, parent, target, callbacks); }, delete_success: _callbacks.delete_success || function() { target.empty(); @@ -169,84 +174,114 @@ define(function(require){ }; monster.parallel({ - faxbox: function(callback) { - if (typeof data === 'object' && data.id) { - self.faxboxGet(data.id, function(_data, status) { - _data.id = data.id; + faxbox: function(callback) { + if (typeof data === 'object' && data.id) { + self.faxboxGet(data.id, function(_data, status) { + _data.id = data.id; - callback(null, _data); + callback(null, _data); + }); + } else { + callback(null, {}); + } + }, + user_list: function(callback) { + self.callApi({ + resource: 'user.list', + data: { + accountId: self.accountId, + filters: { + paginate: false + } + }, + success: function(_data, status) { + _data.data.sort(function(a, b) { + if (a.hasOwnProperty('first_name') && a.hasOwnProperty('last_name') && b.hasOwnProperty('first_name') && b.hasOwnProperty('last_name')) { + return a.first_name.concat(' ', a.last_name).toLowerCase() > b.first_name.concat(' ', b.last_name).toLowerCase() ? 1 : -1; + } else { + return 1; + } }); - } else { - callback(null, {}); - } - }, - user_list: function(callback) { - self.callApi({ - resource: 'user.list', - data: { - accountId: self.accountId, - filters: { paginate:false } - }, - success: function(_data, status) { - _data.data.sort(function(a, b){ - if(a.hasOwnProperty('first_name') && a.hasOwnProperty('last_name') && b.hasOwnProperty('first_name') && b.hasOwnProperty('last_name')) { - return a.first_name.concat(' ', a.last_name).toLowerCase() > b.first_name.concat(' ', b.last_name).toLowerCase() ? 1 : -1; - } - else { - return 1; - } - }); - - _data.data.unshift({ - id: '', - first_name: self.i18n.active().callflows.faxbox.no, - last_name: self.i18n.active().callflows.faxbox.owner - }); - callback(null, _data.data); - } - }); - }, - current_user: function(callback) { - if (!monster.util.isMasquerading()) { - self.faxboxGetUser(self.userId, function(_data, status) { - callback(null, _data); + _data.data.unshift({ + id: '', + first_name: self.i18n.active().callflows.faxbox.no, + last_name: self.i18n.active().callflows.faxbox.owner }); + + callback(null, _data.data); } - else { - callback(null, {}); - } + }); + }, + current_user: function(callback) { + if (!monster.util.isMasquerading()) { + self.faxboxGetUser(self.userId, function(_data, status) { + callback(null, _data); + }); + } else { + callback(null, {}); } }, - function(err, results) { - if (!data.hasOwnProperty('id')) { - if (_.size(results.current_user) === 0) { - results.faxbox = $.extend(true, self.faxboxGetDefaultSettings(), results.faxbox); - } - else { - results.faxbox = $.extend(true, self.faxboxGetDefaultSettings(results.current_user), results.faxbox); + phone_numbers: function(callback) { + self.callApi({ + resource: 'numbers.list', + data: { + accountId: self.accountId, + filters: { + paginate: false + } + }, + success: function(_data) { + _data.numbers = _.chain(_data) + .get('data.numbers', {}) + .keys() + .sortBy() + .value(); + + callback(null, _data.numbers); } + }); + } + }, function(err, results) { + if (!data.hasOwnProperty('id')) { + if (_.size(results.current_user) === 0) { + results.faxbox = $.extend(true, self.faxboxGetDefaultSettings(), results.faxbox); + } else { + results.faxbox = $.extend(true, self.faxboxGetDefaultSettings(results.current_user), results.faxbox); } + } - delete results.current_user; + delete results.current_user; - self.faxboxRender(results, target, callbacks); + var invalidCallerID = _.find(results.phone_numbers, _.get(results.faxbox, 'caller_id', null)); - if (typeof callbacks.after_render === 'function') { - callbacks.after_render(); - } + if (!invalidCallerID) { + results.phone_numbers.unshift(results.faxbox.caller_id); } - ); + + self.faxboxRender(results, target, callbacks); + + if (typeof callbacks.after_render === 'function') { + callbacks.after_render(); + } + }); }, faxboxRender: function(data, target, callbacks) { var self = this, - faxbox_html = $(monster.template(self, 'faxbox-edit', { - faxbox: self.faxboxNormalizedData(data.faxbox), - users: data.user_list + faxbox_html = $(self.getTemplate({ + name: 'edit', + data: { + faxbox: self.faxboxNormalizedData(data.faxbox), + users: data.user_list, + phone_numbers: data.phone_numbers + }, + submodule: 'faxbox' })); - timezone.populateDropdown($('#fax_timezone', faxbox_html), data.faxbox.fax_timezone||'inherit', {inherit: self.i18n.active().defaultTimezone}); + monster.ui.chosen(faxbox_html.find('.callflows-caller-id-dropdown')); + + timezone.populateDropdown($('#fax_timezone', faxbox_html), data.faxbox.fax_timezone || 'inherit', {inherit: self.i18n.active().defaultTimezone}); $('*[rel=popover]:not([type="text"])', faxbox_html).popover({ trigger: 'hover' @@ -261,7 +296,7 @@ define(function(require){ if (!data.faxbox.hasOwnProperty('id')) { $('#owner_id', faxbox_html).change(function(ev) { if ($(this).val()) { - self.faxboxGetUser($(this).val(),function(_data, status) { + self.faxboxGetUser($(this).val(), function(_data, status) { data.faxbox = self.faxboxGetDefaultSettings(_data); $('#edit_link', faxbox_html).show(); self.faxboxRender(data, target, callbacks); @@ -272,8 +307,7 @@ define(function(require){ self.faxboxRender(data, target, callbacks); } }); - } - else { + } else { $('#owner_id', faxbox_html).change(function(ev) { var currentFaxbox = monster.ui.getFormData('faxbox_form'); @@ -302,8 +336,7 @@ define(function(require){ $('#edit_link', faxbox_html).hide(); self.faxboxRender(data, target, callbacks); }); - } - else { + } else { $('[id$="bound_notification_email"]', faxbox_html).each(function(idx, el) { $(el).attr('disabled', false); }); @@ -311,30 +344,28 @@ define(function(require){ }); } - if(!$('#owner_id', faxbox_html).val()) { + if (!$('#owner_id', faxbox_html).val()) { $('#edit_link', faxbox_html).hide(); } $('.inline-action', faxbox_html).click(function(ev) { - var _data = $(this).data('action') == 'edit' ? { id: $('#owner_id', faxbox_html).val() } : {}, + var _data = $(this).data('action') === 'edit' ? { id: $('#owner_id', faxbox_html).val() } : {}, _id = _data.id; monster.pub('callflows.user.popupEdit', { data: _data, callflow: function(_data) { /* Create */ - if(!_id) { - $('#owner_id', faxbox_html).append('') + if (!_id) { + $('#owner_id', faxbox_html).append(''); $('#owner_id', faxbox_html).val(_data.id); - } - else { + } else { /* Update */ - if('id' in _data) { - $('#owner_id #'+_data.id, faxbox_html).text(_data.first_name + ' ' + _data.last_name); - } + if ('id' in _data) { + $('#owner_id #' + _data.id, faxbox_html).text(_data.first_name + ' ' + _data.last_name); /* Delete */ - else { - $('#owner_id #'+_id, faxbox_html).remove(); + } else { + $('#owner_id #' + _id, faxbox_html).remove(); } } } @@ -350,7 +381,7 @@ define(function(require){ fax_identity.val(number.replace(/^\+1([0-9]{3})([0-9]{3})([0-9]{4})$/, '+1 ($1) $2-$3')); } else if (/^1([0-9]{10})$/.test(number)) { fax_identity.val(number.replace(/^1([0-9]{3})([0-9]{3})([0-9]{4})$/, '+1 ($1) $2-$3')); - } else { + } else { fax_identity.val(number.replace(/^([0-9]{3})([0-9]{3})([0-9]{4})$/, '+1 ($1) $2-$3')); } } else { @@ -363,7 +394,7 @@ define(function(require){ var form_html = $('#faxbox_form', faxbox_html), form_data = monster.ui.getFormData('faxbox_form'), - word_reg = /^[\w\s'-]+/ + word_reg = /^[\w\s'-]+/; monster.ui.validate(form_html, { rules: { @@ -395,7 +426,7 @@ define(function(require){ var $this = $(this); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { $this.addClass('disabled'); if (monster.ui.valid(form_html)) { @@ -405,8 +436,7 @@ define(function(require){ }, function(data) { $this.removeClass('disabled'); }); - } - else { + } else { $this.removeClass('disabled'); } } @@ -432,7 +462,7 @@ define(function(require){ var map_crossbar_data = function(data) { var new_list = []; - if(data.length > 0) { + if (data.length > 0) { $.each(data, function(key, val) { new_list.push({ id: val.id, @@ -457,7 +487,7 @@ define(function(require){ caller_name: '', fax_header: '', fax_timezone: 'inherit', - retries: 1, + retries: 3, notifications: { inbound: { email: { @@ -476,24 +506,23 @@ define(function(require){ return default_faxbox; } else { return $.extend(true, {}, default_faxbox, { - name: user.first_name.concat(' ', user.last_name, self.i18n.active().callflows.faxbox.default_settings_name_extension), - caller_name: user.first_name.concat(' ', user.last_name), - fax_header: monster.config.whitelabel.companyName.concat(self.i18n.active().callflows.faxbox.default_settings_header_extension), - owner_id: user.id, - notifications: { - inbound: { - email: { - send_to: user.email || user.username - } - }, - outbound: { - email: { - send_to: user.email || user.username - } - } + name: user.first_name.concat(' ', user.last_name, self.i18n.active().callflows.faxbox.default_settings_name_extension), + caller_name: user.first_name.concat(' ', user.last_name), + fax_header: monster.config.whitelabel.companyName.concat(self.i18n.active().callflows.faxbox.default_settings_header_extension), + owner_id: user.id, + notifications: { + inbound: { + email: { + send_to: user.email || user.username + } + }, + outbound: { + email: { + send_to: user.email || user.username } } - ); + } + }); } }, @@ -501,47 +530,47 @@ define(function(require){ var self = this, normalized_data = self.faxboxNormalizedData($.extend(true, {}, data, form_data)); - if(typeof data == 'object' && data.id) { + if (typeof data === 'object' && data.id) { self.faxboxUpdate(normalized_data, function(_data, status) { - if(typeof success == 'function') { - success(_data, status, 'update'); - } - }, - function(_data, status) { - if(typeof error == 'function') { - error(_data, status, 'update'); - } + if (typeof success === 'function') { + success(_data, status, 'update'); } - ); + }, function(_data, status) { + if (typeof error === 'function') { + error(_data, status, 'update'); + } + }); } else { self.faxboxCreate(normalized_data, function(_data, status) { - if(typeof success == 'function') { - success(_data, status, 'create'); - } - }, - function(_data, status) { - if(typeof error == 'function') { - error(_data, status, 'create'); - } + if (typeof success === 'function') { + success(_data, status, 'create'); } - ); + }, function(_data, status) { + if (typeof error === 'function') { + error(_data, status, 'create'); + } + }); } }, faxboxNormalizedData: function(form_data) { if (form_data.hasOwnProperty('notifications')) { - if (form_data.notifications.hasOwnProperty('inbound') && form_data.notifications.inbound.hasOwnProperty('email') && form_data.notifications.inbound.email.hasOwnProperty('send_to') && form_data.notifications.inbound.email.send_to.length) { - var inbound = form_data.notifications.inbound.email.send_to; - form_data.notifications.inbound.email.send_to = inbound instanceof Array ? inbound.join(',') : inbound.replace(/\s/g, '').split(','); - } else { - delete form_data.notifications.inbound.email.send_to; + if (form_data.notifications.hasOwnProperty('inbound') && form_data.notifications.inbound.hasOwnProperty('email') && form_data.notifications.inbound.email.hasOwnProperty('send_to')) { + if (form_data.notifications.inbound.email.send_to.length) { + var inbound = form_data.notifications.inbound.email.send_to; + form_data.notifications.inbound.email.send_to = inbound instanceof Array ? inbound.join(',') : inbound.replace(/\s/g, '').split(','); + } else { + delete form_data.notifications.inbound.email.send_to; + } } - if (form_data.notifications.hasOwnProperty('outbound') && form_data.notifications.outbound.hasOwnProperty('email') && form_data.notifications.outbound.email.hasOwnProperty('send_to') && form_data.notifications.outbound.email.send_to.length) { - var outbound = form_data.notifications.outbound.email.send_to; - form_data.notifications.outbound.email.send_to = outbound instanceof Array ? outbound.join(',') : outbound.replace(/\s/g, '').split(','); - } else { - delete form_data.notifications.outbound.email.send_to; + if (form_data.notifications.hasOwnProperty('outbound') && form_data.notifications.outbound.hasOwnProperty('email') && form_data.notifications.outbound.email.hasOwnProperty('send_to')) { + if (form_data.notifications.outbound.email.send_to.length) { + var outbound = form_data.notifications.outbound.email.send_to; + form_data.notifications.outbound.email.send_to = outbound instanceof Array ? outbound.join(',') : outbound.replace(/\s/g, '').split(','); + } else { + delete form_data.notifications.outbound.email.send_to; + } } } @@ -551,7 +580,7 @@ define(function(require){ } else { var list = form_data.smtp_permission_list; - form_data.smtp_permission_list = list instanceof Array ? list.join(',') : list.replace(/\s/g, '').split(','); + form_data.smtp_permission_list = list instanceof Array ? list.join(',') : list.replace(/\s/g, '').split(','); } } @@ -563,10 +592,14 @@ define(function(require){ delete form_data.owner_id; } - if(form_data.fax_timezone && form_data.fax_timezone === 'inherit') { + if (form_data.fax_timezone && form_data.fax_timezone === 'inherit') { delete form_data.fax_timezone; } + if (form_data.caller_id === '_disabled') { + delete form_data.caller_id; + } + return form_data; }, @@ -577,7 +610,9 @@ define(function(require){ resource: 'faxbox.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); diff --git a/src/apps/callflows/views/faxbox-callflowEdit.html b/src/apps/callflows/submodules/faxbox/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/faxbox-callflowEdit.html rename to src/apps/callflows/submodules/faxbox/views/callflowEdit.html diff --git a/src/apps/callflows/views/faxbox-edit.html b/src/apps/callflows/submodules/faxbox/views/edit.html similarity index 91% rename from src/apps/callflows/views/faxbox-edit.html rename to src/apps/callflows/submodules/faxbox/views/edit.html index cdbb4d8..be626d4 100644 --- a/src/apps/callflows/views/faxbox-edit.html +++ b/src/apps/callflows/submodules/faxbox/views/edit.html @@ -17,9 +17,16 @@
  • {{ i18n.callflows.faxbox.caller_id_placeholder }}
  • {{ i18n.callflows.faxbox.smtp }}
  • {{#if faxbox.cloud_connector_claim_url}} -
  • {{ i18n.callflows.faxbox.google }}
  • +
  • + {{ i18n.callflows.faxbox.google }} +
  • {{/if}} -
  • {{ i18n.callflows.faxbox.options }}
  • +
  • + + + {{ i18n.callflows.faxbox.options }} + +
  • @@ -73,7 +80,16 @@
    - + + +
    diff --git a/src/apps/callflows/submodules/featurecodes/featurecodes.js b/src/apps/callflows/submodules/featurecodes/featurecodes.js index 235c20f..c263c34 100644 --- a/src/apps/callflows/submodules/featurecodes/featurecodes.js +++ b/src/apps/callflows/submodules/featurecodes/featurecodes.js @@ -1,8 +1,7 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), - monster = require('monster'), - toastr = require('toastr'); + monster = require('monster'); var app = { requests: {}, @@ -17,12 +16,17 @@ define(function(require){ self.featureCodeGetData(function(featureCodes) { var formattedData = self.featureCodeFormatData(featureCodes), - template = $(monster.template(self, 'featurecodes-view', formattedData)); + template = $(self.getTemplate({ + name: 'view', + data: formattedData, + submodule: 'featurecodes' + })); self.featureCodeBindEvents(template, formattedData.actions); - container.empty() - .append(template); + container + .empty() + .append(template); }); }, @@ -36,40 +40,53 @@ define(function(require){ featureCodeFormatData: function(data) { var self = this, - actions = {}, - categories = {}, - formattedData = { - categories: {}, - actions: {} - }; - - self.featureCodesDefine(actions); - - _.each(data, function(callflow) { - if (callflow.hasOwnProperty('featurecode') && callflow.featurecode !== false) { - if (actions.hasOwnProperty(callflow.featurecode.name)) { - actions[callflow.featurecode.name].id = callflow.id; - actions[callflow.featurecode.name].enabled = true; - actions[callflow.featurecode.name].number = callflow.featurecode.number.replace('\\', ''); - } - } - }); - - $.each(actions, function(i, action) { - this.tag = i; - this.number = typeof action.number === 'undefined' ? action.default_number : action.number; - this.hasConfig = this.hasOwnProperty('editConfiguration'); - - if (action.hasOwnProperty('category')) { - categories[action.category] = categories[action.category] || []; - categories[action.category].push(action); - } - }); - - formattedData.categories = categories; - formattedData.actions = actions; - - return formattedData; + actions = self.featureCodesDefine(); + + return { + actions: _.transform(data, function(object, callflow) { + _.merge(object[callflow.featurecode.name], { + id: callflow.id, + enabled: true, + number: callflow.featurecode.number.replace('\\', '') + }); + }, actions), + categories: _ + .chain(actions) + .map(function(value, key) { + return _.merge(value, { + action: key + }); + }) + .groupBy('category') + .map(function(codes, category) { + return { + category: category, + items: _ + .chain(codes) + .map(function(code) { + return _.merge({ + hasConfig: _.isFunction(code.editConfiguration), + number: _.get(code, 'number', code.default_number), + tag: code.action + }, _.pick(code, [ + 'enabled', + 'hasStar', + 'id', + 'name', + 'number_type' + ])); + }) + .sortBy(function(code) { + var number = _.toNumber(code.number); + + return _.isNaN(number) ? -1 : number; + }) + .value() + }; + }) + .sortBy('category') + .value() + }; }, featureCodeBindEvents: function(template, actions) { @@ -98,9 +115,9 @@ define(function(require){ action_wrapper = $this.parents('.action_wrapper'), number_field = action_wrapper.find('.featurecode-number'); - if(!$this.is(':checked') && action_wrapper.data('enabled') === true) { + if (!$this.is(':checked') && action_wrapper.data('enabled') === true) { action_wrapper.addClass('disabled'); - } else if($this.is(':checked') && action_wrapper.data('enabled') === false){ + } else if ($this.is(':checked') && action_wrapper.data('enabled') === false) { action_wrapper.addClass('enabled'); } else { action_wrapper.removeClass('enabled'); @@ -113,13 +130,16 @@ define(function(require){ template.find('.featurecode-save').on('click', function(e) { var $this = $(this); e.preventDefault(); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { var formData = self.featureCodeCleanFormData(template, actions); $this.addClass('disabled'); self.featureCodeMassUpdate(formData, function() { - toastr.success(self.i18n.active().callflows.featureCodes.successUpdate); + monster.ui.toast({ + type: 'success', + message: self.i18n.active().callflows.featureCodes.successUpdate + }); $this.removeClass('disabled'); self.featureCodeRender(); @@ -147,6 +167,7 @@ define(function(require){ data: { accountId: self.accountId, filters: { + has_key: 'featurecode.name', paginate: false } }, @@ -191,19 +212,18 @@ define(function(require){ children: {} }; - /* if(callflow.type === 'number') { callflow.type = 'numbers'} - if(callflow.type === 'pattern') { callflow.type = 'patterns'}*/ + // if (callflow.type === 'number') { callflow.type = 'numbers'} + // if (callflow.type === 'pattern') { callflow.type = 'patterns'} /* if a star is in the pattern, then we need to escape it */ - if(callflow.type === 'patterns' && typeof callflow.number === 'string') { - callflow.number = callflow.number.replace(/([*])/g,'\\$1'); + if (callflow.type === 'patterns' && typeof callflow.number === 'string') { + callflow.number = callflow.number.replace(/([*])/g, '\\$1'); } callflow[callflow.type] = [actions[callflow.action].build_regex(callflow.number)]; form_data.created_callflows.push(callflow); }); - template.find('.disabled').each(function() { var callflow = $(this).data(); @@ -213,7 +233,7 @@ define(function(require){ }); template.find('.changed:not(.enabled, .disabled)').each(function() { - if($(this).data('enabled')) { + if ($(this).data('enabled')) { var callflow = $(this).data(); // Casting in String, as back-end requires a String @@ -226,8 +246,8 @@ define(function(require){ }; /* if a star is in the pattern, then we need to escape it */ - if(callflow.type === 'patterns') { - callflow.number = callflow.number.replace(/([*])/g,'\\$1'); + if (callflow.type === 'patterns') { + callflow.number = callflow.number.replace(/([*])/g, '\\$1'); } callflow[callflow.type] = [actions[callflow.action].build_regex(callflow.number)]; @@ -289,7 +309,7 @@ define(function(require){ var self = this, count = form_data.created_callflows.length + form_data.deleted_callflows.length + form_data.updated_callflows.length; - if(count) { + if (count) { var parallelRequests = {}; _.each(form_data.created_callflows, function(callflow) { @@ -339,17 +359,35 @@ define(function(require){ monster.parallel(parallelRequests, function(err, results) { callback && callback(); }); - } - else { + } else { errorCallback && errorCallback(); - toastr.error(self.i18n.active().callflows.featureCodes.nothing_to_save); + monster.ui.toast({ + type: 'error', + message: self.i18n.active().callflows.featureCodes.nothing_to_save + }); } }, featureCodesDefine: function(featurecodes) { var self = this; - $.extend(featurecodes, { + return { + directed_ext_pickup: { + name: self.i18n.active().callflows.featureCodes.directed_ext_pickup, + category: self.i18n.active().callflows.featureCodes.miscellaneous_cat, + module: 'group_pickup_feature', + number_type: 'patterns', + data: { + type: 'extension' + }, + enabled: false, + hasStar: true, + default_number: '87', + number: this.default_number, + build_regex: function(number) { + return '^\\*' + number + '([0-9]+)$'; + } + }, 'call_forward[action=activate]': { name: self.i18n.active().callflows.featureCodes.enable_call_forward, icon: 'phone', @@ -364,7 +402,7 @@ define(function(require){ default_number: '72', number: this.default_number, build_regex: function(number) { - return '*'+number; + return '*' + number; } }, 'call_forward[action=deactivate]': { @@ -381,7 +419,7 @@ define(function(require){ default_number: '73', number: this.default_number, build_regex: function(number) { - return '*'+number; + return '*' + number; } }, 'call_forward[action=toggle]': { @@ -398,7 +436,7 @@ define(function(require){ default_number: '74', number: this.default_number, build_regex: function(number) { - return '^\\*'+number+'([0-9]*)$'; + return '^\\*' + number + '([0-9]*)$'; } }, 'call_forward[action=update]': { @@ -415,7 +453,7 @@ define(function(require){ default_number: '56', number: this.default_number, build_regex: function(number) { - return '*'+number; + return '*' + number; } }, @@ -433,7 +471,7 @@ define(function(require){ default_number: '11', number: this.default_number, build_regex: function(number) { - return '*'+number; + return '*' + number; } }, 'hotdesk[action=logout]': { @@ -450,7 +488,7 @@ define(function(require){ default_number: '12', number: this.default_number, build_regex: function(number) { - return '*'+number; + return '*' + number; } }, 'hotdesk[action=toggle]': { @@ -467,7 +505,7 @@ define(function(require){ default_number: '13', number: this.default_number, build_regex: function(number) { - return '*'+number; + return '*' + number; } }, 'voicemail[action=check]': { @@ -484,7 +522,7 @@ define(function(require){ default_number: '97', number: this.default_number, build_regex: function(number) { - return '^\\*'+number+'([0-9]*)$'; + return '^\\*' + number + '([0-9]*)$'; } }, 'voicemail[single_mailbox_login]': { @@ -502,7 +540,7 @@ define(function(require){ default_number: '98', number: this.default_number, build_regex: function(number) { - return '^\\*'+number+'([0-9]*)$'; + return '^\\*' + number + '([0-9]*)$'; } }, 'voicemail[action="direct"]': { @@ -518,7 +556,7 @@ define(function(require){ default_number: '*', number: this.default_number, build_regex: function(number) { - return '^\\*'+number+'([0-9]*)$'; + return '^\\*' + number + '([0-9]*)$'; } }, 'intercom': { @@ -534,7 +572,7 @@ define(function(require){ default_number: '0', number: this.default_number, build_regex: function(number) { - return '^\\*'+number+'([0-9]*)$'; + return '^\\*' + number + '([0-9]*)$'; } }, 'privacy[mode=full]': { @@ -551,7 +589,7 @@ define(function(require){ default_number: '67', number: this.default_number, build_regex: function(number) { - return '^\\*'+number+'([0-9]*)$'; + return '^\\*' + number + '([0-9]*)$'; } }, 'park_and_retrieve': { @@ -571,7 +609,7 @@ define(function(require){ default_number: '3', number: this.default_number, build_regex: function(number) { - return '^\\*'+number+'([0-9]*)$'; + return '^\\*' + number + '([0-9]*)$'; } }, 'valet': { @@ -591,7 +629,7 @@ define(function(require){ default_number: '4', number: this.default_number, build_regex: function(number) { - return '*'+number; + return '*' + number; } }, 'retrieve': { @@ -608,7 +646,7 @@ define(function(require){ default_number: '5', number: this.default_number, build_regex: function(number) { - return '^\\*'+number+'([0-9]*)$'; + return '^\\*' + number + '([0-9]*)$'; } }, 'move': { @@ -626,7 +664,7 @@ define(function(require){ build_regex: function(number) { return number; } - }, + } /*'call_forward[action=on_busy_enable]': { name: 'Enable Call-Forward on Busy', icon: 'phone', @@ -850,7 +888,7 @@ define(function(require){ return '^\\*'+number+'([0-9]*)$'; } }*/ - }); + }; }, featureCodesEditParkingParkAndRetrieve: function(featureCode) { @@ -860,7 +898,7 @@ define(function(require){ var popup, formattedData = self.featureCodesFormatParkingData(data), template = $(self.getTemplate({ - name: 'featurecodes-parking-parkandretrieve', + name: 'parking-parkandretrieve', submodule: 'featurecodes', data: formattedData })); @@ -886,7 +924,10 @@ define(function(require){ dataToUpdate = self.featureCodesNormalizeData(data, formData); self.featureCodeUpdate(dataToUpdate.id, dataToUpdate, function() { - toastr.success(self.i18n.active().callflows.featureCodes.parkingParkAndRetrievePopup.successUpdate); + monster.ui.toast({ + type: 'success', + message: self.i18n.active().callflows.featureCodes.parkingParkAndRetrievePopup.successUpdate + }); popup.dialog('close'); }); } @@ -905,7 +946,7 @@ define(function(require){ var popup, formattedData = self.featureCodesFormatParkingData(data), template = $(self.getTemplate({ - name: 'featurecodes-parking-valet', + name: 'parking-valet', submodule: 'featurecodes', data: formattedData })); @@ -931,7 +972,10 @@ define(function(require){ dataToUpdate = self.featureCodesNormalizeData(data, formData); self.featureCodeUpdate(dataToUpdate.id, dataToUpdate, function() { - toastr.success(self.i18n.active().callflows.featureCodes.parkingValetPopup.successUpdate); + monster.ui.toast({ + type: 'success', + message: self.i18n.active().callflows.featureCodes.parkingValetPopup.successUpdate + }); popup.dialog('close'); }); } diff --git a/src/apps/callflows/submodules/featurecodes/views/parking-parkandretrieve.html b/src/apps/callflows/submodules/featurecodes/views/parking-parkandretrieve.html new file mode 100644 index 0000000..6abb8dd --- /dev/null +++ b/src/apps/callflows/submodules/featurecodes/views/parking-parkandretrieve.html @@ -0,0 +1,28 @@ +
    +
    + {{#monsterText 'info'}} + {{ i18n.callflows.featureCodes.infoSettings }} + {{/monsterText}} +
    + + +
    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    +
    + diff --git a/src/apps/callflows/submodules/featurecodes/views/parking-valet.html b/src/apps/callflows/submodules/featurecodes/views/parking-valet.html new file mode 100644 index 0000000..d4508e7 --- /dev/null +++ b/src/apps/callflows/submodules/featurecodes/views/parking-valet.html @@ -0,0 +1,28 @@ +
    +
    + {{#monsterText 'info'}} + {{ i18n.callflows.featureCodes.infoSettings }} + {{/monsterText}} +
    + +
    +
    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    +
    + diff --git a/src/apps/callflows/views/featurecodes-view.html b/src/apps/callflows/submodules/featurecodes/views/view.html similarity index 96% rename from src/apps/callflows/views/featurecodes-view.html rename to src/apps/callflows/submodules/featurecodes/views/view.html index be1507f..819aa5b 100644 --- a/src/apps/callflows/views/featurecodes-view.html +++ b/src/apps/callflows/submodules/featurecodes/views/view.html @@ -9,8 +9,8 @@
    {{#each categories}}
    -

    {{ @key }}

    - {{#each this}} +

    {{ category }}

    + {{#each items}}
    @@ -39,4 +39,4 @@
    -
    \ No newline at end of file +
    diff --git a/src/apps/callflows/submodules/groups/groups.css b/src/apps/callflows/submodules/groups/groups.css index bf11a97..c8cd811 100644 --- a/src/apps/callflows/submodules/groups/groups.css +++ b/src/apps/callflows/submodules/groups/groups.css @@ -1,3 +1,7 @@ +.callflows-port#ring_group_popup .shoutcast-div { + width: 350px; +} + .callflows-port#ring_group_popup .form_content .popup_field .media_action { color: #05addc; margin-left: 10px; diff --git a/src/apps/callflows/submodules/groups/groups.js b/src/apps/callflows/submodules/groups/groups.js index f166282..60577da 100644 --- a/src/apps/callflows/submodules/groups/groups.js +++ b/src/apps/callflows/submodules/groups/groups.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -8,12 +8,16 @@ define(function(require){ subscribe: { 'callflows.fetchActions': 'groupsDefineActions', - 'callflows.groups.edit': '_groupsEdit', + 'callflows.groups.edit': '_groupsEdit' }, - groupsRender: function(data, target, callbacks){ + groupsRender: function(data, target, callbacks) { var self = this, - groups_html = $(monster.template(self, 'groups-edit', data)), + groups_html = $(self.getTemplate({ + name: 'edit', + data: data, + submodule: 'groups' + })), groupForm = groups_html.find('#group-form'); monster.ui.validate(groupForm, { @@ -37,28 +41,27 @@ define(function(require){ var $this = $(this); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { $this.addClass('disabled'); - if(monster.ui.valid(groupForm)) { + if (monster.ui.valid(groupForm)) { var form_data = monster.ui.getFormData('group-form'); self.groupsCleanFormData(form_data, data.field_data); form_data.endpoints = {}; $('.rows .row:not(#row_no_data)', groups_html).each(function(k, v) { - form_data.endpoints[$(v).data('id')] = { - type: $(v).data('type'), - weight: k+1 - }; + form_data.endpoints[$(v).data('id')] = { + type: $(v).data('type'), + weight: k + 1 + }; }); delete data.data.resources; delete data.data.endpoints; self.groupsSave(form_data, data, callbacks.save_success); - } - else { + } else { $this.removeClass('disabled'); monster.ui.alert(self.i18n.active().callflows.groups.there_were_errors_on_the_form); } @@ -74,59 +77,58 @@ define(function(require){ }); var add_user = function() { - var $user = $('#select_user_id', groups_html); + var $user = $('#select_user_id', groups_html); - if($user.val() != 'empty_option_user') { - var user_id = $user.val(); + if ($user.val() !== 'empty_option_user') { + var user_id = $user.val(); - $.each(data.field_data.users, function(k, v) { - if(user_id === v.id) { - var user_data = { - endpoint_id: user_id, - endpoint_type: 'user', - endpoint_name: v.first_name + ' ' + v.last_name, - }; + $.each(data.field_data.users, function(k, v) { + if (user_id === v.id) { + var user_data = { + endpoint_id: user_id, + endpoint_type: 'user', + endpoint_name: v.first_name + ' ' + v.last_name + }; - data.data.endpoints.push(user_data); + data.data.endpoints.push(user_data); - data.data.endpoints.sort(function(a,b){ - return a.endpoint_name.toLowerCase() > b.endpoint_name.toLowerCase(); - }); + data.data.endpoints.sort(function(a, b) { + return a.endpoint_name.toLowerCase() > b.endpoint_name.toLowerCase(); + }); - self.groupsRenderEndpointList(data, groups_html); - $user.val('empty_option_user'); - } - }); - } - }, - add_device = function() { + self.groupsRenderEndpointList(data, groups_html); + $user.val('empty_option_user'); + } + }); + } + }, + add_device = function() { var $device = $('#select_device_id', groups_html); - if($device.val() != 'empty_option_device') { - var device_id = $device.val(); - - $.each(data.field_data.devices, function(k, v){ - if(device_id === v.id) { - var device_data = { - endpoint_id: device_id, - endpoint_type: 'device', - endpoint_name: v.name, - }; + if ($device.val() !== 'empty_option_device') { + var device_id = $device.val(); - data.data.endpoints.push(device_data); + $.each(data.field_data.devices, function(k, v) { + if (device_id === v.id) { + var device_data = { + endpoint_id: device_id, + endpoint_type: 'device', + endpoint_name: v.name + }; - data.data.endpoints.sort(function(a,b){ - return a.endpoint_name.toLowerCase() > b.endpoint_name.toLowerCase(); - }); + data.data.endpoints.push(device_data); - self.groupsRenderEndpointList(data, groups_html); + data.data.endpoints.sort(function(a, b) { + return a.endpoint_name.toLowerCase() > b.endpoint_name.toLowerCase(); + }); - $device.val('empty_option_device'); - } + self.groupsRenderEndpointList(data, groups_html); - }); + $device.val('empty_option_device'); + } + }); } - }; + }; $('#select_user_id', groups_html).change(function() { add_user(); @@ -138,19 +140,23 @@ define(function(require){ groups_html.find('#group-form').on('click', '.action_endpoint.delete', function() { var endpoint_id = $(this).data('id'); //removes it from the grid - $('#row_endpoint_'+endpoint_id, groups_html).remove(); + $('#row_endpoint_' + endpoint_id, groups_html).remove(); //re-add it to the dropdown - $('#option_endpoint_'+endpoint_id, groups_html).show(); + $('#option_endpoint_' + endpoint_id, groups_html).show(); //if grid empty, add no data line - if($('.rows .row', groups_html).size() === 0) { - $('.rows', groups_html).append(monster.template(self, 'groups-endpoint_row')); + if ($('.rows .row', groups_html).size() === 0) { + $('.rows', groups_html) + .append($(self.getTemplate({ + name: 'endpoint_row', + submodule: 'groups' + }))); } /* TODO For some reason splice doesn't work and I don't have time to make it better for now */ var new_list = []; $.each(data.data.endpoints, function(k, v) { - if(!(v.endpoint_id === endpoint_id)) { + if (!(v.endpoint_id === endpoint_id)) { new_list.push(v); } }); @@ -169,7 +175,7 @@ define(function(require){ self.groupsEdit(args.data, args.parent, args.target, args.callbacks, args.data_defaults); }, - groupsEdit: function(data, _parent, _target, _callbacks, data_defaults){ + groupsEdit: function(data, _parent, _target, _callbacks, data_defaults) { var self = this, parent = _parent || $('#groups-content'), target = _target || $('#groups-view', parent), @@ -189,62 +195,50 @@ define(function(require){ }; monster.parallel({ - 'device_list': function(callback) { - self.getAll({ - resource: 'device.list', - data: { - accountId: self.accountId - }, - success: function(data) { - defaults.field_data.devices = data.data; - callback(null, data) - } - }); - }, + device_list: function(callback) { + self.groupsRequestDeviceList({ + success: function(data) { + defaults.field_data.devices = data; + callback(null, data); + } + }); + }, + user_list: function(callback) { + self.groupsRequestUserList({ + success: function(data) { + defaults.field_data.users = data; + callback(null, {}); + } + }); + }, - 'user_list': function(callback) { - self.getAll({ - resource: 'user.list', + groups_get: function(callback) { + if (typeof data === 'object' && data.id) { + self.callApi({ + resource: 'group.get', data: { - accountId: self.accountId + accountId: self.accountId, + groupId: data.id }, success: function(data) { - defaults.field_data.users = data.data; - callback(null, data) + callback(null, data); } }); - }, - - 'groups_get': function(callback) { - if(typeof data === 'object' && data.id) { - self.callApi({ - resource: 'group.get', - data: { - accountId: self.accountId, - groupId: data.id - }, - success: function(data) { - callback(null, data) - } - }); - } - else { - callback(null, {}); - } - }, - }, - function(err, results) { - var render_data = defaults; - - if(typeof data === 'object' && data.id) { - render_data = $.extend(true, defaults, results.groups_get); + } else { + callback(null, {}); } + } + }, function(err, results) { + var render_data = defaults; - render_data = self.groupsFormatData(render_data); - - self.groupsRender(render_data, target, callbacks); + if (typeof data === 'object' && data.id) { + render_data = $.extend(true, defaults, results.groups_get); } - ); + + render_data = self.groupsFormatData(render_data); + + self.groupsRender(render_data, target, callbacks); + }); }, groupsRenderEndpointList: function(data, parent) { @@ -252,15 +246,23 @@ define(function(require){ $('.rows', parent).empty(); - if('endpoints' in data.data && data.data.endpoints.length > 0) { - $.each(data.data.endpoints, function(k, item){ - $('.rows', parent).append(monster.template(self, 'groups-endpoint_row', item)); - $('#option_endpoint_'+item.endpoint_id, parent).hide(); + if ('endpoints' in data.data && data.data.endpoints.length > 0) { + $.each(data.data.endpoints, function(k, item) { + $('.rows', parent) + .append($(self.getTemplate({ + name: 'endpoint_row', + data: item, + submodule: 'groups' + }))); + $('#option_endpoint_' + item.endpoint_id, parent).hide(); }); - } - else { - $('.rows', parent).empty() - .append(monster.template(self, 'groups-endpoint_row')); + } else { + $('.rows', parent) + .empty() + .append($(self.getTemplate({ + name: 'endpoint_row', + submodule: 'groups' + }))); } }, @@ -274,7 +276,7 @@ define(function(require){ list_endpoint = []; $.each(data.field_data.users, function(k, v) { - if(v.id in data.data.endpoints) { + if (v.id in data.data.endpoints) { endpoint_item = { endpoint_type: 'user', endpoint_id: v.id, @@ -287,7 +289,7 @@ define(function(require){ }); $.each(data.field_data.devices, function(k, v) { - if(v.id in data.data.endpoints) { + if (v.id in data.data.endpoints) { endpoint_item = { endpoint_type: 'device', endpoint_id: v.id, @@ -299,7 +301,7 @@ define(function(require){ } }); - list_endpoint.sort(function(a,b){ + list_endpoint.sort(function(a, b) { return a.endpoint_weight - b.endpoint_weight; }); @@ -330,7 +332,7 @@ define(function(require){ ], isUsable: 'true', weight: 20, - caption: function(node, caption_map) { + caption: function(node) { return node.getMetadata('name') || ''; }, edit: function(node, callback) { @@ -345,7 +347,9 @@ define(function(require){ resource: 'group.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -371,7 +375,7 @@ define(function(require){ ], isUsable: 'true', weight: 30, - caption: function(node, caption_map) { + caption: function(node) { return node.getMetadata('name') || ''; }, edit: function(node, callback) { @@ -401,12 +405,16 @@ define(function(require){ self.groupsGetEndpoints(function(formattedData) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-eavesdrop', { - fieldData: formattedData, + popup_html = $(self.getTemplate({ + name: 'eavesdrop', data: { - 'selectedId': node.getMetadata('device_id') || node.getMetadata('user_id') || '', - 'approvedId': node.getMetadata('approved_device_id') || node.getMetadata('approved_user_id') || node.getMetadata('approved_group_id') || '' - } + fieldData: formattedData, + data: { + 'selectedId': node.getMetadata('device_id') || node.getMetadata('user_id') || '', + 'approvedId': node.getMetadata('approved_device_id') || node.getMetadata('approved_user_id') || node.getMetadata('approved_group_id') || '' + } + }, + submodule: 'groups' })); monster.ui.tooltips(popup_html); @@ -470,12 +478,16 @@ define(function(require){ self.groupsGetEndpoints(function(formattedData) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-intercept', { - fieldData: formattedData, + popup_html = $(self.getTemplate({ + name: 'intercept', data: { - 'selectedId': node.getMetadata('device_id') || node.getMetadata('user_id') || '', - 'approvedId': node.getMetadata('approved_device_id') || node.getMetadata('approved_user_id') || node.getMetadata('approved_group_id') || '' - } + fieldData: formattedData, + data: { + 'selectedId': node.getMetadata('device_id') || node.getMetadata('user_id') || '', + 'approvedId': node.getMetadata('approved_device_id') || node.getMetadata('approved_user_id') || node.getMetadata('approved_group_id') || '' + } + }, + submodule: 'groups' })); monster.ui.tooltips(popup_html); @@ -567,12 +579,16 @@ define(function(require){ } }); - popup_html = $(monster.template(self, 'groups-ring_group_login_dialog', { - objects: { - type: 'callflow', - items: _.sortBy(_data, 'name'), - selected: node.getMetadata('callflow_id') || '' - } + popup_html = $(self.getTemplate({ + name: 'ring_group_login_dialog', + data: { + objects: { + type: 'callflow', + items: _.sortBy(_data, 'name'), + selected: node.getMetadata('callflow_id') || '' + } + }, + submodule: 'groups' })); $('#add', popup_html).click(function() { @@ -646,12 +662,16 @@ define(function(require){ } }); - popup_html = $(monster.template(self, 'groups-ring_group_logout_dialog', { - objects: { - type: 'callflow', - items: _.sortBy(_data, 'name'), - selected: node.getMetadata('callflow_id') || '' - } + popup_html = $(self.getTemplate({ + name: 'ring_group_logout_dialog', + data: { + objects: { + type: 'callflow', + items: _.sortBy(_data, 'name'), + selected: node.getMetadata('callflow_id') || '' + } + }, + submodule: 'groups' })); $('#add', popup_html).click(function() { @@ -687,13 +707,17 @@ define(function(require){ }); }, 'user': function(callback) { - self.groupsUserList(function(data) { - callback(null, data); + self.groupsRequestUserList({ + success: function(data) { + callback(null, data); + } }); }, 'device': function(callback) { - self.groupsDeviceList(function(data) { - callback(null, data); + self.groupsRequestDeviceList({ + success: function(data) { + callback(null, data); + } }); } }, function(err, results) { @@ -714,15 +738,25 @@ define(function(require){ groupsEditPageGroup: function(node, callback) { var self = this; - self.groupsDeviceList(function(data) { - var popup, popup_html, index, endpoints, + monster.waterfall([ + function(callback) { + self.groupsRequestDeviceList({ + success: function(data) { + callback(null, data); + } + }); + } + ], function(err, data) { + var popup, + popup_html, + endpoints = node.getMetadata('endpoints'), selected_endpoints = {}, unselected_endpoints = [], unselected_groups = [], unselected_devices = [], unselected_users = []; - if(endpoints = node.getMetadata('endpoints')) { + if (endpoints) { // We need to translate the endpoints to prevent nasty O(N^2) time complexities, // we also need to clone to prevent managing of objects $.each($.extend(true, {}, endpoints), function(i, obj) { @@ -733,12 +767,11 @@ define(function(require){ $.each(data, function(i, obj) { obj.endpoint_type = 'device'; - if(obj.id in selected_endpoints) { + if (obj.id in selected_endpoints) { selected_endpoints[obj.id].endpoint_type = 'device'; selected_endpoints[obj.id].owner_id = obj.owner_id; selected_endpoints[obj.id].name = obj.name; - } - else { + } else { unselected_devices.push(obj); } }); @@ -748,53 +781,83 @@ define(function(require){ self.groupsGroupList(function(_data) { $.each(_data, function(i, obj) { obj.endpoint_type = 'group'; - if(obj.id in selected_endpoints) { - selected_endpoints[obj.id].endpoint_type = 'group', + if (obj.id in selected_endpoints) { + selected_endpoints[obj.id].endpoint_type = 'group'; selected_endpoints[obj.id].name = obj.name; - } - else { + } else { unselected_groups.push(obj); } }); unselected_groups = _.sortBy(unselected_groups, 'name'); - self.groupsUserList(function(_data) { + monster.waterfall([ + function(callback) { + self.groupsRequestUserList({ + success: function(data) { + callback(null, data); + } + }); + } + ], function(err, _data) { $.each(_data, function(i, obj) { obj.name = obj.first_name + ' ' + obj.last_name; obj.endpoint_type = 'user'; - if(obj.id in selected_endpoints) { - selected_endpoints[obj.id].endpoint_type = 'user', + if (obj.id in selected_endpoints) { + selected_endpoints[obj.id].endpoint_type = 'user'; selected_endpoints[obj.id].name = obj.name; - } - else { + } else { unselected_users.push(obj); } }); unselected_users = _.sortBy(unselected_users, 'name'); - popup_html = $(monster.template(self, 'groups-page_group_dialog', { - form: { - name: node.getMetadata('name') || '', - audio: node.getMetadata('audio') || 'one-way' - } + popup_html = $(self.getTemplate({ + name: 'page_group_dialog', + data: { + form: { + name: node.getMetadata('name') || '', + audio: node.getMetadata('audio') || 'one-way' + } + }, + submodule: 'groups' })); $.each(unselected_groups, function() { - $('#groups_pane .connect.left', popup_html).append($(monster.template(self, 'groups-page_group_element', this))); + $('#groups_pane .connect.left', popup_html) + .append($(self.getTemplate({ + name: 'page_group_element', + data: this, + submodule: 'groups' + }))); }); $.each(unselected_devices, function() { - $('#devices_pane .connect.left', popup_html).append($(monster.template(self, 'groups-page_group_element', this))); + $('#devices_pane .connect.left', popup_html) + .append($(self.getTemplate({ + name: 'page_group_element', + data: this, + submodule: 'groups' + }))); }); $.each(unselected_users, function() { - $('#users_pane .connect.left', popup_html).append($(monster.template(self, 'groups-page_group_element', this))); + $('#users_pane .connect.left', popup_html) + .append($(self.getTemplate({ + name: 'page_group_element', + data: this, + submodule: 'groups' + }))); }); $.each(selected_endpoints, function() { //Check if user/device exists. - if(this.endpoint_type) { - $('.connect.right', popup_html).append($(monster.template(self, 'groups-page_group_element', this))); + if (this.endpoint_type) { + $('.connect.right', popup_html) + .append($(self.getTemplate({ + name: 'page_group_element', + data: this, + submodule: 'groups' + }))); } }); @@ -813,13 +876,11 @@ define(function(require){ var tab_id = $(this).attr('id'); - if(tab_id === 'users_tab_link') { + if (tab_id === 'users_tab_link') { $('#users_pane', popup_html).show(); - } - else if(tab_id === 'devices_tab_link') { + } else if (tab_id === 'devices_tab_link') { $('#devices_pane', popup_html).show(); - } - else if(tab_id === 'groups_tab_link') { + } else if (tab_id === 'groups_tab_link') { $('#groups_pane', popup_html).show(); } @@ -833,10 +894,9 @@ define(function(require){ $('#devices_pane .searchfield', popup_html).keyup(function() { $('#devices_pane .column.left li').each(function() { - if($('.item_name', $(this)).html().toLowerCase().indexOf($('#devices_pane .searchfield', popup_html).val().toLowerCase()) == -1) { + if ($('.item_name', $(this)).html().toLowerCase().indexOf($('#devices_pane .searchfield', popup_html).val().toLowerCase()) === -1) { $(this).hide(); - } - else { + } else { $(this).show(); } }); @@ -844,10 +904,9 @@ define(function(require){ $('#users_pane .searchfield', popup_html).keyup(function() { $('#users_pane .column.left li').each(function() { - if($('.item_name', $(this)).html().toLowerCase().indexOf($('#users_pane .searchfield', popup_html).val().toLowerCase()) == -1) { + if ($('.item_name', $(this)).html().toLowerCase().indexOf($('#users_pane .searchfield', popup_html).val().toLowerCase()) === -1) { $(this).hide(); - } - else { + } else { $(this).show(); } }); @@ -855,19 +914,17 @@ define(function(require){ $('#groups_pane .searchfield', popup_html).keyup(function() { $('#groups_pane .column.left li').each(function() { - if($('.item_name', $(this)).html().toLowerCase().indexOf($('#groups_pane .searchfield', popup_html).val().toLowerCase()) == -1) { + if ($('.item_name', $(this)).html().toLowerCase().indexOf($('#groups_pane .searchfield', popup_html).val().toLowerCase()) === -1) { $(this).hide(); - } - else { + } else { $(this).show(); } }); }); - if($.isEmptyObject(selected_endpoints)) { + if ($.isEmptyObject(selected_endpoints)) { $('.column.right .connect', popup_html).addClass('no_element'); - } - else { + } else { $('.column.right .connect', popup_html).removeClass('no_element'); } @@ -897,7 +954,6 @@ define(function(require){ node.setMetadata('endpoints', endpoints); node.setMetadata('name', name); node.setMetadata('audio', audio); - node.caption = name; popup.dialog('close'); @@ -906,7 +962,7 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().oldCallflows.page_group_title, beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -929,24 +985,23 @@ define(function(require){ list_li = [], confirm_text; - if(data.endpoint_type === 'device') { + if (data.endpoint_type === 'device') { confirm_text = self.i18n.active().oldCallflows.the_owner_of_this_device_is_already; $('.connect.right li', popup_html).each(function() { - if($(this).data('id') === data.owner_id) { + if ($(this).data('id') === data.owner_id) { list_li.push($(this)); } }); - } - else if(data.endpoint_type === 'user') { + } else if (data.endpoint_type === 'user') { confirm_text = self.i18n.active().oldCallflows.this_user_has_already_some_devices; $('.connect.right li', popup_html).each(function() { - if($(this).data('owner_id') === data.id) { + if ($(this).data('owner_id') === data.id) { list_li.push($(this)); } }); } - if(list_li.length > 0) { + if (list_li.length > 0) { monster.ui.confirm(confirm_text, function() { $.each(list_li, function() { @@ -959,7 +1014,7 @@ define(function(require){ ); } - if($(this).hasClass('right')) { + if ($(this).hasClass('right')) { $('.options', ui.item).show(); $('.actions', ui.item).show(); //$('.item_name', ui.item).addClass('right'); @@ -980,15 +1035,20 @@ define(function(require){ var $parent_li = li; var data = $parent_li.data(); data.name = jQuery.trim($('.item_name', $parent_li).html()); - $('#'+data.endpoint_type+'s_pane .connect.left', popup_html).append($(monster.template(self, 'groups-page_group_element', data))); + $('#' + data.endpoint_type + 's_pane .connect.left', popup_html) + .append($(self.getTemplate({ + name: 'page_group_element', + data: data, + submodule: 'groups' + }))); $parent_li.remove(); - if($('.connect.right li', popup_html).size() == 0) { + if ($('.connect.right li', popup_html).size() === 0) { $('.column.right .connect', popup).addClass('no_element'); } - if(data.name.toLowerCase().indexOf($('#'+data.endpoint_type+'s_pane .searchfield', popup_html).val().toLowerCase()) == -1) { - $('#'+data.id, popup_html).hide(); + if (data.name.toLowerCase().indexOf($('#' + data.endpoint_type + 's_pane .searchfield', popup_html).val().toLowerCase()) === -1) { + $('#' + data.id, popup_html).hide(); } }; }); @@ -1001,15 +1061,27 @@ define(function(require){ default_timeout = '20', default_delay = '0'; - self.groupsDeviceList(function(data) { - var popup, popup_html, index, endpoints, + monster.waterfall([ + function(callback) { + self.groupsRequestDeviceList({ + success: function(data) { + console.log(data); + callback(null, data); + } + }); + } + ], function(err, data) { + console.log(data); + var popup, + popup_html, + endpoints = node.getMetadata('endpoints'), selected_endpoints = {}, unselected_endpoints = [], unselected_groups = [], unselected_devices = [], unselected_users = []; - if(endpoints = node.getMetadata('endpoints')) { + if (endpoints) { // We need to translate the endpoints to prevent nasty O(N^2) time complexities, // we also need to clone to prevent managing of objects $.each($.extend(true, {}, endpoints), function(i, obj) { @@ -1020,12 +1092,11 @@ define(function(require){ $.each(data, function(i, obj) { obj.endpoint_type = 'device'; - if(obj.id in selected_endpoints) { + if (obj.id in selected_endpoints) { selected_endpoints[obj.id].endpoint_type = 'device'; selected_endpoints[obj.id].owner_id = obj.owner_id; selected_endpoints[obj.id].name = obj.name; - } - else { + } else { obj.delay = default_delay; obj.timeout = default_timeout; unselected_devices.push(obj); @@ -1037,11 +1108,10 @@ define(function(require){ self.groupsGroupList(function(_data) { $.each(_data, function(i, obj) { obj.endpoint_type = 'group'; - if(obj.id in selected_endpoints) { - selected_endpoints[obj.id].endpoint_type = 'group', + if (obj.id in selected_endpoints) { + selected_endpoints[obj.id].endpoint_type = 'group'; selected_endpoints[obj.id].name = obj.name; - } - else { + } else { obj.delay = default_delay; obj.timeout = default_timeout; unselected_groups.push(obj); @@ -1050,15 +1120,22 @@ define(function(require){ unselected_groups = _.sortBy(unselected_groups, 'name'); - self.groupsUserList(function(_data, status) { + monster.waterfall([ + function(callback) { + self.groupsRequestUserList({ + success: function(data) { + callback(null, data); + } + }); + } + ], function(err, _data) { $.each(_data, function(i, obj) { obj.name = obj.first_name + ' ' + obj.last_name; obj.endpoint_type = 'user'; - if(obj.id in selected_endpoints) { - selected_endpoints[obj.id].endpoint_type = 'user', + if (obj.id in selected_endpoints) { + selected_endpoints[obj.id].endpoint_type = 'user'; selected_endpoints[obj.id].name = obj.name; - } - else { + } else { obj.delay = default_delay; obj.timeout = default_timeout; unselected_users.push(obj); @@ -1074,63 +1151,87 @@ define(function(require){ mediaId = node.getMetadata('ringback') || 'default', isShoutcast = mediaId.indexOf('://') >= 0 && mediaId !== 'silence_stream://300000'; - popup_html = $(monster.template(self, 'groups-ring_group_dialog', { - form: { - name: node.getMetadata('name') || '', - strategy: { - items: [ - { - id: 'simultaneous', - name: self.i18n.active().oldCallflows.at_the_same_time - }, - { - id: 'single', - name: self.i18n.active().oldCallflows.in_order - } - ], - selected: node.getMetadata('strategy') || 'simultaneous' - }, - timeout: node.getMetadata('timeout') || '30', - repeats: node.getMetadata('repeats') || 1, - ringback: { - items: $.merge([ - { - id: 'default', - name: self.i18n.active().oldCallflows.default, - class: 'uneditable' - }, - { - id: 'silence_stream://300000', - name: self.i18n.active().oldCallflows.silence, - class: 'uneditable' - }, - { - id: 'shoutcast_url', - name: self.i18n.active().callflows.media.shoutcastURL, - class: 'uneditable' - } - ], media_array), - selected: isShoutcast ? 'shoutcast_url' : mediaId, - shoutcastValue: mediaId + popup_html = $(self.getTemplate({ + name: 'ring_group_dialog', + data: { + form: { + name: node.getMetadata('name') || '', + strategy: { + items: [ + { + id: 'simultaneous', + name: self.i18n.active().oldCallflows.at_the_same_time + }, + { + id: 'single', + name: self.i18n.active().oldCallflows.in_order + } + ], + selected: node.getMetadata('strategy') || 'simultaneous' + }, + timeout: node.getMetadata('timeout') || '30', + repeats: node.getMetadata('repeats') || 1, + ringback: { + items: $.merge([ + { + id: 'default', + name: self.i18n.active().oldCallflows.default, + class: 'uneditable' + }, + { + id: 'silence_stream://300000', + name: self.i18n.active().oldCallflows.silence, + class: 'uneditable' + }, + { + id: 'shoutcast_url', + name: self.i18n.active().callflows.media.shoutcastURL, + class: 'uneditable' + } + ], media_array), + selected: isShoutcast ? 'shoutcast_url' : mediaId, + shoutcastValue: mediaId + } } - } + }, + submodule: 'groups' })); $.each(unselected_groups, function() { - $('#groups_pane .connect.left', popup_html).append($(monster.template(self, 'groups-ring_group_element', this))); + $('#groups_pane .connect.left', popup_html) + .append($(self.getTemplate({ + name: 'ring_group_element', + data: this, + submodule: 'groups' + }))); }); $.each(unselected_devices, function() { - $('#devices_pane .connect.left', popup_html).append($(monster.template(self, 'groups-ring_group_element', this))); + $('#devices_pane .connect.left', popup_html) + .append($(self.getTemplate({ + name: 'ring_group_element', + data: this, + submodule: 'groups' + }))); }); $.each(unselected_users, function() { - $('#users_pane .connect.left', popup_html).append($(monster.template(self, 'groups-ring_group_element', this))); + $('#users_pane .connect.left', popup_html) + .append($(self.getTemplate({ + name: 'ring_group_element', + data: this, + submodule: 'groups' + }))); }); $.each(selected_endpoints, function() { //Check if user/device exists. - if(this.endpoint_type) { - $('.connect.right', popup_html).append($(monster.template(self, 'groups-ring_group_element', this))); + if (this.endpoint_type) { + $('.connect.right', popup_html) + .append($(self.getTemplate({ + name: 'ring_group_element', + data: this, + submodule: 'groups' + }))); } }); @@ -1145,7 +1246,6 @@ define(function(require){ popup_html.find('.shoutcast-div').toggleClass('hidden', !isShoutcast).find('input').val(''); if ($(this).find('option:selected').hasClass('uneditable')) { - $('.media_action[data-action="edit"]', popup_html).hide(); } else { $('.media_action[data-action="edit"]', popup_html).show(); @@ -1182,13 +1282,11 @@ define(function(require){ var tab_id = $(this).attr('id'); - if(tab_id === 'users_tab_link') { + if (tab_id === 'users_tab_link') { $('#users_pane', popup_html).show(); - } - else if(tab_id === 'devices_tab_link') { + } else if (tab_id === 'devices_tab_link') { $('#devices_pane', popup_html).show(); - } - else if(tab_id === 'groups_tab_link') { + } else if (tab_id === 'groups_tab_link') { $('#groups_pane', popup_html).show(); } @@ -1202,10 +1300,9 @@ define(function(require){ $('#devices_pane .searchfield', popup_html).keyup(function() { $('#devices_pane .column.left li').each(function() { - if($('.item_name', $(this)).html().toLowerCase().indexOf($('#devices_pane .searchfield', popup_html).val().toLowerCase()) == -1) { + if ($('.item_name', $(this)).html().toLowerCase().indexOf($('#devices_pane .searchfield', popup_html).val().toLowerCase()) === -1) { $(this).hide(); - } - else { + } else { $(this).show(); } }); @@ -1213,10 +1310,9 @@ define(function(require){ $('#users_pane .searchfield', popup_html).keyup(function() { $('#users_pane .column.left li').each(function() { - if($('.item_name', $(this)).html().toLowerCase().indexOf($('#users_pane .searchfield', popup_html).val().toLowerCase()) == -1) { + if ($('.item_name', $(this)).html().toLowerCase().indexOf($('#users_pane .searchfield', popup_html).val().toLowerCase()) === -1) { $(this).hide(); - } - else { + } else { $(this).show(); } }); @@ -1224,19 +1320,17 @@ define(function(require){ $('#groups_pane .searchfield', popup_html).keyup(function() { $('#groups_pane .column.left li').each(function() { - if($('.item_name', $(this)).html().toLowerCase().indexOf($('#groups_pane .searchfield', popup_html).val().toLowerCase()) == -1) { + if ($('.item_name', $(this)).html().toLowerCase().indexOf($('#groups_pane .searchfield', popup_html).val().toLowerCase()) === -1) { $(this).hide(); - } - else { + } else { $(this).show(); } }); }); - if($.isEmptyObject(selected_endpoints)) { + if ($.isEmptyObject(selected_endpoints)) { $('.column.right .connect', popup_html).addClass('no_element'); - } - else { + } else { $('.column.right .connect', popup_html).removeClass('no_element'); } @@ -1265,23 +1359,22 @@ define(function(require){ endpoints = []; - if(strategy === 'simultaneous') { + if (strategy === 'simultaneous') { var computeTimeout = function(delay, local_timeout, global_timeout) { var duration = delay + local_timeout; - if(duration > global_timeout) { + if (duration > global_timeout) { global_timeout = duration; } return global_timeout; - } - } - else { + }; + } else { var computeTimeout = function(delay, local_timeout, global_timeout) { global_timeout += delay + local_timeout; return global_timeout; - } + }; } $('.right .connect li', popup_html).each(function() { @@ -1300,7 +1393,7 @@ define(function(require){ node.setMetadata('strategy', strategy); node.setMetadata('timeout', global_timeout); node.setMetadata('repeats', repeats); - if(ringback === 'default') { + if (ringback === 'default') { node.deleteMetadata('ringback', ringback); } else { node.setMetadata('ringback', ringback); @@ -1316,7 +1409,7 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().oldCallflows.ring_group, beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -1339,24 +1432,23 @@ define(function(require){ list_li = [], confirm_text; - if(data.endpoint_type === 'device') { + if (data.endpoint_type === 'device') { confirm_text = self.i18n.active().oldCallflows.the_owner_of_this_device_is_already; $('.connect.right li', popup_html).each(function() { - if($(this).data('id') === data.owner_id) { + if ($(this).data('id') === data.owner_id) { list_li.push($(this)); } }); - } - else if(data.endpoint_type === 'user') { + } else if (data.endpoint_type === 'user') { confirm_text = self.i18n.active().oldCallflows.this_user_has_already_some_devices; $('.connect.right li', popup_html).each(function() { - if($(this).data('owner_id') === data.id) { + if ($(this).data('owner_id') === data.id) { list_li.push($(this)); } }); } - if(list_li.length > 0) { + if (list_li.length > 0) { monster.ui.confirm(confirm_text, function() { $.each(list_li, function() { @@ -1369,7 +1461,7 @@ define(function(require){ ); } - if($(this).hasClass('right')) { + if ($(this).hasClass('right')) { $('.options', ui.item).show(); $('.actions', ui.item).show(); //$('.item_name', ui.item).addClass('right'); @@ -1385,7 +1477,7 @@ define(function(require){ $('.pane_content', popup_html).hide(); $('#users_pane', popup_html).show(); - if($('#ringback option:selected').hasClass('uneditable')) { + if ($('#ringback option:selected').hasClass('uneditable')) { $('.media_action[data-action="edit"]', popup_html).hide(); } else { $('.media_action[data-action="edit"]', popup_html).show(); @@ -1395,15 +1487,20 @@ define(function(require){ var $parent_li = li; var data = $parent_li.data(); data.name = jQuery.trim($('.item_name', $parent_li).html()); - $('#'+data.endpoint_type+'s_pane .connect.left', popup_html).append($(monster.template(self, 'groups-ring_group_element', data))); + $('#' + data.endpoint_type + 's_pane .connect.left', popup_html) + .append($(self.getTemplate({ + name: 'ring_group_element', + data: data, + submodule: 'groups' + }))); $parent_li.remove(); - if($('.connect.right li', popup_html).size() == 0) { + if ($('.connect.right li', popup_html).size() === 0) { $('.column.right .connect', popup).addClass('no_element'); } - if(data.name.toLowerCase().indexOf($('#'+data.endpoint_type+'s_pane .searchfield', popup_html).val().toLowerCase()) == -1) { - $('#'+data.id, popup_html).hide(); + if (data.name.toLowerCase().indexOf($('#' + data.endpoint_type + 's_pane .searchfield', popup_html).val().toLowerCase()) === -1) { + $('#' + data.id, popup_html).hide(); } }; }); @@ -1412,21 +1509,6 @@ define(function(require){ }); }, - groupsDeviceList: function(callback) { - var self = this; - - self.callApi({ - resource: 'device.list', - data: { - accountId: self.accountId, - filters: { paginate:false } - }, - success: function(data, status) { - callback && callback(data.data); - } - }); - }, - groupsGroupList: function(callback) { var self = this; @@ -1434,22 +1516,9 @@ define(function(require){ resource: 'group.list', data: { accountId: self.accountId, - filters: { paginate:false } - }, - success: function(data, status) { - callback && callback(data.data); - } - }); - }, - - groupsUserList: function(callback) { - var self = this; - - self.callApi({ - resource: 'user.list', - data: { - accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -1464,7 +1533,9 @@ define(function(require){ resource: 'media.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -1493,8 +1564,7 @@ define(function(require){ success(_data.data, status, 'update'); } }); - } - else { + } else { self.callApi({ resource: 'group.create', data: { @@ -1511,7 +1581,7 @@ define(function(require){ groupsDelete: function(data, callback) { var self = this; - if(typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { self.callApi({ resource: 'group.delete', data: { @@ -1523,6 +1593,46 @@ define(function(require){ } }); } + }, + + groupsRequestUserList: function(args) { + var self = this; + + self.callApi({ + resource: 'user.list', + data: _.merge({ + accountId: self.accountId, + filters: { + paginate: false + } + }, args.data), + success: function(data, status) { + args.hasOwnProperty('success') && args.success(data.data); + }, + error: function(parsedError) { + args.hasOwnProperty('error') && args.error(parsedError); + } + }); + }, + + groupsRequestDeviceList: function(args) { + var self = this; + + self.callApi({ + resource: 'device.list', + data: _.merge({ + accountId: self.accountId, + filters: { + paginate: false + } + }, args.data), + success: function(data, status) { + args.hasOwnProperty('success') && args.success(data.data); + }, + error: function(parsedError) { + args.hasOwnProperty('error') && args.error(parsedError); + } + }); } }; diff --git a/src/apps/callflows/views/misc-eavesdrop.html b/src/apps/callflows/submodules/groups/views/eavesdrop.html similarity index 100% rename from src/apps/callflows/views/misc-eavesdrop.html rename to src/apps/callflows/submodules/groups/views/eavesdrop.html diff --git a/src/apps/callflows/views/groups-edit.html b/src/apps/callflows/submodules/groups/views/edit.html similarity index 99% rename from src/apps/callflows/views/groups-edit.html rename to src/apps/callflows/submodules/groups/views/edit.html index 9f11880..ecbe894 100644 --- a/src/apps/callflows/views/groups-edit.html +++ b/src/apps/callflows/submodules/groups/views/edit.html @@ -26,8 +26,17 @@
    -
    +
    +
    +
    +
    {{ @root.i18n.callflows.groups.endpoints }}
    +
    {{ @root.i18n.callflows.groups.remove }}
    +
    +
    +
    +
    +
    @@ -59,15 +68,6 @@
    - -
    -
    -
    {{ @root.i18n.callflows.groups.endpoints }}
    -
    {{ @root.i18n.callflows.groups.remove }}
    -
    -
    -
    -
    diff --git a/src/apps/callflows/views/groups-endpoint_row.html b/src/apps/callflows/submodules/groups/views/endpoint_row.html similarity index 68% rename from src/apps/callflows/views/groups-endpoint_row.html rename to src/apps/callflows/submodules/groups/views/endpoint_row.html index deb15e5..bada067 100644 --- a/src/apps/callflows/views/groups-endpoint_row.html +++ b/src/apps/callflows/submodules/groups/views/endpoint_row.html @@ -1,7 +1,14 @@
    {{#if endpoint_id}}
    -
    {{#compare endpoint_type "===" "user"}}{{else}}{{/compare}} {{endpoint_name}}
    +
    + {{#compare endpoint_type "===" "user"}} + + {{else}} + + {{/compare}} + {{endpoint_name}} +
    diff --git a/src/apps/callflows/views/groups-ring_group_element.html b/src/apps/callflows/submodules/groups/views/ring_group_element.html similarity index 100% rename from src/apps/callflows/views/groups-ring_group_element.html rename to src/apps/callflows/submodules/groups/views/ring_group_element.html diff --git a/src/apps/callflows/views/groups-ring_group_login_dialog.html b/src/apps/callflows/submodules/groups/views/ring_group_login_dialog.html similarity index 100% rename from src/apps/callflows/views/groups-ring_group_login_dialog.html rename to src/apps/callflows/submodules/groups/views/ring_group_login_dialog.html diff --git a/src/apps/callflows/views/groups-ring_group_logout_dialog.html b/src/apps/callflows/submodules/groups/views/ring_group_logout_dialog.html similarity index 100% rename from src/apps/callflows/views/groups-ring_group_logout_dialog.html rename to src/apps/callflows/submodules/groups/views/ring_group_logout_dialog.html diff --git a/src/apps/callflows/submodules/media/media.js b/src/apps/callflows/submodules/media/media.js index c4d597a..a8c0863 100644 --- a/src/apps/callflows/submodules/media/media.js +++ b/src/apps/callflows/submodules/media/media.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -14,8 +14,15 @@ define(function(require){ mediaRender: function(data, target, callbacks) { var self = this, - media_html = $(monster.template(self, 'media-edit', data)), - mediaForm = media_html.find('#media-form'); + media_html = $(self.getTemplate({ + name: 'edit', + data: _.merge({ + showMediaUploadDisclosure: monster.config.whitelabel.showMediaUploadDisclosure + }, data), + submodule: 'media' + })), + mediaForm = media_html.find('#media-form'), + file; monster.ui.validate(mediaForm, { rules: { @@ -35,7 +42,7 @@ define(function(require){ self.winkstartTabs(media_html); - if(data.data.id) { + if (data.data.id) { $('#upload_div', media_html).hide(); } @@ -47,15 +54,15 @@ define(function(require){ $('#download_link', media_html).click(function(ev) { ev.preventDefault(); - window.location.href = self.apiUrl + (self.apiUrl.substring(self.apiUrl.length-1) != '/' ? '/' : '') + 'accounts/' + - self.accountId + '/media/' + - data.data.id + '/raw?auth_token=' + self.getAuthToken(); + window.location.href = self.apiUrl + (self.apiUrl.substring(self.apiUrl.length - 1) !== '/' ? '/' : '') + + 'accounts/' + self.accountId + '/media/' + data.data.id + + '/raw?auth_token=' + self.getAuthToken(); }); - $('#file', media_html).bind('change', function(evt){ + $('#file', media_html).bind('change', function(evt) { var files = evt.target.files; - if(files.length > 0) { + if (files.length > 0) { var reader = new FileReader(); file = 'updating'; @@ -63,7 +70,7 @@ define(function(require){ var data = evt.target.result; file = data; - } + }; reader.readAsDataURL(files[0]); } @@ -72,15 +79,12 @@ define(function(require){ function changeType($select) { var type = $select.val(); - switch(type) { - case 'tts': - $('.tts', media_html).show(); - $('.file', media_html).hide(); - break; - case 'upload': - $('.tts', media_html).hide(); - $('.file', media_html).show(); - break; + if (type === 'tts') { + $('.tts', media_html).show(); + $('.file', media_html).hide(); + } else if (type === 'upload') { + $('.tts', media_html).hide(); + $('.file', media_html).show(); } } @@ -94,31 +98,30 @@ define(function(require){ ev.preventDefault(); var $this = $(this); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { $this.addClass('disabled'); - if(monster.ui.valid(mediaForm)) { + if (monster.ui.valid(mediaForm)) { var form_data = monster.ui.getFormData('media-form'); form_data = self.mediaCleanFormData(form_data); self.mediaSave(form_data, data, function(_data, status) { - if(!form_data.tts) { - if($('#upload_div', media_html).is(':visible') && $('#file').val() != '') { - if(file === 'updating') { + if (!form_data.tts) { + if ($('#upload_div', media_html).is(':visible') && $('#file').val() !== '') { + if (file === 'updating') { monster.ui.alert(self.i18n.active().callflows.media.the_file_you_want_to_apply); $this.removeClass('disabled'); - } - else { + } else { self.mediaUpload(file, _data.id, function() { - if(typeof callbacks.save_success == 'function') { + if (typeof callbacks.save_success === 'function') { callbacks.save_success(_data, status); } }, function() { - if(data && data.data && data.data.id) { + if (data && data.data && data.data.id) { self.mediaSave({}, data, function() { - if(typeof callbacks.save_success == 'function') { + if (typeof callbacks.save_success === 'function') { callbacks.save_success(_data, status); } }); @@ -128,19 +131,18 @@ define(function(require){ $this.removeClass('disabled'); - if(typeof callbacks.save_error == 'function') { + if (typeof callbacks.save_error === 'function') { callbacks.save_error(_data, status); } }); } - } - else { - if(typeof callbacks.save_success == 'function') { + } else { + if (typeof callbacks.save_success === 'function') { callbacks.save_success(_data, status); } } } else { - if(typeof callbacks.save_success == 'function') { + if (typeof callbacks.save_success === 'function') { callbacks.save_success(_data, status); } } @@ -168,12 +170,12 @@ define(function(require){ mediaCleanFormData: function(form_data) { form_data.description = form_data.upload_media; - if(form_data.description == '') { + if (form_data.description === '') { delete form_data.description; } - if(form_data.media_source == 'tts') { - form_data.description = "tts file"; + if (form_data.media_source === 'tts') { + form_data.description = 'tts file'; } else { delete form_data.tts; } @@ -189,7 +191,7 @@ define(function(require){ self.mediaEdit(args.data, args.parent, args.target, args.callbacks, args.data_defaults); }, - mediaEdit: function(data, _parent, _target, _callbacks, data_defaults){ + mediaEdit: function(data, _parent, _target, _callbacks, data_defaults) { var self = this, parent = _parent || $('#media-content'), target = _target || $('#media-view', parent), @@ -207,21 +209,20 @@ define(function(require){ }, data_defaults || {}) }; - if(typeof data == 'object' && data.id) { + if (typeof data === 'object' && data.id) { self.mediaGet(data.id, function(mediaData) { self.mediaFormatData(mediaData); self.mediaRender($.extend(true, defaults, { data: mediaData }), target, callbacks); - if(typeof callbacks.after_render == 'function') { + if (typeof callbacks.after_render === 'function') { callbacks.after_render(); } }); - } - else { + } else { self.mediaRender(defaults, target, callbacks); - if(typeof callbacks.after_render == 'function') { + if (typeof callbacks.after_render === 'function') { callbacks.after_render(); } } @@ -231,16 +232,15 @@ define(function(require){ var self = this, normalized_data = self.mediaNormalizeData($.extend(true, {}, data.data, form_data)); - if(typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { self.mediaUpdate(normalized_data, function(_data, status) { - if(typeof success == 'function') { + if (typeof success === 'function') { success(_data, status, 'update'); } }); - } - else { + } else { self.mediaCreate(normalized_data, function(_data, status) { - if(typeof success == 'function') { + if (typeof success === 'function') { success(_data, status, 'create'); } }); @@ -250,11 +250,11 @@ define(function(require){ mediaNormalizeData: function(form_data) { delete form_data.upload_media; - if('field_data' in form_data) { + if ('field_data' in form_data) { delete form_data.field_data; } - if(form_data.media_source == 'upload') { + if (form_data.media_source === 'upload') { delete form_data.tts; } @@ -266,14 +266,13 @@ define(function(require){ * And as we're using the same template for both behaviors, we need the same kind of data. * TODO: delete once this bug is fixed! */ - if(data.streamable == 'false') { - data.streamable = false; - } - else if(data.streamable == 'true') { + if (data.streamable === 'false') { + data.streamable = false; + } else if (data.streamable === 'true') { data.streamable = true; } - if(data.description != undefined && data.description.substr(0,12) == 'C:\\fakepath\\') { + if (data.description !== undefined && data.description.substr(0, 12) === 'C:\\fakepath\\') { data.description = data.description.substr(12); } @@ -292,14 +291,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -339,7 +338,7 @@ define(function(require){ isShoutcast = id && id.indexOf('://') >= 0 && !isSilence, returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } else if (isShoutcast) { returned_value = id; @@ -358,21 +357,24 @@ define(function(require){ isSilence = !mediaId || (mediaId && mediaId === 'silence_stream://300000'), // because silence is the default choice, we test for !mediaId isShoutcast = mediaId.indexOf('://') >= 0 && mediaId !== 'silence_stream://300000'; - popup_html = $(monster.template(self, 'media-callflowEdit', { - items: medias, - selected: isShoutcast ? 'shoutcast' : mediaId, - isShoutcast: isShoutcast, - shoutcastValue: mediaId, - isEditable: !isShoutcast && !isSilence + popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { + items: medias, + selected: isShoutcast ? 'shoutcast' : mediaId, + isShoutcast: isShoutcast, + shoutcastValue: mediaId, + isEditable: !isShoutcast && !isSilence + }, + submodule: 'media' })); - if($('#media_selector option:selected', popup_html).val() == undefined) { + if ($('#media_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#media_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#media_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -414,7 +416,7 @@ define(function(require){ title: self.i18n.active().callflows.media.media, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -426,7 +428,9 @@ define(function(require){ resource: 'media.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -445,7 +449,9 @@ define(function(require){ resource: 'media.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { var mediaList = _.sortBy(data.data, function(item) { return item.name.toLowerCase(); }); diff --git a/src/apps/callflows/views/media-callflowEdit.html b/src/apps/callflows/submodules/media/views/callflowEdit.html similarity index 90% rename from src/apps/callflows/views/media-callflowEdit.html rename to src/apps/callflows/submodules/media/views/callflowEdit.html index 98f30a9..ba35182 100644 --- a/src/apps/callflows/views/media-callflowEdit.html +++ b/src/apps/callflows/submodules/media/views/callflowEdit.html @@ -25,6 +25,11 @@
    +
    + {{#monsterText 'warning'}} + {{ i18n.callflows.media.shoutcastURLWarning }} + {{/monsterText}} +
    diff --git a/src/apps/callflows/views/media-edit.html b/src/apps/callflows/submodules/media/views/edit.html similarity index 94% rename from src/apps/callflows/views/media-edit.html rename to src/apps/callflows/submodules/media/views/edit.html index e0839e2..4ac1cf7 100644 --- a/src/apps/callflows/views/media-edit.html +++ b/src/apps/callflows/submodules/media/views/edit.html @@ -55,7 +55,23 @@ + {{#if showMediaUploadDisclosure}} +
    +
    + {{#monsterText}} + {{i18n.mediaUploadDisclosure.text}} + {{/monsterText}} +
    + {{/if}} {{else}} + {{#if showMediaUploadDisclosure}} +
    +
    + {{#monsterText}} + {{i18n.mediaUploadDisclosure.text}} + {{/monsterText}} +
    + {{/if}} {{/if}} @@ -158,4 +174,4 @@ - \ No newline at end of file + diff --git a/src/apps/callflows/submodules/menu/menu.js b/src/apps/callflows/submodules/menu/menu.js index 7a0c961..26e290c 100644 --- a/src/apps/callflows/submodules/menu/menu.js +++ b/src/apps/callflows/submodules/menu/menu.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -45,58 +45,57 @@ define(function(require){ }; monster.parallel({ - media_list: function(callback) { - self.callApi({ - resource: 'media.list', - data: { - accountId: self.accountId, - filters: { paginate:false } - }, - success: function(mediaList, status) { - _.each(mediaList.data, function(media) { - if(media.media_source) { - media.name = '['+media.media_source.substring(0,3).toUpperCase()+'] ' + media.name; - } - }); - - mediaList.data.unshift({ - id: '', - name: self.i18n.active().callflows.menu.not_set - }); - - defaults.field_data.media = mediaList.data; - - callback(null, mediaList); + media_list: function(callback) { + self.callApi({ + resource: 'media.list', + data: { + accountId: self.accountId, + filters: { + paginate: false } - }); - }, - menu_get: function(callback) { - if(typeof data == 'object' && data.id) { - self.menuGet(data.id, function(menuData, status) { - self.menuformatData(menuData); + }, + success: function(mediaList, status) { + _.each(mediaList.data, function(media) { + if (media.media_source) { + media.name = '[' + media.media_source.substring(0, 3).toUpperCase() + '] ' + media.name; + } + }); - callback(null, { data: menuData }); + mediaList.data.unshift({ + id: '', + name: self.i18n.active().callflows.menu.not_set }); + + defaults.field_data.media = mediaList.data; + + callback(null, mediaList); } - else { - callback(null, {}); - } - } + }); }, - function(err, results) { - var render_data = defaults; + menu_get: function(callback) { + if (typeof data === 'object' && data.id) { + self.menuGet(data.id, function(menuData, status) { + self.menuformatData(menuData); - if(typeof data === 'object' && data.id) { - render_data = $.extend(true, defaults, results.menu_get) + callback(null, { data: menuData }); + }); + } else { + callback(null, {}); } + } + }, function(err, results) { + var render_data = defaults; - self.menuRender(render_data, target, callbacks); + if (typeof data === 'object' && data.id) { + render_data = $.extend(true, defaults, results.menu_get); + } - if(typeof callbacks.after_render == 'function') { - callbacks.after_render(); - } + self.menuRender(render_data, target, callbacks); + + if (typeof callbacks.after_render === 'function') { + callbacks.after_render(); } - ); + }); }, menuPopupEdit: function(data, callback, data_defaults) { @@ -108,14 +107,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -127,9 +126,13 @@ define(function(require){ }, data_defaults); }, - menuRender: function(data, target, callbacks){ + menuRender: function(data, target, callbacks) { var self = this, - menu_html = $(monster.template(self, 'menu-edit', data)), + menu_html = $(self.getTemplate({ + name: 'edit', + data: data, + submodule: 'menu' + })), menuForm = menu_html.find('#menu-form'); monster.ui.validate(menuForm, { @@ -165,7 +168,7 @@ define(function(require){ self.winkstartTabs(menu_html); - if(!$('#media_greeting', menu_html).val()) { + if (!$('#media_greeting', menu_html).val()) { $('#edit_link_media', menu_html).hide(); } @@ -174,7 +177,7 @@ define(function(require){ }); $('.inline_action_media', menu_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? { id: $('#media_greeting', menu_html).val() } : {}, + var _data = ($(this).data('action') === 'edit') ? { id: $('#media_greeting', menu_html).val() } : {}, _id = _data.id; ev.preventDefault(); @@ -185,20 +188,18 @@ define(function(require){ /* Create */ dataMedia.name = '[UPL] ' + dataMedia.name; - if(!_id) { - $('#media_greeting', menu_html).append('') + if (!_id) { + $('#media_greeting', menu_html).append(''); $('#media_greeting', menu_html).val(dataMedia.id); $('#edit_link_media', menu_html).show(); - } - else { + } else { /* Update */ - if(dataMedia.hasOwnProperty('id')) { - $('#media_greeting #'+dataMedia.id, menu_html).text(dataMedia.name); - } + if (dataMedia.hasOwnProperty('id')) { + $('#media_greeting #' + dataMedia.id, menu_html).text(dataMedia.name); /* Delete */ - else { - $('#media_greeting #'+_id, menu_html).remove(); + } else { + $('#media_greeting #' + _id, menu_html).remove(); $('#edit_link_media', menu_html).hide(); } } @@ -211,15 +212,15 @@ define(function(require){ var $this = $(this); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { $this.addClass('disabled'); - if(monster.ui.valid(menuForm)) { + if (monster.ui.valid(menuForm)) { var form_data = monster.ui.getFormData('menu-form'); self.menuCleanFormData(form_data); - if('field_data' in data) { + if ('field_data' in data) { delete data.field_data; } @@ -250,7 +251,7 @@ define(function(require){ var self = this, normalized_data = self.menuNormalizeData($.extend(true, {}, data.data, form_data)); - if (typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { self.menuUpdate(normalized_data, function(data, status) { success && success(data, status, 'update'); }, error); @@ -271,26 +272,21 @@ define(function(require){ data.timeout /= 1000; // ms to seconds } - if(data.interdigit_timeout) { + if (data.interdigit_timeout) { data.interdigit_timeout /= 1000; // ms to seconds } - - if(data.media) { - if(data.media.invalid_media === false && data.media.transfer_media === false && data.media.exit_media === false) { + if (data.media) { + if (data.media.invalid_media === false && data.media.transfer_media === false && data.media.exit_media === false) { data.suppress_media = true; - } - else { + } else { data.suppress_media = false; } } }, menuCleanFormData: function(form_data) { - if(form_data.record_pin.length == 0) { - form_data.max_extension_length = 4; - } - else if(form_data.max_extension_length < form_data.record_pin.length) { + if (form_data.max_extension_length < form_data.record_pin.length) { form_data.max_extension_length = form_data.record_pin.length; } @@ -302,12 +298,11 @@ define(function(require){ if ('suppress_media' in form_data) { form_data.media = form_data.media || {}; - if(form_data.suppress_media === true) { + if (form_data.suppress_media === true) { form_data.media.invalid_media = false; form_data.media.transfer_media = false; form_data.media.exit_media = false; - } - else { + } else { form_data.media.invalid_media = true; form_data.media.transfer_media = true; form_data.media.exit_media = true; @@ -316,19 +311,19 @@ define(function(require){ }, menuNormalizeData: function(form_data) { - if(!form_data.media.greeting) { + if (!form_data.media.greeting) { delete form_data.media.greeting; } - if(form_data.hunt_allow == '') { + if (form_data.hunt_allow === '') { delete form_data.hunt_allow; } - if(form_data.hunt_deny == '') { + if (form_data.hunt_deny === '') { delete form_data.hunt_deny; } - if(form_data.record_pin == '') { + if (form_data.record_pin === '') { delete form_data.record_pin; } @@ -359,10 +354,10 @@ define(function(require){ ], isUsable: 'true', weight: 60, - key_caption: function(child_node, caption_map) { + key_caption: function(child_node) { var key = child_node.key; - return (key != '_') ? key : self.i18n.active().callflows.menu.default_action; + return (key !== '_') ? key : self.i18n.active().callflows.menu.default_action; }, key_edit: function(child_node, callback) { var popup, popup_html; @@ -371,23 +366,28 @@ define(function(require){ The '#' Key is only displayed if it exists in the callflow, otherwise it is hidden by the template (see /tmpl/menu_key_callflow.html) */ - popup_html = $(monster.template(self, 'menu-callflowKey', { - items: { - '_': self.i18n.active().callflows.menu.default_action, - '0': '0', - '1': '1', - '2': '2', - '3': '3', - '4': '4', - '5': '5', - '6': '6', - '7': '7', - '8': '8', - '9': '9', - '*': '*', - '#': '#' + popup_html = $(self.getTemplate({ + name: 'callflowKey', + data: { + items: { + '_': self.i18n.active().callflows.menu.default_action, + 'timeout': 'timeout', + '0': '0', + '1': '1', + '2': '2', + '3': '3', + '4': '4', + '5': '5', + '6': '6', + '7': '7', + '8': '8', + '9': '9', + '*': '*', + '#': '#' + }, + selected: child_node.key }, - selected: child_node.key + submodule: 'menu' })); popup_html.find('#add').on('click', function() { @@ -410,7 +410,7 @@ define(function(require){ var id = node.getMetadata('id'), returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } @@ -422,18 +422,21 @@ define(function(require){ self.menuList(function(menus) { var popup, popup_html; - popup_html = $(monster.template(self, 'menu-callflowEdit', { - items: _.sortBy(menus, 'name'), - selected: node.getMetadata('id') || '' + popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { + items: _.sortBy(menus, 'name'), + selected: node.getMetadata('id') || '' + }, + submodule: 'menu' })); - if($('#menu_selector option:selected', popup_html).val() == undefined) { + if ($('#menu_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#menu_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#menu_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -456,7 +459,7 @@ define(function(require){ title: self.i18n.active().callflows.menu.menu_title, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -468,7 +471,9 @@ define(function(require){ resource: 'menu.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -487,7 +492,9 @@ define(function(require){ resource: 'menu.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); diff --git a/src/apps/callflows/views/menu-callflowEdit.html b/src/apps/callflows/submodules/menu/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/menu-callflowEdit.html rename to src/apps/callflows/submodules/menu/views/callflowEdit.html diff --git a/src/apps/callflows/views/menu-callflowKey.html b/src/apps/callflows/submodules/menu/views/callflowKey.html similarity index 100% rename from src/apps/callflows/views/menu-callflowKey.html rename to src/apps/callflows/submodules/menu/views/callflowKey.html diff --git a/src/apps/callflows/views/menu-edit.html b/src/apps/callflows/submodules/menu/views/edit.html similarity index 100% rename from src/apps/callflows/views/menu-edit.html rename to src/apps/callflows/submodules/menu/views/edit.html diff --git a/src/apps/callflows/submodules/misc/misc.js b/src/apps/callflows/submodules/misc/misc.js index 5eb3f9c..1105488 100644 --- a/src/apps/callflows/submodules/misc/misc.js +++ b/src/apps/callflows/submodules/misc/misc.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -10,33 +10,45 @@ define(function(require){ 'callflows.fetchActions': 'miscDefineActions' }, + appFlags: { + misc: { + webhook: { + verbsWithFormat: ['post', 'put'], + bodyFormats: ['form-data', 'json'], + httpVerbs: { + get: 'GET', + post: 'POST', + put: 'PUT' + } + } + } + }, + miscGetGroupPickupData: function(callback) { var self = this; monster.parallel({ - groups: function(callback) { - self.miscGroupList(function(data) { - callback(null, data); - }); - }, - users: function(callback) { - self.miscUserList(function(data) { - _.each(data, function(user) { - user.name = user.first_name + ' ' + user.last_name; - }); - callback(null, data); - }); - }, - devices: function(callback) { - self.miscDeviceList(function(data) { - callback(null, data); + groups: function(callback) { + self.miscGroupList(function(data) { + callback(null, data); + }); + }, + users: function(callback) { + self.miscUserList(function(data) { + _.each(data, function(user) { + user.name = user.first_name + ' ' + user.last_name; }); - } + callback(null, data); + }); }, - function(err, results) { - callback && callback(results); + devices: function(callback) { + self.miscDeviceList(function(data) { + callback(null, data); + }); } - ); + }, function(err, results) { + callback && callback(results); + }); }, miscDefineActions: function(args) { @@ -52,7 +64,7 @@ define(function(require){ maxSize: '1' } ], - isUsable : 'false' + isUsable: 'false' }, 'callflow[id=*]': { name: self.i18n.active().oldCallflows.callflow, @@ -75,11 +87,10 @@ define(function(require){ var id = node.getMetadata('id'), return_value = ''; - if(id in caption_map) { - if(caption_map[id].hasOwnProperty('name')) { + if (id in caption_map) { + if (caption_map[id].hasOwnProperty('name')) { return_value = caption_map[id].name; - } - else if(caption_map[id].hasOwnProperty('numbers')) { + } else if (caption_map[id].hasOwnProperty('numbers')) { return_value = caption_map[id].numbers.toString(); } } @@ -91,25 +102,31 @@ define(function(require){ resource: 'callflow.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, - success:function(data, status) { + success: function(data, status) { var popup, popup_html, _data = []; $.each(data.data, function() { - if(!this.featurecode && this.id !== self.flow.id) { + if (!this.featurecode && this.id !== self.flow.id) { this.name = this.name ? this.name : ((this.numbers) ? this.numbers.toString() : self.i18n.active().oldCallflows.no_numbers); _data.push(this); } }); - popup_html = $(monster.template(self, 'callflow-edit_dialog', { - objects: { - type: 'callflow', - items: _.sortBy(_data, 'name'), - selected: node.getMetadata('id') || '' - } + popup_html = $(self.getTemplate({ + name: 'callflow-edit_dialog', + data: { + objects: { + type: 'callflow', + items: _.sortBy(_data, 'name'), + selected: node.getMetadata('id') || '' + } + }, + submodule: 'misc' })); $('#add', popup_html).click(function() { @@ -123,7 +140,7 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().oldCallflows.callflow_title, beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -227,11 +244,11 @@ define(function(require){ ], isUsable: 'true', weight: 10, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -253,11 +270,11 @@ define(function(require){ ], isUsable: 'true', weight: 20, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -279,11 +296,11 @@ define(function(require){ ], isUsable: 'true', weight: 30, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -296,11 +313,11 @@ define(function(require){ tip: self.i18n.active().oldCallflows.dynamic_cid_tip, isUsable: 'true', weight: 10, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -325,18 +342,22 @@ define(function(require){ ], isUsable: 'true', weight: 20, - caption: function(node, caption_map) { + caption: function(node) { return (node.getMetadata('caller_id_name_prefix') || '') + ' ' + (node.getMetadata('caller_id_number_prefix') || ''); }, edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-prepend_cid_callflow', { - data_cid: { - 'caller_id_name_prefix': node.getMetadata('caller_id_name_prefix') || '', - 'caller_id_number_prefix': node.getMetadata('caller_id_number_prefix') || '', - 'apply_to': node.getMetadata('apply_to') || '' - } + popup_html = $(self.getTemplate({ + name: 'prepend_cid_callflow', + data: { + data_cid: { + 'caller_id_name_prefix': node.getMetadata('caller_id_name_prefix') || '', + 'caller_id_number_prefix': node.getMetadata('caller_id_number_prefix') || '', + 'apply_to': node.getMetadata('apply_to') || '' + } + }, + submodule: 'misc' })); $('#add', popup_html).click(function() { @@ -356,8 +377,8 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().oldCallflows.prepend_caller_id_title, beforeClose: function() { - if(typeof callback == 'function') { - callback(); + if (typeof callback === 'function') { + callback(); } } }); @@ -386,23 +407,22 @@ define(function(require){ ], isUsable: 'true', weight: 30, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } }, 'check_cid[]': { name: self.i18n.active().oldCallflows.check_cid, - icon: 'list-ol', - category: self.i18n.active().oldCallflows.caller_id_cat, - module: 'check_cid', - tip: self.i18n.active().oldCallflows.check_cid_tip, - data: { - }, + icon: 'list-ol', + category: self.i18n.active().oldCallflows.caller_id_cat, + module: 'check_cid', + tip: self.i18n.active().oldCallflows.check_cid_tip, + data: {}, rules: [ { type: 'quantity', @@ -414,69 +434,74 @@ define(function(require){ caption: function(node, caption_map) { return ''; }, - edit: function(node, callback) { + edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self, 'check_cid-callflowEdit', { - data_check_cid: { - 'regex': node.getMetadata('regex') || '' - } - })), - popup; - $('#add', popup_html).click(function() { - var regex = $('#regex_input', popup_html).val(); - node.setMetadata('regex', regex); - node.setMetadata('use_absolute_mode', false); - node.caption = regex; - - popup.dialog('close'); - }); - - popup = monster.ui.dialog(popup_html, { - title: self.i18n.active().oldCallflows.check_cid_title, - beforeClose: function() { - if(typeof callback == 'function') { - callback(); - } - } - }); - }, + popup_html = $(self.getTemplate({ + name: 'check_cid-callflowEdit', + data: { + data_check_cid: { + 'regex': node.getMetadata('regex') || '' + } + }, + submodule: 'misc' + })); + + $('#add', popup_html).click(function() { + var regex = $('#regex_input', popup_html).val(); + node.setMetadata('regex', regex); + node.setMetadata('use_absolute_mode', false); + node.caption = regex; + + popup.dialog('close'); + }); + + popup = monster.ui.dialog(popup_html, { + title: self.i18n.active().oldCallflows.check_cid_title, + beforeClose: function() { + if (typeof callback === 'function') { + callback(); + } + } + }); + }, key_caption: function(child_node, caption_map) { var key = child_node.key; - return (key != '_') ? key : self.i18n.active().oldCallflows.check_cid_match; + return (key !== '_') ? key : self.i18n.active().oldCallflows.check_cid_match; }, - key_edit: function(child_node, callback) { - var popup, popup_html; + key_edit: function(child_node, callback) { + var popup, popup_html; - popup_html = $(monster.template(self, 'check_cid-childCallflow', { - items: { - 'match': self.i18n.active().oldCallflows.check_cid_match, - 'nomatch': self.i18n.active().oldCallflows.check_cid_nomatch + popup_html = $(self.getTemplate({ + name: 'check_cid-childCallflow', + data: { + items: { + 'match': self.i18n.active().oldCallflows.check_cid_match, + 'nomatch': self.i18n.active().oldCallflows.check_cid_nomatch + }, + selected: child_node.key }, - selected: child_node.key - })); + submodule: 'misc' + })); - popup_html.find('#add').on('click', function() { - child_node.key = $('#check_cid_callflow_key_selector', popup_html).val(); + popup_html.find('#add').on('click', function() { + child_node.key = $('#check_cid_callflow_key_selector', popup_html).val(); - child_node.key_caption = $('#check_cid_callflow_key_selector option:selected', popup_html).text(); + child_node.key_caption = $('#check_cid_callflow_key_selector option:selected', popup_html).text(); - popup.dialog('close'); - }); + popup.dialog('close'); + }); - popup = monster.ui.dialog(popup_html, { - title: self.i18n.active().oldCallflows.check_cid_matchnomatch, - minHeight: '0', - beforeClose: function() { - if (typeof callback === 'function') { - callback(); - } + popup = monster.ui.dialog(popup_html, { + title: self.i18n.active().oldCallflows.check_cid_matchnomatch, + minHeight: '0', + beforeClose: function() { + if (typeof callback === 'function') { + callback(); + } } - }); - - - } - + }); + } }, 'webhook[]': { name: self.i18n.active().oldCallflows.webhook, @@ -498,14 +523,18 @@ define(function(require){ return node.getMetadata('webhook') || ''; }, edit: function(node, callback) { - var popup_html = $(monster.template(self, 'webhook-callflowEdit', { - data_webhook: { - 'http_verb': node.getMetadata('http_verb') || 'get', - 'retries': node.getMetadata('retries') || '3', - 'uri': node.getMetadata('uri') || '' - } - })), - popup; + var popup_html = $(self.getTemplate({ + name: 'webhook-callflowEdit', + data: { + data_webhook: { + 'http_verb': node.getMetadata('http_verb') || 'get', + 'retries': node.getMetadata('retries') || '3', + 'uri': node.getMetadata('uri') || '' + } + }, + submodule: 'misc' + })), + popup; $('#add', popup_html).click(function() { node.setMetadata('http_verb', $('#http_verb option:selected', popup_html).val()); node.setMetadata('retries', $('#retries_input', popup_html).val()); @@ -514,17 +543,69 @@ define(function(require){ popup.dialog('close'); }); - popup = monster.ui.dialog(popup_html, { - title: self.i18n.active().oldCallflows.webhook_title, - beforeClose: function() { - if(typeof callback == 'function') { - callback(); - } - } - }); - } + popup = monster.ui.dialog(popup_html, { + title: self.i18n.active().oldCallflows.webhook_title, + beforeClose: function() { + if (typeof callback === 'function') { + callback(); + } + } + }); + } }, + 'set_alert_info[]': { + name: self.i18n.active().callflows.setAlertInfo.name, + icon: 'play', + category: self.i18n.active().oldCallflows.advanced_cat, + module: 'set_alert_info', + tip: self.i18n.active().callflows.setAlertInfo.tip, + data: { + alert_info: '' + }, + rules: [ + { + type: 'quantity', + maxSize: '1' + } + ], + isUsable: 'true', + weight: 20, + + caption: function(node) { + return (node.getMetadata('alert_info') || ''); + }, + + edit: function(node, callback) { + var popup_html = $(self.getTemplate({ + name: 'setAlertEdit', + data: { + alert_info: node.getMetadata('alert_info') || '' + }, + submodule: 'misc' + })), + popup; + + $('#add', popup_html).click(function() { + var alert_info_val = $('#alert_info', popup_html).val(); + + node.setMetadata('alert_info', alert_info_val); + + node.caption = alert_info_val; + + popup.dialog('close'); + }); + + popup = monster.ui.dialog(popup_html, { + title: self.i18n.active().callflows.setAlertInfo.title, + beforeClose: function() { + if (typeof callback === 'function') { + callback(); + } + } + }); + } + }, 'manual_presence[]': { name: self.i18n.active().oldCallflows.manual_presence, icon: 'lightbulb-o', @@ -541,15 +622,19 @@ define(function(require){ ], isUsable: 'true', weight: 40, - caption: function(node, caption_map) { + caption: function(node) { return node.getMetadata('presence_id') || ''; }, edit: function(node, callback) { - var popup_html = $(monster.template(self, 'presence-callflowEdit', { - data_presence: { - 'presence_id': node.getMetadata('presence_id') || '', - 'status': node.getMetadata('status') || 'busy' - } + var popup_html = $(self.getTemplate({ + name: 'presence-callflowEdit', + data: { + data_presence: { + 'presence_id': node.getMetadata('presence_id') || '', + 'status': node.getMetadata('status') || 'busy' + } + }, + submodule: 'misc' })), popup; @@ -566,8 +651,8 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().oldCallflows.manual_presence_title, beforeClose: function() { - if(typeof callback == 'function') { - callback(); + if (typeof callback === 'function') { + callback(); } } }); @@ -589,16 +674,20 @@ define(function(require){ ], isUsable: 'true', weight: 50, - caption: function(node, caption_map) { + caption: function(node) { return node.getMetadata('language') || ''; }, edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-language', { - data_language: { - 'language': node.getMetadata('language') || '' - } + popup_html = $(self.getTemplate({ + name: 'language', + data: { + data_language: { + 'language': node.getMetadata('language') || '' + } + }, + submodule: 'misc' })); $('#add', popup_html).click(function() { @@ -612,8 +701,8 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().oldCallflows.language_title, beforeClose: function() { - if(typeof callback == 'function') { - callback(); + if (typeof callback === 'function') { + callback(); } } }); @@ -635,25 +724,29 @@ define(function(require){ ], isUsable: 'true', weight: 60, - caption: function(node, caption_map) { + caption: function(node) { return node.getMetadata('name') || ''; }, edit: function(node, callback) { self.miscGetGroupPickupData(function(results) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-group_pickup', { + popup_html = $(self.getTemplate({ + name: 'group_pickup', data: { - items: results, - selected: node.getMetadata('device_id') || node.getMetadata('group_id') || node.getMetadata('user_id') || '' - } + data: { + items: results, + selected: node.getMetadata('device_id') || node.getMetadata('group_id') || node.getMetadata('user_id') || '' + } + }, + submodule: 'misc' })); $('#add', popup_html).click(function() { var selector = $('#endpoint_selector', popup_html), id = selector.val(), - name = selector.find('#'+id).html(), - type = $('#'+ id, popup_html).parents('optgroup').data('type'), + name = selector.find('#' + id).html(), + type = $('#' + id, popup_html).parents('optgroup').data('type'), type_id = type.substring(type, type.length - 1) + '_id'; /* Clear all the useless attributes */ @@ -692,7 +785,7 @@ define(function(require){ ], isUsable: 'true', weight: 70, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { @@ -703,26 +796,29 @@ define(function(require){ this.name = this.first_name + ' ' + this.last_name; }); - popup_html = $(monster.template(self, 'fax-callflowEdit', { - objects: { - items: data, - selected: node.getMetadata('owner_id') || '', - t_38: node.getMetadata('media') && node.getMetadata('media').fax_option || false - } + popup_html = $(self.getTemplate({ + name: 'fax-callflowEdit', + data: { + objects: { + items: data, + selected: node.getMetadata('owner_id') || '', + t_38: node.getMetadata('media') && (node.getMetadata('media').fax_option || false) + } + }, + submodule: 'misc' })); - if($('#user_selector option:selected', popup_html).val() == undefined) { + if ($('#user_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#user_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#user_selector', popup_html).val() } : {}; ev.preventDefault(); monster.pub('callflows.user.popupEdit', { - data: _data, + data: _data, callback: function(_data) { node.setMetadata('owner_id', _data.id || 'null'); @@ -743,7 +839,7 @@ define(function(require){ title: self.i18n.active().oldCallflows.select_user_title, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -772,12 +868,16 @@ define(function(require){ return ''; }, edit: function(node, callback) { - var popup_html = $(monster.template(self, 'recordCall-callflowEdit', { - data_call_record: { - 'format': node.getMetadata('format') || 'mp3', - 'url': node.getMetadata('url') || '', - 'time_limit': node.getMetadata('time_limit') || '600' - } + var popup_html = $(self.getTemplate({ + name: 'recordCall-callflowEdit', + data: { + data_call_record: { + 'format': node.getMetadata('format') || 'mp3', + 'url': node.getMetadata('url') || '', + 'time_limit': node.getMetadata('time_limit') || '600' + } + }, + submodule: 'misc' })), popup; @@ -793,8 +893,8 @@ define(function(require){ title: self.i18n.active().oldCallflows.start_call_recording, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { - callback(); + if (typeof callback === 'function') { + callback(); } } }); @@ -820,7 +920,7 @@ define(function(require){ caption: function(node) { return ''; }, - edit: function(node, callback) { + edit: function(node) { } }, 'pivot[]': { @@ -849,13 +949,17 @@ define(function(require){ edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self,'misc-pivot', { - data_pivot: { - 'method': node.getMetadata('method') || 'get', - 'voice_url': node.getMetadata('voice_url') || '', - 'req_timeout': node.getMetadata('req_timeout') || '5', - 'req_format': node.getMetadata('req_format') || 'twiml' - } + popup_html = $(self.getTemplate({ + name: 'pivot', + data: { + data_pivot: { + 'method': node.getMetadata('method') || 'get', + 'voice_url': node.getMetadata('voice_url') || '', + 'req_timeout': node.getMetadata('req_timeout') || '5', + 'req_format': node.getMetadata('req_format') || 'twiml' + } + }, + submodule: 'misc' })); $('#add', popup_html).click(function() { @@ -870,8 +974,8 @@ define(function(require){ title: self.i18n.active().oldCallflows.pivot_title, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { - callback(); + if (typeof callback === 'function') { + callback(); } } }); @@ -901,15 +1005,19 @@ define(function(require){ edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self,'misc-disa', { - data_disa: { - 'pin': node.getMetadata('pin'), - 'retries': node.getMetadata('retries'), - 'interdigit': node.getMetadata('interdigit'), - 'max_digits': node.getMetadata('max_digits'), - 'preconnect_audio': node.getMetadata('preconnect_audio'), - 'use_account_caller_id': node.getMetadata('use_account_caller_id') - } + popup_html = $(self.getTemplate({ + name: 'disa', + data: { + data_disa: { + 'pin': node.getMetadata('pin'), + 'retries': node.getMetadata('retries'), + 'interdigit': node.getMetadata('interdigit'), + 'max_digits': node.getMetadata('max_digits'), + 'preconnect_audio': node.getMetadata('preconnect_audio'), + 'use_account_caller_id': node.getMetadata('use_account_caller_id') + } + }, + submodule: 'misc' })); monster.ui.tooltips(popup_html); @@ -917,13 +1025,12 @@ define(function(require){ $('#add', popup_html).click(function() { var save_disa = function() { var setData = function(field, value) { - if(value !== 'default') { - node.setMetadata(field, value); - } - else { - node.deleteMetadata(field); - } - }; + if (value !== 'default') { + node.setMetadata(field, value); + } else { + node.deleteMetadata(field); + } + }; setData('pin', $('#disa_pin_input', popup_html).val()); setData('retries', $('#disa_retries_input', popup_html).val()); @@ -934,12 +1041,11 @@ define(function(require){ popup.dialog('close'); }; - if($('#disa_pin_input', popup_html).val() == '') { + if ($('#disa_pin_input', popup_html).val() === '') { monster.ui.confirm(self.i18n.active().oldCallflows.not_setting_a_pin, function() { save_disa(); }); - } - else { + } else { save_disa(); } }); @@ -947,8 +1053,8 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().callflows.disa.title, beforeClose: function() { - if(typeof callback == 'function') { - callback(); + if (typeof callback === 'function') { + callback(); } } }); @@ -978,14 +1084,18 @@ define(function(require){ edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-collect-dtmf', { - data_dtmf: { - 'interdigit_timeout': node.getMetadata('interdigit_timeout') || '', - 'collection_name': node.getMetadata('collection_name') || '', - 'max_digits': node.getMetadata('max_digits') || '', - 'terminator': node.getMetadata('terminator') || '#', - 'timeout': node.getMetadata('timeout') || '5000' - } + popup_html = $(self.getTemplate({ + name: 'collect-dtmf', + data: { + data_dtmf: { + 'interdigit_timeout': node.getMetadata('interdigit_timeout') || '', + 'collection_name': node.getMetadata('collection_name') || '', + 'max_digits': node.getMetadata('max_digits') || '', + 'terminator': node.getMetadata('terminator') || '#', + 'timeout': node.getMetadata('timeout') || '5000' + } + }, + submodule: 'misc' })); monster.ui.tooltips(popup_html); @@ -1042,10 +1152,14 @@ define(function(require){ edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-sleep', { - data_sleep: { - 'duration': node.getMetadata('duration') - } + popup_html = $(self.getTemplate({ + name: 'sleep', + data: { + data_sleep: { + 'duration': node.getMetadata('duration') + } + }, + submodule: 'misc' })); monster.ui.tooltips(popup_html); @@ -1097,12 +1211,16 @@ define(function(require){ edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-tts', { - data_tts: { - 'text': node.getMetadata('text'), - 'language': node.getMetadata('language'), - 'voice': node.getMetadata('voice') - } + popup_html = $(self.getTemplate({ + name: 'tts', + data: { + data_tts: { + 'text': node.getMetadata('text'), + 'language': node.getMetadata('language'), + 'voice': node.getMetadata('voice') + } + }, + submodule: 'misc' })); monster.ui.tooltips(popup_html); @@ -1152,40 +1270,43 @@ define(function(require){ ], isUsable: 'true', weight: 100, - caption: function(node, caption_map) { + caption: function(node) { return self.i18n.active().oldCallflows.sip_code_caption + node.getMetadata('code'); }, edit: function(node, callback) { self.miscMediaList(function(data) { var popup, popup_html; - popup_html = $(monster.template(self, 'misc-response', { - response_data: { - items: data, - media_enabled: node.getMetadata('media') ? true : false, - selected_media: node.getMetadata('media') || '', - code: node.getMetadata('code') || '', - message: node.getMetadata('message') || '' - } + popup_html = $(self.getTemplate({ + name: 'response', + data: { + response_data: { + items: data, + media_enabled: node.getMetadata('media') ? true : false, + selected_media: node.getMetadata('media') || '', + code: node.getMetadata('code') || '', + message: node.getMetadata('message') || '' + } + }, + submodule: 'misc' })); - if($('#media_selector option:selected', popup_html).val() == undefined - || $('#media_selector option:selected', popup_html).val() == 'null') { + if ($('#media_selector option:selected', popup_html).val() === undefined + || $('#media_selector option:selected', popup_html).val() === 'null') { $('#edit_link', popup_html).hide(); } $('#media_selector', popup_html).change(function() { - if($('#media_selector option:selected', popup_html).val() == undefined - || $('#media_selector option:selected', popup_html).val() == 'null') { + if ($('#media_selector option:selected', popup_html).val() === undefined + || $('#media_selector option:selected', popup_html).val() === 'null') { $('#edit_link', popup_html).hide(); } else { $('#edit_link', popup_html).show(); } - }) + }); $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#media_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#media_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -1200,10 +1321,10 @@ define(function(require){ }); $('#add', popup_html).click(function() { - if($('#response_code_input', popup_html).val().match(/^[1-6][0-9]{2}$/)) { + if ($('#response_code_input', popup_html).val().match(/^[1-6][0-9]{2}$/)) { node.setMetadata('code', $('#response_code_input', popup_html).val()); node.setMetadata('message', $('#response_message_input', popup_html).val()); - if($('#media_selector', popup_html).val() && $('#media_selector', popup_html).val() != 'null') { + if ($('#media_selector', popup_html).val() && $('#media_selector', popup_html).val() !== 'null') { node.setMetadata('media', $('#media_selector', popup_html).val()); } else { node.deleteMetadata('media'); @@ -1221,7 +1342,7 @@ define(function(require){ title: self.i18n.active().oldCallflows.response_title, minHeight: '0', beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -1252,10 +1373,30 @@ define(function(require){ edit: function(node, callback) { self.miscEditMissedCallAlerts(node, callback); } + }, + 'set_variables[]': { + name: self.i18n.active().callflows.setCav.title, + icon: 'settings2', + category: self.i18n.active().oldCallflows.advanced_cat, + module: 'set_variables', + tip: self.i18n.active().callflows.setCav.tip, + data: { + custom_application_vars: {} + }, + rules: [], + isUsable: 'true', + weight: 31, + caption: function(node) { + return ''; + }, + edit: function(node, callback) { + self.miscEditSetCAV(node, callback); + } } }); }, + /* Render edit dialogs */ miscEditMissedCallAlerts: function(node, callback) { var self = this, recipients = node.getMetadata('recipients'), @@ -1288,7 +1429,13 @@ define(function(require){ } }); - var template = $(monster.template(self, 'misc-missedCallAlert-dialog', { emails: selectedEmails.toString() })), + var template = $(self.getTemplate({ + name: 'missedCallAlert-dialog', + data: { + emails: selectedEmails.toString() + }, + submodule: 'misc' + })), widget = monster.ui.linkedColumns(template.find('.items-selector-wrapper'), items, selectedItems, { i18n: { columnsTitles: { @@ -1335,6 +1482,198 @@ define(function(require){ }); }, + miscEditSetCAV: function(node, callback) { + var self = this, + variables = _.extend({}, node.getMetadata('custom_application_vars')), + initTemplate = function() { + var template = $(self.getTemplate({ + name: 'setcav-dialog', + data: { + variables: variables + }, + submodule: 'misc' + })), + popup; + + if (_.size(variables) <= 0) { + addRow(template); + } + + _.each(variables, function(variable, key) { + addRow(template, { + key: key, + value: variable + }); + }); + + popup = monster.ui.dialog(template, { + title: self.i18n.active().callflows.setCav.popupTitle, + width: 500, + beforeClose: function() { + if (typeof callback === 'function') { + callback(); + } + } + }); + + bindSetCavEvents({ + template: template, + popup: popup + }); + }, + bindSetCavEvents = function(args) { + var template = args.template, + popup = args.popup, + formData; + + template.find('.cav-add-row .svg-icon') + .on('click', function() { + addRow(template); + }); + + template.find('#save_cav_variables').on('click', function() { + formData = monster.ui.getFormData('set_cav_form'); + variables = _ + .chain(formData.items) + .reject(function(item) { + return _.isEmpty(item.key) || _.isEmpty(item.value); + }) + .keyBy('key') + .mapValues('value') + .value(); + + node.setMetadata('custom_application_vars', variables); + + popup.dialog('close'); + }); + }, + addRow = function(template, data) { + var cavRow = $(self.getTemplate({ + name: 'setcav-row', + submodule: 'misc', + data: _.merge(data, { + index: template.find('.cav-list tbody tr').length + 1 + }) + })); + + template.find('.cav-list tbody') + .append(cavRow); + + template.find('.cav-remove-row') + .on('click', function() { + if (template.find('.cav-list tbody tr').length <= 1) { + return; + } + + $(this).parent().parent().remove(); + }); + }; + + initTemplate(); + }, + + miscRenderEditWebhook: function(node, callback) { + var self = this, + popup, + initTemplate = function() { + var data = { + hasVerbWithFormat: _.includes(self.appFlags.misc.webhook.verbsWithFormat, node.getMetadata('http_verb')), + bodyFormatList: _.map(self.appFlags.misc.webhook.bodyFormats, function(item) { + return { + value: item, + label: _.get(self.i18n.active().callflows.webhook.format.options, _.camelCase(item), monster.util.formatVariableToDisplay(item)) + }; + }), + httpVerbsList: self.appFlags.misc.webhook.httpVerbs, + format: node.getMetadata('format', ''), + uri: node.getMetadata('uri', ''), + http_verb: node.getMetadata('http_verb', 'get'), + retries: node.getMetadata('retries', 1), + custom_data: node.getMetadata('custom_data', {}) + }, + $template = $(self.getTemplate({ + name: 'webhook-callflowEdit', + data: data, + submodule: 'misc' + })), + $form = $template.find('#webhook_form'); + + monster.ui.keyValueEditor($template.find('.custom-data-container'), { + data: data.custom_data, + inputName: 'custom_data' + }); + + monster.ui.tooltips($template); + + monster.ui.validate($form, { + rules: { + uri: { + required: true, + url: true + } + }, + messages: { + uri: { + url: self.i18n.active().callflows.webhook.uri.errorMessages.url + } + } + }); + + $template.find('#http_verb').on('change', function() { + var $this = $(this), + newValue = $this.val(), + $formPopupField = $template.find('#form_popup_field'), + animationMethod = _.includes(self.appFlags.misc.webhook.verbsWithFormat, newValue) ? 'slideDown' : 'slideUp'; + + $formPopupField[animationMethod](250); + }); + + $template.find('#add').on('click', function(e) { + e.preventDefault(); + + if (!monster.ui.valid($form)) { + return; + } + + var formData = monster.ui.getFormData('webhook_form'); + + _.each(formData, function(value, key) { + if (key === 'custom_data') { + value = _ + .chain(value) + .keyBy('key') + .mapValues('value') + .value(); + } else if (key === 'retries') { + value = _.parseInt(value, 10); + } else if ( + key === 'format' + && !_.includes(self.appFlags.misc.webhook.verbsWithFormat, formData.http_verb) + ) { + node.deleteMetadata('format'); + return; + } + + node.setMetadata(key, value); + }); + + popup.dialog('close'); + }); + + return $template; + }; + + popup = monster.ui.dialog(initTemplate(), { + title: self.i18n.active().callflows.webhook.popupTitle, + beforeClose: function() { + if (_.isFunction(callback)) { + callback(); + } + } + }); + }, + + /* API helpers */ miscDeviceList: function(callback) { var self = this; @@ -1342,7 +1681,9 @@ define(function(require){ resource: 'device.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -1357,7 +1698,9 @@ define(function(require){ resource: 'group.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -1372,7 +1715,9 @@ define(function(require){ resource: 'user.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -1387,7 +1732,9 @@ define(function(require){ resource: 'media.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); diff --git a/src/apps/callflows/submodules/misc/misc.scss b/src/apps/callflows/submodules/misc/misc.scss new file mode 100644 index 0000000..e10a934 --- /dev/null +++ b/src/apps/callflows/submodules/misc/misc.scss @@ -0,0 +1,240 @@ +/********** Two columns **********/ + +.callflows-port #two_columns { + padding-bottom: 20px; +} + +.callflows-port #two_columns .wrapper { + clear: left; + width: 520px; + padding: 10px; +} + +.callflows-port #two_columns .wrapper_form { + margin-top: 20px; + margin-left: 40px; +} + +.callflows-port #two_columns .wrapper .column { + width: 220px; + padding: 6px 0px 5px; + background: #444; + border-radius: 6px; +} + +.callflows-port #two_columns .wrapper .column.right { + float: right; + margin-left: 10px; +} + +.callflows-port #two_columns .wrapper .column.left { + float: left; + margin-right: 10px; +} + +.callflows-port #two_columns .wrapper .title_column { + background-color: #AFAFAF; + height: 28px; + line-height: 28px; + font-weight: bold; + font-size: 14px; + text-align: center; + margin-bottom: 3px; +} + +.callflows-port #two_columns .wrapper .left ul.connect { + background-color: #444444; + height: 289px; + width: 220px; + overflow: auto; + float: left; +} + +.callflows-port #two_columns .wrapper .connect { + min-height: 289px; +} + +.callflows-port #two_columns .wrapper .right ul.connect { + background-color: #444444; + height: 289px; + width: 220px; + overflow: auto; +} + +.callflows-port #two_columns .wrapper li { + list-style-type: none; + background-color: #AFAFAF; + color: #444; + display: block; + height: 28px; + line-height: 28px; + list-style-type: none; + overflow: hidden; + position: relative; + cursor: default; +} + +.callflows-port #two_columns .wrapper li:not(:first-child) { + border-top: 1px solid #444; +} + +.callflows-port #two_columns .item_name { + float:left; + overflow: hidden; + height: 28px; + line-height: 28px; + width: 155px; + font-size: 12px; + white-space: nowrap; +} +.callflows-port #two_columns .item_name.right { + width: 120px; +} + +.callflows-port #two_columns .wrapper li:hover { + background-color: #cccccc; +} + +.callflows-port #two_columns .wrapper li a.drag_btn { + float: left; + height: 28px; + width: 7px; + margin-right: 5px; + margin-left: 1px; +} + +/* Ring group specific css */ +.callflows-port #two_columns .options { + float: right; + margin-right: 2px; + padding-left: 4px; + border-left: 1px solid #444444; + height: 28px; +} + +.callflows-port #two_columns .options .option { + width: 30px; + font-size: 12px; + margin-top: 2px; + height: 20px; +} + +.callflows-port #two_columns .ring_group_form_wrapper { + display: block; + margin: auto; + width: 260px; +} + +.callflows-port #two_columns .form_field_div { + width: 260px; +} + +.callflows-port #two_columns .button_field_div { + margin: 20px 0px 5px; + text-align: center; +} + +/********** Listpanel's search box **********/ + +.callflows-port .search_box { + height: 28px; + background-color:#444444; + padding-top: 7px; + border-bottom: 1px solid #222; +} + +.callflows-port .search_box .searchsubmit1 { + float: left; + height: 20px; + width: 23px; +} +.callflows-port .search_box .searchsubmit2 { + float: left; + height: 20px; + width: 26px; +} + +.callflows-port .search_box .searchfield { + border: medium none; + float: left; + height: 14px; + width: 130px; + border-radius: 0px; + box-shadow: none; +} + +.callflows-port .search_box .searchfield:focus { + border: none; + border-color: transparent; + -webkit-box-shadow: none; + -moz-box-shadow: none; + box-shadow: none; +} + +/********** Receive Fax **********/ + +.callflows-port#fax_callflow_popup #t_38_checkbox { + margin-top: 8px; +} + +/* Missed call alert */ +#missed_call_alert_popup { + width: 540px; +} +#missed_call_alert_popup .buttons-center { + margin-top: 10px; +} + +#missed_call_alert_popup form { + margin-bottom: 0; + margin-top: 20px; +} + +/* Set CAV */ +#set_cav_alert_popup .cav-add-row .svg-icon { + cursor: pointer; +} + +#set_cav_alert_popup .cav-remove-row { + margin-top: -10px; + cursor: pointer; + display: inline; + visibility: hidden; +} + +#set_cav_alert_popup .cav-remove-row:hover { + color: #ff0000; +} + +#set_cav_alert_popup .cav-list tr:hover .cav-remove-row { + visibility: visible; +} + +/* Collect DTMF Popup */ +.dialog_popup.collect-dtmf-popup .form_content .popup_field { + padding-bottom: 0; +} + +/************ Webhooks *************/ +.callflows-port#webhook_popup { + max-width: 450px; + + .custom-data { + label[for="custom_data"] { + display: block; + text-align: center; + width: 100%; + } + .custom-data-container { + clear: both; + + .data-key { + flex: initial; + width: 140px; + } + } + } + .monster-invalid { + float: none; + } +} diff --git a/src/apps/callflows/views/callflow-edit_dialog.html b/src/apps/callflows/submodules/misc/views/callflow-edit_dialog.html similarity index 100% rename from src/apps/callflows/views/callflow-edit_dialog.html rename to src/apps/callflows/submodules/misc/views/callflow-edit_dialog.html diff --git a/src/apps/callflows/views/fax-callflowEdit.html b/src/apps/callflows/submodules/misc/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/fax-callflowEdit.html rename to src/apps/callflows/submodules/misc/views/callflowEdit.html diff --git a/src/apps/callflows/views/check_cid-callflowEdit.html b/src/apps/callflows/submodules/misc/views/check_cid-callflowEdit.html similarity index 100% rename from src/apps/callflows/views/check_cid-callflowEdit.html rename to src/apps/callflows/submodules/misc/views/check_cid-callflowEdit.html diff --git a/src/apps/callflows/views/check_cid-childCallflow.html b/src/apps/callflows/submodules/misc/views/check_cid-childCallflow.html similarity index 100% rename from src/apps/callflows/views/check_cid-childCallflow.html rename to src/apps/callflows/submodules/misc/views/check_cid-childCallflow.html diff --git a/src/apps/callflows/views/misc-collect-dtmf.html b/src/apps/callflows/submodules/misc/views/collect-dtmf.html similarity index 100% rename from src/apps/callflows/views/misc-collect-dtmf.html rename to src/apps/callflows/submodules/misc/views/collect-dtmf.html diff --git a/src/apps/callflows/views/misc-disa.html b/src/apps/callflows/submodules/misc/views/disa.html similarity index 100% rename from src/apps/callflows/views/misc-disa.html rename to src/apps/callflows/submodules/misc/views/disa.html diff --git a/src/apps/callflows/submodules/misc/views/fax-callflowEdit.html b/src/apps/callflows/submodules/misc/views/fax-callflowEdit.html new file mode 100644 index 0000000..74637fd --- /dev/null +++ b/src/apps/callflows/submodules/misc/views/fax-callflowEdit.html @@ -0,0 +1,32 @@ +
    +

    {{ i18n.oldCallflows.sends_fax_to_user }}

    +
    +
    + diff --git a/src/apps/callflows/views/misc-group_pickup.html b/src/apps/callflows/submodules/misc/views/group_pickup.html similarity index 100% rename from src/apps/callflows/views/misc-group_pickup.html rename to src/apps/callflows/submodules/misc/views/group_pickup.html diff --git a/src/apps/callflows/views/misc-language.html b/src/apps/callflows/submodules/misc/views/language.html similarity index 98% rename from src/apps/callflows/views/misc-language.html rename to src/apps/callflows/submodules/misc/views/language.html index 580a8a4..6c71e14 100644 --- a/src/apps/callflows/views/misc-language.html +++ b/src/apps/callflows/submodules/misc/views/language.html @@ -11,4 +11,4 @@
    -
    \ No newline at end of file +
    diff --git a/src/apps/callflows/views/misc-missedCallAlert-dialog.html b/src/apps/callflows/submodules/misc/views/missedCallAlert-dialog.html similarity index 100% rename from src/apps/callflows/views/misc-missedCallAlert-dialog.html rename to src/apps/callflows/submodules/misc/views/missedCallAlert-dialog.html diff --git a/src/apps/callflows/views/misc-pivot.html b/src/apps/callflows/submodules/misc/views/pivot.html similarity index 100% rename from src/apps/callflows/views/misc-pivot.html rename to src/apps/callflows/submodules/misc/views/pivot.html diff --git a/src/apps/callflows/views/misc-prepend_cid_callflow.html b/src/apps/callflows/submodules/misc/views/prepend_cid_callflow.html similarity index 100% rename from src/apps/callflows/views/misc-prepend_cid_callflow.html rename to src/apps/callflows/submodules/misc/views/prepend_cid_callflow.html diff --git a/src/apps/callflows/views/presence-callflowEdit.html b/src/apps/callflows/submodules/misc/views/presence-callflowEdit.html similarity index 100% rename from src/apps/callflows/views/presence-callflowEdit.html rename to src/apps/callflows/submodules/misc/views/presence-callflowEdit.html diff --git a/src/apps/callflows/views/recordCall-callflowEdit.html b/src/apps/callflows/submodules/misc/views/recordCall-callflowEdit.html similarity index 100% rename from src/apps/callflows/views/recordCall-callflowEdit.html rename to src/apps/callflows/submodules/misc/views/recordCall-callflowEdit.html diff --git a/src/apps/callflows/views/misc-response.html b/src/apps/callflows/submodules/misc/views/response.html similarity index 100% rename from src/apps/callflows/views/misc-response.html rename to src/apps/callflows/submodules/misc/views/response.html diff --git a/src/apps/callflows/submodules/misc/views/setAlertEdit.html b/src/apps/callflows/submodules/misc/views/setAlertEdit.html new file mode 100644 index 0000000..e26c9db --- /dev/null +++ b/src/apps/callflows/submodules/misc/views/setAlertEdit.html @@ -0,0 +1,13 @@ +
    +
    +
    + +
    +
    +
    + +
    +
    diff --git a/src/apps/callflows/submodules/misc/views/setcav-dialog.html b/src/apps/callflows/submodules/misc/views/setcav-dialog.html new file mode 100644 index 0000000..f159c10 --- /dev/null +++ b/src/apps/callflows/submodules/misc/views/setcav-dialog.html @@ -0,0 +1,26 @@ +
    + {{#monsterText}} + {{ i18n.callflows.setCav.help }} + {{/monsterText}} +
    + + + + + + + + + +
    {{i18n.callflows.setCav.key}}{{i18n.callflows.setCav.value}}
    +
    + {{telicon "plus--circle-o"}} +
    +
    + +
    + +
    + +
    +
    diff --git a/src/apps/callflows/submodules/misc/views/setcav-row.html b/src/apps/callflows/submodules/misc/views/setcav-row.html new file mode 100644 index 0000000..6f36377 --- /dev/null +++ b/src/apps/callflows/submodules/misc/views/setcav-row.html @@ -0,0 +1,9 @@ + + + + + + + + {{telicon "minus--circle-o" class="cav-remove-row"}} + diff --git a/src/apps/callflows/views/misc-sleep.html b/src/apps/callflows/submodules/misc/views/sleep.html similarity index 100% rename from src/apps/callflows/views/misc-sleep.html rename to src/apps/callflows/submodules/misc/views/sleep.html diff --git a/src/apps/callflows/views/misc-tts.html b/src/apps/callflows/submodules/misc/views/tts.html similarity index 100% rename from src/apps/callflows/views/misc-tts.html rename to src/apps/callflows/submodules/misc/views/tts.html diff --git a/src/apps/callflows/submodules/misc/views/webhook-callflowEdit.html b/src/apps/callflows/submodules/misc/views/webhook-callflowEdit.html new file mode 100644 index 0000000..76cca53 --- /dev/null +++ b/src/apps/callflows/submodules/misc/views/webhook-callflowEdit.html @@ -0,0 +1,66 @@ +
    + {{#monsterText}} + {{ i18n.callflows.webhook.help }} + {{/monsterText}} +
    +
    + + + + + +
    +
    +
    + +
    +
    diff --git a/src/apps/callflows/submodules/qubicle/qubicle.js b/src/apps/callflows/submodules/qubicle/qubicle.js index 85c3d24..a03e031 100644 --- a/src/apps/callflows/submodules/qubicle/qubicle.js +++ b/src/apps/callflows/submodules/qubicle/qubicle.js @@ -44,9 +44,13 @@ define(function(require) { }, edit: function(node, callback) { self.qubicleList(function(data) { - var popup_html = $(monster.template(self, 'qubicle-callflowEdit', { - items: _.sortBy(data, 'name'), - selected: node.getMetadata('id') || '' + var popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { + items: _.sortBy(data, 'name'), + selected: node.getMetadata('id') || '' + }, + submodule: 'qubicle' })), popup; diff --git a/src/apps/callflows/views/qubicle-callflowEdit.html b/src/apps/callflows/submodules/qubicle/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/qubicle-callflowEdit.html rename to src/apps/callflows/submodules/qubicle/views/callflowEdit.html diff --git a/src/apps/callflows/submodules/resource/resource.js b/src/apps/callflows/submodules/resource/resource.js index c7538ee..bb62f08 100644 --- a/src/apps/callflows/submodules/resource/resource.js +++ b/src/apps/callflows/submodules/resource/resource.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -30,11 +30,11 @@ define(function(require){ ], isUsable: 'true', weight: 140, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -54,22 +54,26 @@ define(function(require){ ], isUsable: 'true', weight: 150, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self, 'resource-account_carrier', { - data_resource: { - 'hunt_account_id': node.getMetadata('hunt_account_id') || '', - } + popup_html = $(self.getTemplate({ + name: 'account_carrier', + data: { + data_resource: { + 'hunt_account_id': node.getMetadata('hunt_account_id') || '' + } + }, + submodule: 'resource' })); $('#add', popup_html).click(function() { var hunt_id = $('#hunt_account_id', popup_html).val(); - if(hunt_id) { + if (hunt_id) { node.setMetadata('hunt_account_id', hunt_id); } @@ -79,8 +83,8 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().callflows.resource.account_carrier_title, beforeClose: function() { - if(typeof callback == 'function') { - callback(); + if (typeof callback === 'function') { + callback(); } } }); diff --git a/src/apps/callflows/views/resource-account_carrier.html b/src/apps/callflows/submodules/resource/views/account_carrier.html similarity index 100% rename from src/apps/callflows/views/resource-account_carrier.html rename to src/apps/callflows/submodules/resource/views/account_carrier.html diff --git a/src/apps/callflows/submodules/temporalset/temporalset.css b/src/apps/callflows/submodules/temporalset/temporalset.css index 7dc20ed..b3969a3 100644 --- a/src/apps/callflows/submodules/temporalset/temporalset.css +++ b/src/apps/callflows/submodules/temporalset/temporalset.css @@ -1,5 +1,6 @@ .callflows-port #temporalset-form .items-selector-wrapper { width: 535px; + margin-left: 99px; } .callflows-port .warning-no-save { diff --git a/src/apps/callflows/submodules/temporalset/temporalset.js b/src/apps/callflows/submodules/temporalset/temporalset.js index 533893a..1d11fda 100644 --- a/src/apps/callflows/submodules/temporalset/temporalset.js +++ b/src/apps/callflows/submodules/temporalset/temporalset.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'); @@ -168,7 +168,11 @@ define(function(require){ temporalsetRender: function(data, target, callbacks) { var self = this, - temporalset_html = $(monster.template(self, 'temporalset-callflowEdit', data)), + temporalset_html = $(self.getTemplate({ + name: 'callflowEdit', + data: data, + submodule: 'temporalset' + })), temporalsetForm = temporalset_html.find('#temporalset-form'), widgetRules = self.temporalSetFormatRules(data); @@ -280,7 +284,9 @@ define(function(require){ resource: 'temporalRule.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); @@ -295,7 +301,9 @@ define(function(require){ resource: 'temporalSet.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); diff --git a/src/apps/callflows/views/temporalset-callflowEdit.html b/src/apps/callflows/submodules/temporalset/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/temporalset-callflowEdit.html rename to src/apps/callflows/submodules/temporalset/views/callflowEdit.html diff --git a/src/apps/callflows/submodules/timeofday/timeofday.css b/src/apps/callflows/submodules/timeofday/timeofday.css index 9b131d5..04ee1d6 100644 --- a/src/apps/callflows/submodules/timeofday/timeofday.css +++ b/src/apps/callflows/submodules/timeofday/timeofday.css @@ -47,7 +47,6 @@ position: absolute; } - .callflows-port #timeofday-form .time-wrapper-field .time-wrapper { width: 233px; padding: 0; @@ -74,4 +73,4 @@ .callflows-port #timeofday-form .timepicker { width: 80px; margin: 0 10px; -} \ No newline at end of file +} diff --git a/src/apps/callflows/submodules/timeofday/timeofday.js b/src/apps/callflows/submodules/timeofday/timeofday.js index 71c4318..166024f 100644 --- a/src/apps/callflows/submodules/timeofday/timeofday.js +++ b/src/apps/callflows/submodules/timeofday/timeofday.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'), @@ -16,12 +16,11 @@ define(function(require){ var self = this, normalized_data = self.timeofdayNormalizeData($.extend(true, {}, data.data, form_data)); - if(typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { self.temporalRuleUpdate(normalized_data, function(_data, status) { success && success(_data, status, 'update'); }); - } - else { + } else { self.temporalRuleCreate(normalized_data, function(_data, status) { success & success(_data, status, 'create'); }); @@ -42,14 +41,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -70,7 +69,7 @@ define(function(require){ timeofdayEdit: function(data, _parent, _target, _callbacks, data_defaults) { var self = this, parent = _parent || $('#timeofday-content'), - target = _target || $('#timeofday-view', parent) + target = _target || $('#timeofday-view', parent), _callbacks = _callbacks || {}, callbacks = { save_success: _callbacks.save_success, @@ -127,8 +126,8 @@ define(function(require){ cycle: [ { id: 'weekly', value: 'Weekly' }, - { id: 'monthly', value:'Monthly' }, - { id: 'yearly', value:'Yearly' } + { id: 'monthly', value: 'Monthly' }, + { id: 'yearly', value: 'Yearly' } ], ordinals: [ @@ -160,7 +159,7 @@ define(function(require){ } }; - if(typeof data == 'object' && data.id) { + if (typeof data === 'object' && data.id) { self.temporalRuleGet(data.id, function(_data, status) { var oldFormatData = { data: _data }; @@ -179,20 +178,23 @@ define(function(require){ callbacks.after_render(); } }); - } - else { + } else { self.timeofdayRender(defaults, target, callbacks); - if(typeof callbacks.after_render == 'function') { + if (typeof callbacks.after_render === 'function') { callbacks.after_render(); } } }, - timeofdayRender: function(data, target, callbacks){ + timeofdayRender: function(data, target, callbacks) { var self = this, - wday, - timeofday_html = $(monster.template(self, 'timeofday-callflowEdit', data)), + timeofday_html = $(self.getTemplate({ + name: 'callflowEdit', + data: data, + submodule: 'timeofday' + })), + selectedWdays = data.data.wdays.length, _after_render, timeofdayForm = timeofday_html.find('#timeofday-form'); @@ -230,38 +232,47 @@ define(function(require){ $('#weekdays', timeofday_html).hide(); $('#specific_day', timeofday_html).hide(); - if(data.data.id == undefined) { + if (data.data.id === undefined) { $('#weekly_every', timeofday_html).show(); $('#days_checkboxes', timeofday_html).show(); } else { - if(data.data.cycle == 'monthly') { + if (data.data.cycle === 'monthly') { $('#monthly_every', timeofday_html).show(); $('#ordinal', timeofday_html).show(); - if(data.data.days != undefined && data.data.days[0] != undefined) { + if (data.data.days !== undefined && data.data.days[0] !== undefined) { $('#specific_day', timeofday_html).show(); } else { $('#weekdays', timeofday_html).show(); } - } else if(data.data.cycle == 'yearly') { + } else if (data.data.cycle === 'yearly') { $('#yearly_every', timeofday_html).show(); $('#ordinal', timeofday_html).show(); - if(data.data.days != undefined && data.data.days[0] != undefined) { + if (data.data.days !== undefined && data.data.days[0] !== undefined) { $('#specific_day', timeofday_html).show(); } else { $('#weekdays', timeofday_html).show(); } - } else if(data.data.cycle = 'weekly') { + } else if (data.data.cycle === 'weekly') { $('#weekly_every', timeofday_html).show(); $('#days_checkboxes', timeofday_html).show(); } } $('.fake_checkbox', timeofday_html).click(function() { + var $this = $(this), + toCheck = !$this.hasClass('checked'); + $(this).toggleClass('checked'); + + if (toCheck) { + selectedWdays += 1; + } else { + selectedWdays -= 1; + } }); $('#ordinal', timeofday_html).change(function() { - if($(this).val() == 'every') { + if ($(this).val() === 'every') { $('#weekdays', timeofday_html).hide(); $('#specific_day', timeofday_html).show(); } else { @@ -271,6 +282,8 @@ define(function(require){ }); $('#cycle', timeofday_html).change(function() { + var $this = $(this); + $('#yearly_every', timeofday_html).hide(); $('#monthly_every', timeofday_html).hide(); $('#weekly_every', timeofday_html).hide(); @@ -279,35 +292,29 @@ define(function(require){ $('#weekdays', timeofday_html).hide(); $('#specific_day', timeofday_html).hide(); - switch($(this).val()) { - case 'yearly': - $('#yearly_every', timeofday_html).show(); - $('#ordinal', timeofday_html).show(); - if($('#ordinal', timeofday_html).val() == 'every') { - //$('#weekdays', timeofday_html).hide(); - $('#specific_day', timeofday_html).show(); - } else { - $('#weekdays', timeofday_html).show(); - //$('#specific_day', timeofday_html).hide(); - } - break; - - case 'monthly': - $('#monthly_every', timeofday_html).show(); - $('#ordinal', timeofday_html).show(); - if($('#ordinal', timeofday_html).val() == 'every') { - //$('#weekdays', timeofday_html).hide(); - $('#specific_day', timeofday_html).show(); - } else { - $('#weekdays', timeofday_html).show(); - //$('#specific_day', timeofday_html).hide(); - } - break; - - case 'weekly': - $('#weekly_every', timeofday_html).show(); - $('#days_checkboxes', timeofday_html).show(); - break; + if ($this.val() === 'yearly') { + $('#yearly_every', timeofday_html).show(); + $('#ordinal', timeofday_html).show(); + if ($('#ordinal', timeofday_html).val() === 'every') { + //$('#weekdays', timeofday_html).hide(); + $('#specific_day', timeofday_html).show(); + } else { + $('#weekdays', timeofday_html).show(); + //$('#specific_day', timeofday_html).hide(); + } + } else if ($this.val() === 'monthly') { + $('#monthly_every', timeofday_html).show(); + $('#ordinal', timeofday_html).show(); + if ($('#ordinal', timeofday_html).val() === 'every') { + //$('#weekdays', timeofday_html).hide(); + $('#specific_day', timeofday_html).show(); + } else { + $('#weekdays', timeofday_html).show(); + //$('#specific_day', timeofday_html).hide(); + } + } else if ($this.val() === 'weekly') { + $('#weekly_every', timeofday_html).show(); + $('#days_checkboxes', timeofday_html).show(); } }); @@ -316,10 +323,15 @@ define(function(require){ var $this = $(this); - if(!$this.hasClass('disabled')) { - $this.addClass('disabled'); + if (!$this.hasClass('disabled')) { + if ($('#cycle', timeofday_html).val() === 'weekly' && selectedWdays === 0) { + monster.ui.toast({ + type: 'warning', + message: self.i18n.active().callflows.timeofday.toastr.warning.missingDay + }); + } else if (monster.ui.valid(timeofdayForm)) { + $this.addClass('disabled'); - if(monster.ui.valid(timeofdayForm)) { var form_data = monster.ui.getFormData('timeofday-form'); form_data.wdays = []; @@ -329,13 +341,12 @@ define(function(require){ form_data.wdays.push($(this).data('value')); }); - form_data.interval = $('#cycle', timeofday_html).val() == 'monthly' ? $('#interval_month', timeofday_html).val() : $('#interval_week', timeofday_html).val(); + form_data.interval = $('#cycle', timeofday_html).val() === 'monthly' ? $('#interval_month', timeofday_html).val() : $('#interval_week', timeofday_html).val(); form_data.start_date = timeofday_html.find('#start_date').datepicker('getDate'); form_data = self.timeofdayCleanFormData(form_data); self.timeofdaySave(form_data, data, callbacks.save_success); - } - else { + } else { $this.removeClass('disabled'); monster.ui.alert('error', self.i18n.active().callflows.timeofday.there_were_errors_on_the_form); } @@ -360,7 +371,7 @@ define(function(require){ _after_render = callbacks.after_render; callbacks.after_render = function() { - if(typeof _after_render == 'function') { + if (typeof _after_render === 'function') { _after_render(); } }; @@ -375,37 +386,36 @@ define(function(require){ timeStart = form_data.extra.allDay ? '0:00' : form_data.extra.timeofday.from, timeEnd = form_data.extra.allDay ? '24:00' : form_data.extra.timeofday.to; - if(form_data.cycle != 'weekly' && form_data.weekday != undefined) { + if (form_data.cycle !== 'weekly' && form_data.weekday !== undefined) { form_data.wdays = []; form_data.wdays.push(form_data.weekday); } $.each(form_data.wdays, function(i, val) { - if(val) { - if(val == 'wednesday') { + if (val) { + if (val === 'wednesday') { val = 'wensday'; } wdays.push(val); } }); - if(wdays.length > 0 && wdays[0] == 'sunday') { + if (wdays.length > 0 && wdays[0] === 'sunday') { wdays.push(wdays.shift()); } form_data.wdays = wdays; - if(form_data.start_date === '') { + if (form_data.start_date === '') { delete form_data.start_date; - } - else { + } else { form_data.start_date = monster.util.dateToGregorian(form_data.start_date); } form_data.time_window_start = parseInt(monster.util.timeToSeconds(timeStart)); form_data.time_window_stop = parseInt(monster.util.timeToSeconds(timeEnd)); - if(form_data.month) { + if (form_data.month) { form_data.month = parseInt(form_data.month); } @@ -415,22 +425,21 @@ define(function(require){ }, timeofdayNormalizeData: function(form_data) { - if(form_data.cycle == 'weekly') { + if (form_data.cycle === 'weekly') { delete form_data.ordinal; delete form_data.days; delete form_data.month; - } - else { - form_data.cycle == 'yearly' ? delete form_data.interval : delete form_data.month; - form_data.ordinal != 'every' ? delete form_data.days : delete form_data.wdays; + } else { + form_data.cycle === 'yearly' ? delete form_data.interval : delete form_data.month; + form_data.ordinal !== 'every' ? delete form_data.days : delete form_data.wdays; } delete form_data.time; delete form_data.weekday; - if(form_data.enabled === "true") { + if (form_data.enabled === 'true') { form_data.enabled = true; - } else if(form_data.enabled === "false") { + } else if (form_data.enabled === 'false') { form_data.enabled = false; } else { delete form_data.enabled; @@ -469,10 +478,10 @@ define(function(require){ data.data.showSave = true; data.data.showDelete = data.data.id ? true : false; - if(data.data.hasOwnProperty('ui_metadata') && data.data.ui_metadata.hasOwnProperty('origin') && data.data.ui_metadata.origin === 'voip') { + if (data.data.hasOwnProperty('ui_metadata') && data.data.ui_metadata.hasOwnProperty('origin') && data.data.ui_metadata.origin === 'voip') { data.data.showSave = false; - if(!monster.util.isSuperDuper()) { + if (!monster.util.isSuperDuper()) { data.data.showDelete = false; } } @@ -482,8 +491,8 @@ define(function(require){ timeofdayMigrateData: function(data) { // Check for spelling ;) - if('wdays' in data.data && (wday = $.inArray('wensday', data.data.wdays)) > -1) { - data.data.wdays[wday] = 'wednesday'; + if ('wdays' in data.data && $.inArray('wensday', data.data.wdays) > -1) { + data.data.wdays[data.data.wdays.indexOf('wensday')] = 'wednesday'; } return data; @@ -530,9 +539,13 @@ define(function(require){ var popup, popup_html; - popup_html = $(monster.template(self, 'timeofday-callflowKey', { - items: formattedData, - selected: child_node.key + popup_html = $(self.getTemplate({ + name: 'callflowKey', + data: { + items: formattedData, + selected: child_node.key + }, + submodule: 'timeofday' })); $('.inline_action', popup_html).click(function(ev) { @@ -586,9 +599,13 @@ define(function(require){ edit: function(node, callback) { var popup, popup_html; - popup_html = $(monster.template(self, 'timeofday-callflowTimezone', { - items: {}, - selected: {} + popup_html = $(self.getTemplate({ + name: 'callflowTimezone', + data: { + items: {}, + selected: {} + }, + submodule: 'timeofday' })); timezone.populateDropdown($('#timezone_selector', popup_html), node.getMetadata('timezone') || 'inherit', {inherit: self.i18n.active().defaultTimezone}); @@ -637,40 +654,42 @@ define(function(require){ ], isUsable: 'true', weight: 20, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { self.temporalRuleList(function(listRules) { var popup, popup_html, - rules, + rules = node.getMetadata('rules'), unselected_rules = [], selected_rules = []; - if(rules = node.getMetadata('rules')) { + if (rules) { $.each(listRules, function(i, obj) { - if($.inArray(obj.id, rules) != -1) { + if ($.inArray(obj.id, rules) !== -1) { selected_rules.push(obj); - } - else { + } else { unselected_rules.push(obj); } }); - } - else { + } else { unselected_rules = listRules; } - popup_html = $(monster.template(self, 'timeofday-two_column', { - left: { - title: self.i18n.active().callflows.timeofday.unselected_time_of_day_rules, - items: unselected_rules + popup_html = $(self.getTemplate({ + name: 'two_column', + data: { + left: { + title: self.i18n.active().callflows.timeofday.unselected_time_of_day_rules, + items: unselected_rules + }, + right: { + title: self.i18n.active().callflows.timeofday.selected_time_of_day_rules, + items: selected_rules + } }, - right: { - title: self.i18n.active().callflows.timeofday.selected_time_of_day_rules, - items: selected_rules - } + submodule: 'timeofday' })); $('#add', popup_html).click(function() { @@ -688,7 +707,7 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().callflows.timeofday.disable_time_of_day_rules_title, beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -732,38 +751,42 @@ define(function(require){ ], isUsable: 'true', weight: 30, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { self.temporalRuleList(function(listRules) { - var popup, popup_html, rules, - unselected_rules = [], - selected_rules = []; + var popup, + popup_html, + rules = node.getMetadata('rules'), + unselected_rules = [], + selected_rules = []; - if(rules = node.getMetadata('rules')) { + if (rules) { $.each(listRules, function(i, obj) { - if($.inArray(obj.id, rules) != -1) { + if ($.inArray(obj.id, rules) !== -1) { selected_rules.push(obj); - } - else { + } else { unselected_rules.push(obj); } }); - } - else { + } else { unselected_rules = listRules; } - popup_html = $(monster.template(self, 'timeofday-two_column', { - left: { - title: self.i18n.active().callflows.timeofday.unselected_time_of_day_rules, - items: unselected_rules + popup_html = $(self.getTemplate({ + name: 'two_column', + data: { + left: { + title: self.i18n.active().callflows.timeofday.unselected_time_of_day_rules, + items: unselected_rules + }, + right: { + title: self.i18n.active().callflows.timeofday.selected_time_of_day_rules, + items: selected_rules + } }, - right: { - title: self.i18n.active().callflows.timeofday.selected_time_of_day_rules, - items: selected_rules - } + submodule: 'timeofday' })); $('#add', popup_html).click(function() { @@ -781,7 +804,7 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().callflows.timeofday.enable_time_of_day_rules, beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -825,30 +848,32 @@ define(function(require){ ], isUsable: 'true', weight: 40, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { self.temporalRuleList(function(listRules) { - var popup, popup_html, rules, - unselected_rules = [], - selected_rules = []; - - if(rules = node.getMetadata('rules')) { - $.each(listRules, function(i, obj) { - if($.inArray(obj.id, rules) != -1) { - selected_rules.push(obj); - } - else { - unselected_rules.push(obj); - } - }); - } - else { - unselected_rules = listRules; - } + var popup, + popup_html, + rules = node.getMetadata('rules'), + unselected_rules = [], + selected_rules = []; - popup_html = $(monster.template(self, 'timeofday-two_column', { + if (rules) { + $.each(listRules, function(i, obj) { + if ($.inArray(obj.id, rules) !== -1) { + selected_rules.push(obj); + } else { + unselected_rules.push(obj); + } + }); + } else { + unselected_rules = listRules; + } + + popup_html = $(self.getTemplate({ + name: 'two_column', + data: { left: { title: self.i18n.active().callflows.timeofday.unselected_time_of_day_rules, items: unselected_rules @@ -857,49 +882,50 @@ define(function(require){ title: self.i18n.active().callflows.timeofday.selected_time_of_day_rules, items: selected_rules } - })); + }, + submodule: 'timeofday' + })); - $('#add', popup_html).click(function() { - var _rules = []; + $('#add', popup_html).click(function() { + var _rules = []; - $('.right .connect li', popup_html).each(function() { - _rules.push($(this).data('id')); - }); + $('.right .connect li', popup_html).each(function() { + _rules.push($(this).data('id')); + }); - node.setMetadata('rules', _rules); + node.setMetadata('rules', _rules); - popup.dialog('close'); - }); + popup.dialog('close'); + }); - popup = monster.ui.dialog(popup_html, { - title: self.i18n.active().callflows.timeofday.reset_time_of_day_rules, - beforeClose: function() { - if(typeof callback == 'function') { - callback(); - } + popup = monster.ui.dialog(popup_html, { + title: self.i18n.active().callflows.timeofday.reset_time_of_day_rules, + beforeClose: function() { + if (typeof callback === 'function') { + callback(); } - }); + } + }); - /* Initialize the scrollpane AFTER it has rendered */ + /* Initialize the scrollpane AFTER it has rendered */ - //$('.scrollable', popup).jScrollPane(); + //$('.scrollable', popup).jScrollPane(); - $('.connect', popup).sortable({ - connectWith: $('.connect', popup), - zIndex: 2000, - helper: 'clone', - appendTo: $('.wrapper', popup), - scroll: false, - tolerance: 'pointer', - receive: function() { - //$('.scrollable', popup).data('jsp').reinitialise(); - }, - remove: function() { - //$('.scrollable', popup).data('jsp').reinitialise(); - } - }); - } - ); + $('.connect', popup).sortable({ + connectWith: $('.connect', popup), + zIndex: 2000, + helper: 'clone', + appendTo: $('.wrapper', popup), + scroll: false, + tolerance: 'pointer', + receive: function() { + //$('.scrollable', popup).data('jsp').reinitialise(); + }, + remove: function() { + //$('.scrollable', popup).data('jsp').reinitialise(); + } + }); + }); } } }); diff --git a/src/apps/callflows/views/timeofday-callflowEdit.html b/src/apps/callflows/submodules/timeofday/views/callflowEdit.html similarity index 100% rename from src/apps/callflows/views/timeofday-callflowEdit.html rename to src/apps/callflows/submodules/timeofday/views/callflowEdit.html diff --git a/src/apps/callflows/views/timeofday-callflowKey.html b/src/apps/callflows/submodules/timeofday/views/callflowKey.html similarity index 100% rename from src/apps/callflows/views/timeofday-callflowKey.html rename to src/apps/callflows/submodules/timeofday/views/callflowKey.html diff --git a/src/apps/callflows/views/timeofday-callflowTimezone.html b/src/apps/callflows/submodules/timeofday/views/callflowTimezone.html similarity index 100% rename from src/apps/callflows/views/timeofday-callflowTimezone.html rename to src/apps/callflows/submodules/timeofday/views/callflowTimezone.html diff --git a/src/apps/callflows/views/timeofday-two_column.html b/src/apps/callflows/submodules/timeofday/views/two_column.html similarity index 100% rename from src/apps/callflows/views/timeofday-two_column.html rename to src/apps/callflows/submodules/timeofday/views/two_column.html diff --git a/src/apps/callflows/submodules/user/user.css b/src/apps/callflows/submodules/user/user.css index 81ed2a2..eb57dcd 100644 --- a/src/apps/callflows/submodules/user/user.css +++ b/src/apps/callflows/submodules/user/user.css @@ -16,6 +16,8 @@ } .callflows-port #user-form #equipment .help_box { + color: #333333; + line-height: 12px; } .callflows-port #user-form #equipment .add_device { diff --git a/src/apps/callflows/submodules/user/user.js b/src/apps/callflows/submodules/user/user.js index 0a5a576..b0bef32 100644 --- a/src/apps/callflows/submodules/user/user.js +++ b/src/apps/callflows/submodules/user/user.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'), @@ -17,10 +17,10 @@ define(function(require){ userDefineActions: function(args) { var self = this, - callflow_nodes= args.actions; + callflow_nodes = args.actions; $.extend(callflow_nodes, { - 'user[id=*]': { + 'user[id=*]': { name: self.i18n.active().callflows.user.user, icon: 'user', category: self.i18n.active().oldCallflows.basic_cat, @@ -41,7 +41,7 @@ define(function(require){ var id = node.getMetadata('id'), returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } @@ -55,25 +55,28 @@ define(function(require){ this.name = this.first_name + ' ' + this.last_name; }); - popup_html = $(monster.template(self, 'user-callflowEdit' , { - can_call_self: node.getMetadata('can_call_self') || false, - parameter: { - name: 'timeout (s)', - value: node.getMetadata('timeout') || '20' + popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { + can_call_self: node.getMetadata('can_call_self') || false, + parameter: { + name: 'timeout (s)', + value: node.getMetadata('timeout') || '20' + }, + objects: { + items: _.sortBy(users, 'name'), + selected: node.getMetadata('id') || '' + } }, - objects: { - items: _.sortBy(users, 'name'), - selected: node.getMetadata('id') || '' - } + submodule: 'user' })); - if($('#user_selector option:selected', popup_html).val() == undefined) { + if ($('#user_selector option:selected', popup_html).val() === undefined) { $('#edit_link', popup_html).hide(); } $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#user_selector', popup_html).val() } : {}; + var _data = ($(this).data('action') === 'edit') ? { id: $('#user_selector', popup_html).val() } : {}; ev.preventDefault(); @@ -104,7 +107,7 @@ define(function(require){ popup = monster.ui.dialog(popup_html, { title: self.i18n.active().callflows.user.select_user, beforeClose: function() { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -116,7 +119,9 @@ define(function(require){ resource: 'user.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -142,11 +147,11 @@ define(function(require){ ], isUsable: 'true', weight: 10, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -168,11 +173,11 @@ define(function(require){ ], isUsable: 'true', weight: 20, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -194,11 +199,11 @@ define(function(require){ ], isUsable: 'true', weight: 30, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -227,14 +232,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -310,7 +315,8 @@ define(function(require){ softphone: self.i18n.active().callflows.user.softphone_type, sip_uri: self.i18n.active().callflows.user.sip_uri_type }, - call_restriction: {} + call_restriction: {}, + canImpersonate: monster.util.canImpersonate(self.accountId) } }; @@ -322,10 +328,12 @@ define(function(require){ resource: 'numbers.listClassifiers', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(_data_classifiers, status) { - if('data' in _data_classifiers) { + if ('data' in _data_classifiers) { $.each(_data_classifiers.data, function(k, v) { defaults.field_data.call_restriction[k] = { friendly_name: v.friendly_name @@ -343,10 +351,12 @@ define(function(require){ resource: 'media.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(_data, status) { - if(_data.data) { + if (_data.data) { _data.data.unshift( { id: '', @@ -370,22 +380,21 @@ define(function(require){ }); }, user_get: function(callback) { - if(typeof data == 'object' && data.id) { + if (typeof data === 'object' && data.id) { self.userGet(data.id, function(_data, status) { self.userMigrateData(_data); callback(null, _data); }); - } - else { - self.random_id = $.md5(monster.util.randomString(10)+new Date().toString()); + } else { + self.random_id = monster.md5(monster.util.randomString(10) + new Date().toString()); defaults.field_data.new_user = self.random_id; callback(null, defaults); } }, user_hotdesks: function(callback) { - if(typeof data == 'object' && data.id) { + if (typeof data === 'object' && data.id) { self.callApi({ resource: 'user.hotdesks', data: { @@ -400,7 +409,7 @@ define(function(require){ defaults.field_data.device_list[v.device_id] = { name: v.device_name }; }); - if($.isEmptyObject(defaults.field_data.device_list)) { + if ($.isEmptyObject(defaults.field_data.device_list)) { delete defaults.field_data.device_list; } @@ -410,17 +419,16 @@ define(function(require){ //callback({api_name: 'Hotdesk'}, _data); callback(null, defaults); } - }) - } - else { + }); + } else { callback(null, defaults); } } }, function(err, results) { var render_data = defaults; - if(typeof data === 'object' && data.id) { - if(results.user_get.hasOwnProperty('call_restriction')) { + if (typeof data === 'object' && data.id) { + if (results.user_get.hasOwnProperty('call_restriction')) { $.each(results.user_get.call_restriction, function(k, v) { if (defaults.field_data.call_restriction.hasOwnProperty(k)) { defaults.field_data.call_restriction[k].action = v.action; @@ -448,7 +456,7 @@ define(function(require){ self.userRender(render_data, target, callbacks); - if(typeof callbacks.after_render == 'function') { + if (typeof callbacks.after_render === 'function') { callbacks.after_render(); } }); @@ -456,9 +464,14 @@ define(function(require){ userRender: function(data, target, callbacks) { var self = this, - user_html = $(monster.template(self, 'user-edit', data)), + user_html = $(self.getTemplate({ + name: 'edit', + data: _.merge({ + showPAssertedIdentity: monster.config.whitelabel.showPAssertedIdentity + }, data), + submodule: 'user' + })), user_form = user_html.find('#user-form'), - data_devices, hotdesk_pin = $('.hotdesk_pin', user_html), hotdesk_pin_require = $('#hotdesk_require_pin', user_html); @@ -466,7 +479,7 @@ define(function(require){ monster.ui.validate(user_form, { rules: { - "extra.shoutcastUrl": { + 'extra.shoutcastUrl': { protocol: true }, username: { @@ -478,13 +491,13 @@ define(function(require){ required: true, minlength: 1, maxlength: 256, - regex: /^[0-9a-zA-Z\s\-\']+$/ + regex: /^[0-9a-zA-Z\s\-']+$/ }, last_name: { required: true, minlength: 1, maxlength: 256, - regex: /^[0-9a-zA-Z\s\-\']+$/ + regex: /^[0-9a-zA-Z\s\-']+$/ }, email: { @@ -501,14 +514,17 @@ define(function(require){ equalTo: '#pwd_mngt_pwd1' }, 'hotdesk.pin': { regex: /^[0-9]*$/ }, - 'hotdesk.id': { regex: /^[0-9\+\#\*]*$/ }, - call_forward_number: { regex: /^[\+]?[0-9]*$/ }, - 'caller_id.internal.name': { regex: /^[0-9A-Za-z ,]{0,30}$/ }, + 'hotdesk.id': { regex: /^[0-9+#*]*$/ }, + call_forward_number: { regex: /^[+]?[0-9]*$/ }, + 'caller_id.internal.name': { maxlength: 30 }, 'caller_id.external.name': { regex: /^[0-9A-Za-z ,]{0,30}$/ }, - 'caller_id.internal.number': { regex: /^[\+]?[0-9\s\-\.\(\)]*$/ }, - 'caller_id.external.number': { regex: /^[\+]?[0-9\s\-\.\(\)]*$/ }, 'caller_id.emergency.name': { regex: /^[0-9A-Za-z ,]{0,30}$/ }, - 'caller_id.emergency.number': { regex: /^[\+]?[0-9\s\-\.\(\)]*$/ } + 'caller_id.asserted.name': { regex: /^[0-9A-Za-z ,]{0,30}$/ }, + 'caller_id.internal.number': { regex: /^[+]?[0-9\s\-.()]*$/ }, + 'caller_id.external.number': { regex: /^[+]?[0-9\s\-.()]*$/ }, + 'caller_id.emergency.number': { regex: /^[+]?[0-9\s\-.()]*$/ }, + 'caller_id.asserted.number': { phoneNumber: true }, + 'caller_id.asserted.realm': { realm: true } }, messages: { username: { regex: self.i18n.active().callflows.user.validation.username }, @@ -519,15 +535,29 @@ define(function(require){ 'caller_id.internal.name': { regex: self.i18n.active().callflows.user.validation.caller_id.name }, 'caller_id.external.name': { regex: self.i18n.active().callflows.user.validation.caller_id.name }, 'caller_id.emergency.name': { regex: self.i18n.active().callflows.user.validation.caller_id.name }, + 'caller_id.asserted.name': { regex: self.i18n.active().callflows.user.validation.caller_id.name }, 'caller_id.internal.number': { regex: self.i18n.active().callflows.user.validation.caller_id.number }, 'caller_id.external.number': { regex: self.i18n.active().callflows.user.validation.caller_id.number }, - 'caller_id.emergency.number': { regex: self.i18n.active().callflows.user.validation.caller_id.number } + 'caller_id.emergency.number': { regex: self.i18n.active().callflows.user.validation.caller_id.number }, + 'caller_id.asserted.number': { regex: self.i18n.active().callflows.user.validation.caller_id.number }, + 'caller_id.asserted.realm': { regex: self.i18n.active().callflows.user.validation.caller_id.realm } } }); - timezone.populateDropdown($('#timezone', user_html), data.data.timezone||'inherit', {inherit: self.i18n.active().defaultTimezone}); + timezone.populateDropdown( + $('#timezone', user_html), + _.get(data.data, 'timezone', 'inherit'), + { + inherit: self.i18n.active().defaultTimezone + } + ); + + user_html.find('input[data-mask]').each(function() { + var $this = $(this); + monster.ui.mask($this, $this.data('mask')); + }); - if (data.data.id === monster.apps.auth.userId){ + if (data.data.id === monster.apps.auth.userId) { $('.user-delete', user_html).hide(); } @@ -544,33 +574,82 @@ define(function(require){ hotdesk_pin_require.is(':checked') ? hotdesk_pin.show() : hotdesk_pin.hide(); + if (!$('#music_on_hold_media_id', user_html).val()) { + $('#edit_link_media', user_html).hide(); + } + + self.userBindEvents({ + template: user_html, + userForm: user_form, + hotdeskPin: hotdesk_pin, + hotdeskPinRequire: hotdesk_pin_require, + data: data, + callbacks: callbacks + }); + + target + .empty() + .append(user_html); + }, + + /** + * Bind events for the user edit template + * @param {Object} args + * @param {jQuery} args.template + * @param {jQuery} args.userForm + * @param {jQuery} args.hotdeskPin + * @param {jQuery} args.hotdeskPinRequire + * @param {Object} args.data + * @param {Object} args.callbacks + * @param {Function} args.callbacks.save_success + * @param {Function} args.callbacks.save_error + * @param {Function} args.callbacks.delete_success + * @param {Function} args.callbacks.delete_error + */ + userBindEvents: function(args) { + var self = this, + user_html = args.template, + user_form = args.userForm, + hotdesk_pin = args.hotdeskPin, + hotdesk_pin_require = args.hotdeskPinRequire, + data = args.data, + callbacks = args.callbacks, + data_devices; + hotdesk_pin_require.change(function() { $(this).is(':checked') ? hotdesk_pin.show('blind') : hotdesk_pin.hide('blind'); }); + $('.user-impersonate', user_html).click(function(ev) { + monster.pub('auth.triggerImpersonateUser', { + userId: data.data.id, + userName: data.data.first_name + ' ' + data.data.last_name + }); + }); + $('.user-save', user_html).click(function(ev) { ev.preventDefault(); var $this = $(this); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { $this.addClass('disabled'); if (monster.ui.valid(user_form)) { var form_data = monster.ui.getFormData('user-form'); - if(form_data.enable_pin === false) { + if (form_data.enable_pin === false) { delete data.data.queue_pin; delete data.data.record_call; } - if(form_data.music_on_hold.media_id === 'shoutcast') { + if (form_data.music_on_hold.media_id === 'shoutcast') { form_data.music_on_hold.media_id = user_html.find('.shoutcast-url-input').val(); } self.userCleanFormData(form_data); - if('field_data' in data) { + if ('field_data' in data) { delete data.field_data; } @@ -580,50 +659,48 @@ define(function(require){ accountId: self.accountId }, success: function(_data, status) { - if(form_data.priv_level == 'admin') { + if (form_data.priv_level === 'admin') { form_data.apps = form_data.apps || {}; - if(!('voip' in form_data.apps) && $.inArray('voip', (_data.data.available_apps || [])) > -1) { - form_data.apps['voip'] = { + if (!('voip' in form_data.apps) && $.inArray('voip', (_data.data.available_apps || [])) > -1) { + form_data.apps.voip = { label: self.i18n.active().callflows.user.voip_services_label, icon: 'device', api_url: monster.config.api.default - } + }; } - } - else if(form_data.priv_level == 'user' && $.inArray('userportal', (_data.data.available_apps || [])) > -1) { + } else if (form_data.priv_level === 'user' && $.inArray('userportal', (_data.data.available_apps || [])) > -1) { form_data.apps = form_data.apps || {}; - if(!('userportal' in form_data.apps)) { - form_data.apps['userportal'] = { + if (!('userportal' in form_data.apps)) { + form_data.apps.userportal = { label: self.i18n.active().callflows.user.user_portal_label, icon: 'userportal', api_url: monster.config.api.default - } + }; } } self.userSave(form_data, data, function(data, status, action) { - if(action == 'create') { + if (action === 'create') { self.userAcquireDevice(data, function() { - if(typeof callbacks.save_success == 'function') { + if (typeof callbacks.save_success === 'function') { callbacks.save_success(data, status, action); } }, function() { - if(typeof callbacks.save_error == 'function') { + if (typeof callbacks.save_error === 'function') { callbacks.save_error(data, status, action); } }); - } - else { - if(typeof callbacks.save_success == 'function') { + } else { + if (typeof callbacks.save_success === 'function') { callbacks.save_success(data, status, action); } } - // }, winkstart.error_message.process_error(callbacks.save_error)); + }, function() { + $this.removeClass('disabled'); }); } }); - } - else { + } else { $this.removeClass('disabled'); monster.ui.alert(self.i18n.active().callflows.user.there_were_errors_on_the_form); } @@ -638,10 +715,6 @@ define(function(require){ }); }); - if(!$('#music_on_hold_media_id', user_html).val()) { - $('#edit_link_media', user_html).hide(); - } - $('#music_on_hold_media_id', user_html).change(function() { !$('#music_on_hold_media_id option:selected', user_html).val() ? $('#edit_link_media', user_html).hide() : $('#edit_link_media', user_html).show(); @@ -649,7 +722,7 @@ define(function(require){ }); $('.inline_action_media', user_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? { id: $('#music_on_hold_media_id', user_html).val() } : {}, + var _data = ($(this).data('action') === 'edit') ? { id: $('#music_on_hold_media_id', user_html).val() } : {}, _id = _data.id; ev.preventDefault(); @@ -657,20 +730,18 @@ define(function(require){ data: _data, callback: function(media) { /* Create */ - if(!_id) { - $('#music_on_hold_media_id', user_html).append('') + if (!_id) { + $('#music_on_hold_media_id', user_html).append(''); $('#music_on_hold_media_id', user_html).val(media.id); $('#edit_link_media', user_html).show(); - } - else { + } else { /* Update */ - if(media.hasOwnProperty('id')) { - $('#music_on_hold_media_id #'+ media.id, user_html).text(media.name); - } + if (media.hasOwnProperty('id')) { + $('#music_on_hold_media_id #' + media.id, user_html).text(media.name); /* Delete */ - else { - $('#music_on_hold_media_id #'+_id, user_html).remove(); + } else { + $('#music_on_hold_media_id #' + _id, user_html).remove(); $('#edit_link_media', user_html).hide(); } } @@ -690,10 +761,9 @@ define(function(require){ var defaults = {}; - if(!data.data.id) { + if (!data.data.id) { defaults.new_user = self.random_id; - } - else { + } else { defaults.owner_id = data.data.id; } @@ -739,10 +809,9 @@ define(function(require){ ev.preventDefault(); - if(!data.data.id) { + if (!data.data.id) { defaults.new_user = self.random_id; - } - else { + } else { defaults.owner_id = data.data.id; } @@ -762,69 +831,67 @@ define(function(require){ data_defaults: defaults }); }); - - (target) - .empty() - .append(user_html); }, userRenderList: function(parent, callback) { var self = this; self.userList(function(data, status) { - var map_crossbar_data = function(data) { - var new_list = []; - - if(data.length > 0) { - $.each(data, function(key, val) { - new_list.push({ - id: val.id, - title: (val.first_name && val.last_name) ? - val.last_name + ', ' + val.first_name : - '(no name)' - }); + var map_crossbar_data = function(data) { + var new_list = []; + + if (data.length > 0) { + $.each(data, function(key, val) { + new_list.push({ + id: val.id, + title: (val.first_name && val.last_name) ? val.last_name + ', ' + val.first_name : '(no name)' }); - } - - new_list.sort(function(a, b) { - return a.title.toLowerCase() < b.title.toLowerCase() ? -1 : 1; }); + } - return new_list; - }; - - // $('#user-listpanel', parent) - // .empty() - // .listpanel({ - // label: _t('user', 'users_label'), - // identifier: 'user-listview', - // new_entity_label: _t('user', 'add_user_label'), - // data: map_crossbar_data(data.data), - // publisher: monster.pub, - // notifyMethod: 'callflows.user.edit', - // notifyCreateMethod: 'callflows.user.edit', - // notifyParent: parent - // }); + new_list.sort(function(a, b) { + return a.title.toLowerCase() < b.title.toLowerCase() ? -1 : 1; + }); - callback && callback(); - } - ); + return new_list; + }; + + // $('#user-listpanel', parent) + // .empty() + // .listpanel({ + // label: _t('user', 'users_label'), + // identifier: 'user-listview', + // new_entity_label: _t('user', 'add_user_label'), + // data: map_crossbar_data(data.data), + // publisher: monster.pub, + // notifyMethod: 'callflows.user.edit', + // notifyCreateMethod: 'callflows.user.edit', + // notifyParent: parent + // }); + + callback && callback(); + }); }, userRenderDeviceList: function(data, parent) { var self = this, parent = $('#tab_devices', parent); - if(data.data.id) { + if (data.data.id) { var filter = data.data.new_user ? { filter_new_user: data.data.id } : { filter_owner_id: data.data.id }; self.userListDevice(filter, function(_data, status) { $('.rows', parent).empty(); - if(_data.length > 0) { + if (_data.length > 0) { $.each(_data, function(k, v) { v.display_type = data.field_data.device_types[v.device_type]; v.not_enabled = this.enabled === false ? true : false; - $('.rows', parent).append($(monster.template(self, 'user-deviceRow', v))); + $('.rows', parent) + .append($(self.getTemplate({ + name: 'deviceRow', + data: v, + submodule: 'user' + }))); }); self.callApi({ @@ -838,21 +905,27 @@ define(function(require){ }); } }); - } - else { - $('.rows', parent).append($(monster.template(self, 'user-deviceRow'))); + } else { + $('.rows', parent) + .append($(self.getTemplate({ + name: 'deviceRow', + submodule: 'user' + }))); } }); - } - else { - $('.rows', parent).empty() - .append($(monster.template(self, 'user-deviceRow'))); + } else { + $('.rows', parent) + .empty() + .append($(self.getTemplate({ + name: 'deviceRow', + submodule: 'user' + }))); } }, userMigrateData: function(data) { - if(!('priv_level' in data)) { - if('apps' in data && 'voip' in data.apps) { + if (!('priv_level' in data)) { + if ('apps' in data && 'voip' in data.apps) { data.priv_level = 'admin'; } else { data.priv_level = 'user'; @@ -870,76 +943,72 @@ define(function(require){ enabled = $checkbox.is(':checked'); self.userGetDevice(device_id, function(_data) { - if($.inArray(_data.device_type, ['cellphone', 'smartphone', 'landline']) > -1) { - _data.call_forward.enabled = enabled; + if ($.inArray(_data.device_type, ['cellphone', 'smartphone', 'landline']) > -1) { + _data.call_forward.enabled = enabled; + } + _data.enabled = enabled; + self.userUpdateDevice(device_id, _data, function(_data) { + $checkbox.removeAttr('disabled'); + if (_data.enabled === true) { + $('#' + _data.id + ' .column.third', parent).removeClass('disabled'); + } else { + $('#' + _data.id + ' .column.third', parent).addClass('disabled'); } - _data.enabled = enabled; - self.userUpdateDevice(device_id, _data, function(_data) { - $checkbox.removeAttr('disabled'); - if(_data.enabled === true) { - $('#'+ _data.id + ' .column.third', parent).removeClass('disabled'); - } - else { - $('#'+ _data.id + ' .column.third', parent).addClass('disabled'); - } - }, - function() { - $checkbox.removeAttr('disabled'); - enabled ? $checkbox.removeAttr('checked') : $checkbox.attr('checked', 'checked'); - } - ); - }, - function() { + }, function() { $checkbox.removeAttr('disabled'); enabled ? $checkbox.removeAttr('checked') : $checkbox.attr('checked', 'checked'); - } - ); + }); + }, function() { + $checkbox.removeAttr('disabled'); + enabled ? $checkbox.removeAttr('checked') : $checkbox.attr('checked', 'checked'); + }); }, userAcquireDevice: function(user_data, success, error) { var self = this, user_id = user_data.id; - if(self.random_id) { + if (self.random_id) { self.userListDevice({ filter_new_user: self.random_id }, function(_data, status) { var device_id; var array_length = _data.length; - if(array_length != 0) { - $.each(_data, function(k, v) { + if (array_length !== 0) { + $.each(_data, function(k) { device_id = this.id; self.userGetDevice(device_id, function(_data, status) { _data.owner_id = user_id; delete _data.new_user; self.userUpdateDevice(device_id, _data, function(_data, status) { - if(k == array_length - 1) { + if (k === array_length - 1) { success({}, status, 'create'); } }); }); }); - } - else { + } else { success({}, status, 'create'); } }); - } - else { + } else { success({}, status, 'create'); } }, - userCleanFormData: function(form_data){ - form_data.caller_id.internal.number = form_data.caller_id.internal.number.replace(/\s|\(|\)|\-|\./g,''); - form_data.caller_id.external.number = form_data.caller_id.external.number.replace(/\s|\(|\)|\-|\./g,''); - form_data.caller_id.emergency.number = form_data.caller_id.emergency.number.replace(/\s|\(|\)|\-|\./g,''); + userCleanFormData: function(form_data) { + form_data.caller_id.internal.number = form_data.caller_id.internal.number.replace(/\s|\(|\)|-|\./g, ''); + form_data.caller_id.external.number = form_data.caller_id.external.number.replace(/\s|\(|\)|-|\./g, ''); + form_data.caller_id.emergency.number = form_data.caller_id.emergency.number.replace(/\s|\(|\)|-|\./g, ''); + form_data.caller_id.asserted.number = _.isEmpty(form_data.caller_id.asserted.number) + ? '' // Need to keep the empty string so the new value is not lost when merging the form data with the original data + : monster.util.getFormatPhoneNumber(form_data.caller_id.asserted.number).e164Number; form_data.call_restriction.closed_groups = { action: form_data.extra.closed_groups ? 'deny' : 'inherit' }; - if(!form_data.hotdesk.require_pin) { + if (!form_data.hotdesk.require_pin) { delete form_data.hotdesk.pin; } - if(form_data.pwd_mngt_pwd1 != 'fakePassword') { + if (form_data.pwd_mngt_pwd1 !== 'fakePassword') { form_data.password = form_data.pwd_mngt_pwd1; } @@ -954,68 +1023,55 @@ define(function(require){ var self = this, normalized_data = self.userNormalizeData($.extend(true, {}, data.data, form_data)); - if(typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { self.userUpdate(normalized_data, function(_data, status) { - if(typeof success == 'function') { - success(_data, status, 'update'); - } - }, - function(_data, status) { - if(typeof error == 'function') { - error(_data, status, 'update'); - } + if (typeof success === 'function') { + success(_data, status, 'update'); } - ); - } - else { + }, function(_data, status) { + if (typeof error === 'function') { + error(_data, status, 'update'); + } + }); + } else { self.userCreate(normalized_data, function(_data, status) { - if(typeof success == 'function') { - success(_data, status, 'create'); - } - }, - function(_data, status) { - if(typeof error == 'function') { - error(_data, status, 'create'); - } + if (typeof success === 'function') { + success(_data, status, 'create'); + } + }, function(_data, status) { + if (typeof error === 'function') { + error(_data, status, 'create'); } - ); + }); } }, userNormalizeData: function(data) { - if($.isArray(data.directories)) { + var self = this; + + if ($.isArray(data.directories)) { data.directories = {}; } - $.each(data.caller_id, function(key, val) { - $.each(val, function(_key, _val) { - if(_val == '') { - delete val[_key]; - } - }); - - if($.isEmptyObject(val)) { - delete data.caller_id[key]; - } - }); + self.compactObject(data.caller_id); - if($.isEmptyObject(data.caller_id)) { + if (_.isEmpty(data.caller_id)) { delete data.caller_id; } - if(!data.music_on_hold.media_id) { + if (!data.music_on_hold.media_id) { delete data.music_on_hold.media_id; } - if(data.hotdesk.hasOwnProperty("enable")) { + if (data.hotdesk.hasOwnProperty('enable')) { delete data.hotdesk.enable; } - if(data.hotdesk.hasOwnProperty('log_out')) { + if (data.hotdesk.hasOwnProperty('log_out')) { var new_endpoint_ids = []; $.each(data.hotdesk.endpoint_ids, function(k, v) { - if(data.hotdesk.log_out.indexOf(v) < 0) { + if (data.hotdesk.log_out.indexOf(v) < 0) { new_endpoint_ids.push(v); } }); @@ -1025,26 +1081,25 @@ define(function(require){ delete data.hotdesk.log_out; } - if(data.hotdesk.hasOwnProperty('endpoint_ids') && data.hotdesk.endpoint_ids.length === 0) { + if (data.hotdesk.hasOwnProperty('endpoint_ids') && data.hotdesk.endpoint_ids.length === 0) { delete data.hotdesk.endpoint_ids; } - if(data.hasOwnProperty('call_forward') && data.call_forward.number === '') { + if (data.hasOwnProperty('call_forward') && data.call_forward.number === '') { delete data.call_forward.number; } - if(data.hasOwnProperty('presence_id') && data.presence_id === '') { + if (data.hasOwnProperty('presence_id') && data.presence_id === '') { delete data.presence_id; } - if(data.timezone && data.timezone === 'inherit') { + if (data.timezone && data.timezone === 'inherit') { delete data.timezone; } return data; }, - userList: function(callback) { var self = this; @@ -1052,7 +1107,9 @@ define(function(require){ resource: 'user.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); @@ -1075,7 +1132,7 @@ define(function(require){ }); }, - userCreate: function(data, callback) { + userCreate: function(data, callback, error) { var self = this; self.callApi({ @@ -1086,11 +1143,14 @@ define(function(require){ }, success: function(data) { callback && callback(data.data); + }, + error: function(data) { + error && error(data.data); } }); }, - userUpdate: function(data, callback) { + userUpdate: function(data, callback, error) { var self = this; self.callApi({ @@ -1102,6 +1162,9 @@ define(function(require){ }, success: function(data) { callback && callback(data.data); + }, + error: function(data) { + error && error(data.data); } }); }, @@ -1137,7 +1200,7 @@ define(function(require){ success: function(data) { callback && callback(data.data); } - }) + }); }, userGetDevice: function(deviceId, callbackSuccess, callbackError) { @@ -1155,7 +1218,7 @@ define(function(require){ error: function(data) { callbackError && callbackError(); } - }) + }); }, userUpdateDevice: function(deviceId, data, callbackSuccess, callbackError) { diff --git a/src/apps/callflows/views/user-callflowEdit.html b/src/apps/callflows/submodules/user/views/callflowEdit.html similarity index 95% rename from src/apps/callflows/views/user-callflowEdit.html rename to src/apps/callflows/submodules/user/views/callflowEdit.html index 32cdd2b..052c929 100644 --- a/src/apps/callflows/views/user-callflowEdit.html +++ b/src/apps/callflows/submodules/user/views/callflowEdit.html @@ -26,11 +26,11 @@
    - {{ i18n.callflows.user.allow_this_user_to_call_himself }} + {{ i18n.callflows.user.allow_this_user_to_call_themselves }}
    {{ i18n.callflows.user.when_you_check_this_box }}
    - \ No newline at end of file + diff --git a/src/apps/callflows/views/user-deviceRow.html b/src/apps/callflows/submodules/user/views/deviceRow.html similarity index 99% rename from src/apps/callflows/views/user-deviceRow.html rename to src/apps/callflows/submodules/user/views/deviceRow.html index bb50530..73e67d2 100644 --- a/src/apps/callflows/views/user-deviceRow.html +++ b/src/apps/callflows/submodules/user/views/deviceRow.html @@ -19,4 +19,4 @@
    {{ i18n.callflows.user.there_is_currently_no_devices }}
    {{/if}}
    -
    \ No newline at end of file + diff --git a/src/apps/callflows/views/user-edit.html b/src/apps/callflows/submodules/user/views/edit.html similarity index 92% rename from src/apps/callflows/views/user-edit.html rename to src/apps/callflows/submodules/user/views/edit.html index 92a0456..b2d05ff 100644 --- a/src/apps/callflows/views/user-edit.html +++ b/src/apps/callflows/submodules/user/views/edit.html @@ -86,18 +86,6 @@ -
  • - -
  • @@ -186,7 +174,7 @@
    - +

    @@ -202,7 +190,7 @@
    - +

    @@ -218,9 +206,34 @@
    - + +
    +
    +
    + + {{#if showPAssertedIdentity}} +

    {{ i18n.callflows.user.asserted }}

    +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + {{/if}}
    @@ -277,6 +290,11 @@
    +
    + {{#monsterText 'warning'}} + {{ i18n.callflows.accountSettings.musicOnHold.shoutcastURLWarning }} + {{/monsterText}} +
    @@ -630,8 +648,11 @@
    {{#if data.id}} + {{#if field_data.canImpersonate}} + + {{/if}} {{/if}}
    -
    \ No newline at end of file + diff --git a/src/apps/callflows/views/vmbox-callflowEdit.html b/src/apps/callflows/submodules/vmbox/views/callflowEdit.html similarity index 99% rename from src/apps/callflows/views/vmbox-callflowEdit.html rename to src/apps/callflows/submodules/vmbox/views/callflowEdit.html index 09cc79c..e5cf76f 100644 --- a/src/apps/callflows/views/vmbox-callflowEdit.html +++ b/src/apps/callflows/submodules/vmbox/views/callflowEdit.html @@ -24,4 +24,4 @@
    - \ No newline at end of file + diff --git a/src/apps/callflows/views/vmbox-edit.html b/src/apps/callflows/submodules/vmbox/views/edit.html similarity index 79% rename from src/apps/callflows/views/vmbox-edit.html rename to src/apps/callflows/submodules/vmbox/views/edit.html index 6ab820e..9f0ce6b 100644 --- a/src/apps/callflows/views/vmbox-edit.html +++ b/src/apps/callflows/submodules/vmbox/views/edit.html @@ -80,6 +80,27 @@ + +
    + +
    + + + + +
    +
    @@ -237,6 +258,44 @@
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    @@ -257,4 +316,4 @@
    - \ No newline at end of file + diff --git a/src/apps/callflows/submodules/vmbox/vmbox.js b/src/apps/callflows/submodules/vmbox/vmbox.js index a53d23c..c44b661 100644 --- a/src/apps/callflows/submodules/vmbox/vmbox.js +++ b/src/apps/callflows/submodules/vmbox/vmbox.js @@ -1,4 +1,4 @@ -define(function(require){ +define(function(require) { var $ = require('jquery'), _ = require('lodash'), monster = require('monster'), @@ -24,14 +24,14 @@ define(function(require){ save_success: function(_data) { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(_data); } }, delete_success: function() { popup.dialog('close'); - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback({ data: {} }); } }, @@ -103,12 +103,11 @@ define(function(require){ }); }, get_vmbox: function(callback) { - if(typeof data == 'object' && data.id) { + if (typeof data === 'object' && data.id) { self.vmboxGet(data.id, function(_data) { callback(null, _data); }); - } - else { + } else { callback(null, {}); } } @@ -116,13 +115,13 @@ define(function(require){ function(err, results) { var render_data = defaults; - if(typeof data === 'object' && data.id) { + if (typeof data === 'object' && data.id) { render_data = $.extend(true, defaults, { data: results.get_vmbox }); } self.vmboxRender(render_data, target, callbacks); - if(typeof callbacks.after_render == 'function') { + if (typeof callbacks.after_render === 'function') { callbacks.after_render(); } }); @@ -141,10 +140,14 @@ define(function(require){ vmboxRender: function(data, target, callbacks) { var self = this, formattedData = self.vmboxFormatData(data), - vmbox_html = $(monster.template(self, 'vmbox-edit', formattedData)), + vmbox_html = $(self.getTemplate({ + name: 'edit', + data: formattedData, + submodule: 'vmbox' + })), vmboxForm = vmbox_html.find('#vmbox-form'); - timezone.populateDropdown($('#timezone', vmbox_html), data.data.timezone||'inherit', {inherit: self.i18n.active().defaultTimezone}); + timezone.populateDropdown($('#timezone', vmbox_html), data.data.timezone || 'inherit', {inherit: self.i18n.active().defaultTimezone}); monster.ui.validate(vmboxForm, { rules: { @@ -172,9 +175,8 @@ define(function(require){ self.winkstartTabs(vmbox_html); - $('#owner_id', vmbox_html).change(function() { - if($(this).val()) { + if ($(this).val()) { self.callApi({ resource: 'user.get', data: { @@ -182,7 +184,7 @@ define(function(require){ userId: $(this).val() }, success: function(data) { - if('timezone' in data.data) { + if ('timezone' in data.data) { $('#timezone', vmbox_html).val(data.data.timezone); } } @@ -190,22 +192,21 @@ define(function(require){ } }); - if(!$('#owner_id', vmbox_html).val()) { + if (!$('#owner_id', vmbox_html).val()) { $('#edit_link', vmbox_html).hide(); } $('#owner_id', vmbox_html).change(function() { - if(!$('#owner_id option:selected', vmbox_html).val()) { + if (!$('#owner_id option:selected', vmbox_html).val()) { $('#edit_link', vmbox_html).hide(); $('#timezone', vmbox_html).val(timezone.getLocaleTimezone()); - } - else { - $('#edit_link', vmbox_html).show(); + } else { + $('#edit_link', vmbox_html).show(); } }); $('.inline_action', vmbox_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? { id: $('#owner_id', vmbox_html).val() } : {}, + var _data = ($(this).data('action') === 'edit') ? { id: $('#owner_id', vmbox_html).val() } : {}, _id = _data.id; ev.preventDefault(); @@ -214,22 +215,20 @@ define(function(require){ data: _data, callback: function(_data) { /* Create */ - if(!_id) { - $('#owner_id', vmbox_html).append('') + if (!_id) { + $('#owner_id', vmbox_html).append(''); $('#owner_id', vmbox_html).val(_data.id); $('#edit_link', vmbox_html).show(); $('#timezone', vmbox_html).val(_data.timezone); - } - else { + } else { /* Update */ - if('id' in _data) { - $('#owner_id #'+_data.data.id, vmbox_html).text(_data.first_name + ' ' + _data.last_name); + if ('id' in _data) { + $('#owner_id #' + _data.data.id, vmbox_html).text(_data.first_name + ' ' + _data.last_name); $('#timezone', vmbox_html).val(_data.timezone); - } - /* Delete */ - else { - $('#owner_id #'+_id, vmbox_html).remove(); + } else { + /* Delete */ + $('#owner_id #' + _id, vmbox_html).remove(); $('#edit_link', vmbox_html).hide(); $('#timezone', vmbox_html).val('America/Los_Angeles'); } @@ -238,7 +237,7 @@ define(function(require){ }); }); - if(!$('#media_unavailable', vmbox_html).val()) { + if (!$('#media_unavailable', vmbox_html).val()) { $('#edit_link_media', vmbox_html).hide(); } @@ -247,7 +246,7 @@ define(function(require){ }); $('.inline_action_media', vmbox_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? { id: $('#media_unavailable', vmbox_html).val() } : {}, + var _data = ($(this).data('action') === 'edit') ? { id: $('#media_unavailable', vmbox_html).val() } : {}, _id = _data.id; ev.preventDefault(); @@ -256,20 +255,18 @@ define(function(require){ data: _data, callback: function(_data) { /* Create */ - if(!_id) { - $('#media_unavailable', vmbox_html).append('') + if (!_id) { + $('#media_unavailable', vmbox_html).append(''); $('#media_unavailable', vmbox_html).val(_data.id); $('#edit_link_media', vmbox_html).show(); - } - else { + } else { /* Update */ - if('id' in _data) { - $('#media_unavailable #'+_data.id, vmbox_html).text(_data.name); - } - /* Delete */ - else { - $('#media_unavailable #'+_id, vmbox_html).remove(); + if ('id' in _data) { + $('#media_unavailable #' + _data.id, vmbox_html).text(_data.name); + } else { + /* Delete */ + $('#media_unavailable #' + _id, vmbox_html).remove(); $('#edit_link_media', vmbox_html).hide(); } } @@ -277,15 +274,51 @@ define(function(require){ }); }); + if (!$('#media_temporary_unavailable', vmbox_html).val()) { + $('#edit_link_temporary_media', vmbox_html).hide(); + } + + $('#media_temporary_unavailable', vmbox_html).change(function() { + !$('#media_temporary_unavailable option:selected', vmbox_html).val() ? $('#edit_link_temporary_media', vmbox_html).hide() : $('#edit_link_temporary_media', vmbox_html).show(); + }); + + $('.inline_action_temporary_media', vmbox_html).click(function(ev) { + var _data = ($(this).data('action') === 'edit') ? { id: $('#media_temporary_unavailable', vmbox_html).val() } : {}, + _id = _data.id; + + ev.preventDefault(); + + monster.pub('callflows.media.editPopup', { + data: _data, + callback: function(_data) { + /* Create */ + if (!_id) { + $('#media_temporary_unavailable', vmbox_html).append(''); + $('#media_temporary_unavailable', vmbox_html).val(_data.id); - var validateEmail = function (email) { - var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + $('#edit_link_temporary_media', vmbox_html).show(); + } else { + /* Update */ + if ('id' in _data) { + $('#media_temporary_unavailable #' + _data.id, vmbox_html).text(_data.name); + } else { + /* Delete */ + $('#media_temporary_unavailable #' + _id, vmbox_html).remove(); + $('#edit_link_temporary_media', vmbox_html).hide(); + } + } + } + }); + }); + + var validateEmail = function(email) { + var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); }, getRecipients = function() { var list = $('#recipients_list', vmbox_html).val().replace(/\s+/g, '').split(','); - return list.filter(function(email) { return validateEmail(email) }); + return list.filter(function(email) { return validateEmail(email); }); }; $('.vmbox-save', vmbox_html).click(function(ev) { @@ -293,23 +326,24 @@ define(function(require){ var $this = $(this); - if(!$this.hasClass('disabled')) { + if (!$this.hasClass('disabled')) { $this.addClass('disabled'); - if(monster.ui.valid(vmboxForm)) { + if (monster.ui.valid(vmboxForm)) { var form_data = monster.ui.getFormData('vmbox-form'); form_data.notify_email_addresses = getRecipients(); /* self.clean_form_data(form_data); */ - if('field_data' in data) { + if ('field_data' in data) { delete data.field_data; } - self.vmboxSave(form_data, data, callbacks.save_success); - } - else { + self.vmboxSave(form_data, data, callbacks.save_success, function() { + $this.removeClass('disabled'); + }); + } else { $this.removeClass('disabled'); } } @@ -332,36 +366,39 @@ define(function(require){ var self = this, normalized_data = self.vmboxNormalizeData($.extend(true, {}, data.data, form_data), form_data); - if(typeof data.data == 'object' && data.data.id) { + if (typeof data.data === 'object' && data.data.id) { self.vmboxUpdate(normalized_data, function(_data, status) { - if(typeof success == 'function') { + if (typeof success === 'function') { success(_data, status, 'update'); } - }); - } - else { + }, error); + } else { self.vmboxCreate(normalized_data, function(_data, status) { - if(typeof success == 'function') { + if (typeof success === 'function') { success(_data, status, 'create'); } - }); + }, error); } }, vmboxNormalizeData: function(mergedData, formData) { - if(!mergedData.owner_id) { + if (!mergedData.owner_id) { delete mergedData.owner_id; } - if(!mergedData.media.unavailable) { + if (!mergedData.media.unavailable) { delete mergedData.media.unavailable; } - if(mergedData.pin === '') { + if (!mergedData.media.temporary_unavailable) { + delete mergedData.media.temporary_unavailable; + } + + if (mergedData.pin === '') { delete mergedData.pin; } - if(mergedData.timezone && mergedData.timezone === 'inherit') { + if (mergedData.timezone && mergedData.timezone === 'inherit') { delete mergedData.timezone; } @@ -403,7 +440,7 @@ define(function(require){ var id = node.getMetadata('id'), returned_value = ''; - if(id in caption_map) { + if (id in caption_map) { returned_value = caption_map[id].name; } @@ -413,61 +450,65 @@ define(function(require){ var _this = this; self.vmboxList(function(data) { - var popup, popup_html; + var popup, popup_html; - popup_html = $(monster.template(self, 'vmbox-callflowEdit', { + popup_html = $(self.getTemplate({ + name: 'callflowEdit', + data: { items: _.sortBy(data, 'name'), selected: node.getMetadata('id') || '' - })); + }, + submodule: 'vmbox' + })); - if($('#vmbox_selector option:selected', popup_html).val() == undefined) { - $('#edit_link', popup_html).hide(); - } + if ($('#vmbox_selector option:selected', popup_html).val() === undefined) { + $('#edit_link', popup_html).hide(); + } - $('.inline_action', popup_html).click(function(ev) { - var _data = ($(this).data('action') == 'edit') ? - { id: $('#vmbox_selector', popup_html).val() } : {}; + $('.inline_action', popup_html).click(function(ev) { + var _data = ($(this).data('action') === 'edit') ? { id: $('#vmbox_selector', popup_html).val() } : {}; - ev.preventDefault(); + ev.preventDefault(); - self.vmboxPopupEdit({ - data: _data, - callback: function(vmbox) { - node.setMetadata('id', vmbox.id || 'null'); + self.vmboxPopupEdit({ + data: _data, + callback: function(vmbox) { + node.setMetadata('id', vmbox.id || 'null'); - node.caption = vmbox.name || ''; + node.caption = vmbox.name || ''; - popup.dialog('close'); - } - }); + popup.dialog('close'); + } }); + }); - $('#add', popup_html).click(function() { - node.setMetadata('id', $('#vmbox_selector', popup_html).val()); + $('#add', popup_html).click(function() { + node.setMetadata('id', $('#vmbox_selector', popup_html).val()); - node.caption = $('#vmbox_selector option:selected', popup_html).text(); + node.caption = $('#vmbox_selector option:selected', popup_html).text(); - popup.dialog('close'); - }); + popup.dialog('close'); + }); - popup = monster.ui.dialog(popup_html, { - title: self.i18n.active().callflows.vmbox.voicemail_title, - minHeight: '0', - beforeClose: function() { - if(typeof callback == 'function') { - callback(); - } + popup = monster.ui.dialog(popup_html, { + title: self.i18n.active().callflows.vmbox.voicemail_title, + minHeight: '0', + beforeClose: function() { + if (typeof callback === 'function') { + callback(); } - }); - } - ); + } + }); + }); }, listEntities: function(callback) { self.callApi({ resource: 'voicemail.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data, status) { callback && callback(data.data); @@ -477,7 +518,7 @@ define(function(require){ editEntity: 'callflows.vmbox.edit' }; - if(hasCategory) { + if (hasCategory) { action.category = self.i18n.active().oldCallflows.basic_cat; } @@ -510,11 +551,11 @@ define(function(require){ ], isUsable: 'true', weight: 120, - caption: function(node, caption_map) { + caption: function(node) { return ''; }, edit: function(node, callback) { - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback(); } } @@ -529,7 +570,9 @@ define(function(require){ resource: 'voicemail.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); @@ -552,7 +595,7 @@ define(function(require){ }); }, - vmboxCreate: function(data, callback) { + vmboxCreate: function(data, callback, error) { var self = this; self.callApi({ @@ -563,11 +606,14 @@ define(function(require){ }, success: function(data) { callback && callback(data.data); + }, + error: function(errorPayload, data, globalHandler) { + error && error(errorPayload); } }); }, - vmboxUpdate: function(data, callback) { + vmboxUpdate: function(data, callback, error) { var self = this; self.callApi({ @@ -579,6 +625,9 @@ define(function(require){ }, success: function(data) { callback && callback(data.data); + }, + error: function(errorPayload, data, globalHandler) { + error && error(errorPayload); } }); }, @@ -605,7 +654,9 @@ define(function(require){ resource: 'media.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); @@ -620,7 +671,9 @@ define(function(require){ resource: 'user.list', data: { accountId: self.accountId, - filters: { paginate:false } + filters: { + paginate: false + } }, success: function(data) { callback && callback(data.data); diff --git a/src/apps/callflows/views/accountSettings.html b/src/apps/callflows/views/accountSettings.html index a63bea2..25fcf79 100644 --- a/src/apps/callflows/views/accountSettings.html +++ b/src/apps/callflows/views/accountSettings.html @@ -19,20 +19,15 @@
    {{ i18n.callflows.accountSettings.callerId.titleInbound }}
    - +
    - +
    - +
    - +
    @@ -42,20 +37,20 @@
    {{ i18n.callflows.accountSettings.callerId.titleOutbound }}
    - +
    - +
    - +
    - + {{#each numberList}} {{/each}} - +
    @@ -65,24 +60,50 @@
    {{ i18n.callflows.accountSettings.callerId.titleEmergency }}
    - +
    - +
    - +
    - + {{#each numberList}} {{/each}} - +
    + + {{#if showPAssertedIdentity}} +
    +
    {{ i18n.callflows.accountSettings.callerId.titleAsserted }}
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    + {{/if}}
    @@ -100,9 +121,9 @@
    {{ i18n.callflows.accountSettings.musicOnHold.title }}
    - +
    - @@ -121,9 +142,14 @@
    - +
    - + +
    +
    + {{#monsterText 'warning'}} + {{ i18n.callflows.accountSettings.musicOnHold.shoutcastURLWarning }} + {{/monsterText}}
    @@ -131,6 +157,15 @@ + {{#if showMediaUploadDisclosure}} +
    +
    + {{#monsterPanelText i18n.mediaUploadDisclosure.title "info" "fill-width"}} + {{i18n.mediaUploadDisclosure.text}} + {{/monsterPanelText}} +
    +
    + {{/if}}
    @@ -139,9 +174,9 @@
    {{ i18n.callflows.accountSettings.preflow.title }}
    - +
    - {{#select account.preflow.always}} {{#each extra.preflowCallflows}} diff --git a/src/apps/callflows/views/branch.html b/src/apps/callflows/views/branch.html index 08c9c18..77d8442 100644 --- a/src/apps/callflows/views/branch.html +++ b/src/apps/callflows/views/branch.html @@ -1,6 +1,6 @@
    {{#compare node.actionName "!==" "root"}} - {{#if display_key}} + {{#if display_key}}
    {{else}}
    @@ -21,7 +21,7 @@
    {{#compare node.actionName "!==" "root"}} -
    +
    {{else}}
    {{/compare}} diff --git a/src/apps/callflows/views/callflowList.html b/src/apps/callflows/views/callflowList.html index 1a77cc3..133ea4e 100644 --- a/src/apps/callflows/views/callflowList.html +++ b/src/apps/callflows/views/callflowList.html @@ -1,8 +1,8 @@ {{#each callflows}} -
  • +
  • -{{/each}} \ No newline at end of file +{{/each}} diff --git a/src/apps/callflows/views/callflows-callflowElementDetails.html b/src/apps/callflows/views/callflows-callflowElementDetails.html new file mode 100644 index 0000000..7658ca2 --- /dev/null +++ b/src/apps/callflows/views/callflows-callflowElementDetails.html @@ -0,0 +1,4 @@ +
    + +
    +
    diff --git a/src/apps/callflows/views/entity-list.html b/src/apps/callflows/views/entity-list.html index b454730..bb66e1b 100644 --- a/src/apps/callflows/views/entity-list.html +++ b/src/apps/callflows/views/entity-list.html @@ -1,16 +1,17 @@ {{#each entities}} -
  • -
  • + -
  • -{{/each}} \ No newline at end of file + {{/if}} +
    + +{{/each}} diff --git a/src/apps/callflows/views/layout.html b/src/apps/callflows/views/layout.html index 49d42dd..45f901a 100644 --- a/src/apps/callflows/views/layout.html +++ b/src/apps/callflows/views/layout.html @@ -10,11 +10,13 @@
    {{ i18n.entityManager.featureCodeTitle }}
    - {{#each actions}} -
    -
    {{this.name}}
    + {{#each actions}} +
    +
    + {{name}} +
    - {{/each}} + {{/each}}
    @@ -39,4 +41,4 @@
    -
    \ No newline at end of file +
    diff --git a/src/apps/callflows/views/node.html b/src/apps/callflows/views/node.html index 0aa106d..8fa599b 100644 --- a/src/apps/callflows/views/node.html +++ b/src/apps/callflows/views/node.html @@ -1,18 +1,19 @@
    -
    +
    - + {{ callflow.name }}
    -
    - {{#compare node.module "===" "callflow"}} - -
    - {{else}} - {{ node.caption }} - {{/compare}} +
    + {{#compare callflow.name '===' "Callflow"}} + + {{else}} +
    {{ node.caption }}
    + {{/compare}}
    -
    +
    diff --git a/src/apps/callflows/views/root.html b/src/apps/callflows/views/root.html index 52c18f7..ddab949 100644 --- a/src/apps/callflows/views/root.html +++ b/src/apps/callflows/views/root.html @@ -4,4 +4,4 @@
    -
    \ No newline at end of file +
    diff --git a/src/apps/callflows/views/rowNumber.html b/src/apps/callflows/views/rowNumber.html index e19a37d..7e8d12a 100644 --- a/src/apps/callflows/views/rowNumber.html +++ b/src/apps/callflows/views/rowNumber.html @@ -7,7 +7,7 @@ {{#compare numbers.[0] "===" ""}} {{ i18n.oldCallflows.no_number }} {{else}} - {{ formatPhoneNumber numbers.[0] }} + {{ numbers.[0] }} {{/compare}} {{/compare}} @@ -20,7 +20,7 @@ {{#compare numbers.[1] "===" ""}} {{ i18n.oldCallflows.no_number }} {{else}} - {{ formatPhoneNumber numbers.[1] }} + {{ numbers.[1] }} {{/compare}} {{/compare}} @@ -34,7 +34,7 @@ {{#compare numbers.[0] "===" ""}} {{ i18n.oldCallflows.no_number }} {{else}} - {{ formatPhoneNumber numbers.[0] }} + {{ numbers.[0] }} {{/compare}} {{/compare}} diff --git a/src/apps/callflows/views/tools.html b/src/apps/callflows/views/tools.html index a1f49c1..ceebcf5 100644 --- a/src/apps/callflows/views/tools.html +++ b/src/apps/callflows/views/tools.html @@ -1,5 +1,5 @@
    -
    {{ i18n.oldCallflows.actions }}
    +
    {{ i18n.oldCallflows.actions }}