diff --git a/app.js b/app.js index 600bd96..3cc3252 100644 --- a/app.js +++ b/app.js @@ -30,7 +30,8 @@ define(function(require) { max: 31 }, faxboxes: {}, - faxnumbers: [] + allnumbers: [], // list of all numbers in the account + faxboxnumbers: {} // { "somefaxboxid": [array of DIDs that go to this faxbox] } }, initApp: function(callback) { @@ -48,7 +49,8 @@ define(function(require) { self.getFaxData(function(results) { self.appFlags.faxboxes = _.keyBy(results.faxboxes, 'id'); //console.log(_.size(self.appFlags.faxboxes)); - self.appFlags.faxnumbers = results.faxnumbers; + self.appFlags.faxboxnumbers = results.faxboxnumbers; + var menus = [ { tabs: [ @@ -92,9 +94,9 @@ define(function(require) { callback(null, faxboxes); }); }, - faxnumbers: function(callback) { - self.getFaxNumbers(function(faxnumbers) { - callback(null, faxnumbers); + faxboxnumbers: function(callback) { + self.getFaxboxNumbers(function(faxboxnumbers) { + callback(null, faxboxnumbers); }); }, storage: function(callback) { @@ -126,7 +128,6 @@ define(function(require) { parent = args.container || $('#fax_app_container .app-content-wrapper'), dataTemplate = { faxboxes: self.appFlags.faxboxes, - faxnumbers: self.appFlags.faxnumbers, count: _.size(self.appFlags.faxboxes) }, template = $(self.getTemplate({ @@ -190,6 +191,9 @@ define(function(require) { template.find('.select-faxbox').val(faxboxId).trigger('chosen:updated'); + //load send from phone numbers belonging to this faxbox + self.loadNumberChoices(template, self.appFlags.faxboxnumbers[faxboxId]); + self.maybeShowAllNumbersOption(template); self.displayListFaxes(type, template, faxboxId); }); @@ -344,6 +348,12 @@ define(function(require) { $('.outbound-expand').show(); }); + template.on('click', '.show-all-numbers', function() { + self.loadNumberChoices(template, self.appFlags.allnumbers); //load all numbers + $('.show-all-numbers').fadeOut(2000); + monster.ui.toast({ type: "info", message: self.i18n.active().fax.outbound.allNumbers }); + $('#from_number_header').text(self.i18n.active().fax.outbound.fromNumberAll); + }); template.on('click', '.send-fax-button', function(e) { e.preventDefault(); @@ -771,6 +781,29 @@ define(function(require) { }); }, + loadNumberChoices: function(template, numbers) { + var self = this; + var $phoneNumberSelect = template.find('#sendfax_from_number'); + if ($phoneNumberSelect) { + $phoneNumberSelect.empty(); + if (numbers && numbers.length > 1) { + $phoneNumberSelect.append($('
'); + monster.ui.alert('' + err.responseText + ''); } }); }, - getFaxNumbers: function(callback) { + getCallflows: function(callback) { var self = this; self.callApi({ - resource: 'numbers.listAll', + resource: 'callflow.list', data: { accountId: self.accountId, filters: { paginate: false } }, - success: function(res, status) { - var numbers = _.map(res.data.numbers, function(n, number) { - return {number: number}; - }); + error: function(err) { + console.log(err); + }, + success: function(res) { + callback && callback(res.data); + } + }); + }, + + getCallflow: function(id, callback) { + var self = this; + + self.callApi({ + resource: 'callflow.get', + data: { + accountId: self.accountId, + callflowId: id + }, + error: function(err) { + console.log(err); + }, + success: function(res) { + callback && callback(res.data); + } + }); + }, + + getNumbers: function(callback) { + var self = this; + + if (self.appFlags.allnumbers.length > 0) { + return callback && callback(self.appFlags.allnumbers); //sortof cache :) + } + + self.callApi({ + resource: 'numbers.list', + data: { + accountId: self.accountId, + filters: { paginate: false } + }, + error: function(err) { + console.log(err); + }, + success: function(res) { + var numbers = _.keys(res.data.numbers); + self.appFlags.allnumbers = numbers; callback && callback(numbers); } }); - } + }, + + getFaxboxNumbers: function(callback) { + var self = this, + faxboxNumbers = {}; + + var findFaxboxId = function(flow) { + if (flow.module == 'faxbox') { + return flow.data.id; + } else if (flow.children.length > 0) { + findFaxBoxId(flow.children["_"]); + } + }; + + self.getNumbers(function(numbers) { + self.getCallflows(function(callflows) { //get all callflows + let done = new Promise((resolve, reject) => { //let these finish before proceeding + if (callflows.length == 0) resolve(); + _.each(callflows, function(cf, idx) { + if (cf.modules.includes('faxbox')) { //if callflow uses the faxbox module, get it individually + self.getCallflow(cf.id, function(callflow) { + var fbid = findFaxboxId(callflow.flow); //search for the faxbox ID + if (fbid) faxboxNumbers[fbid] = []; + _.each(cf.numbers, function(cfnum) { //check each callflow number to see if it's a real DID + if (numbers.includes(cfnum)) { + faxboxNumbers[fbid].push(cfnum); //add the number (if it's a DID) to the list for this faxbox ID + } + }); + if (faxboxNumbers[fbid] && faxboxNumbers[fbid].length == 0) { //this faxbox has no DIDs routing to it + console.log('Warning: faxbox '+fbid+' has no DIDs routing to it!'); + } + }); + } + if ((idx + 1) == callflows.length) resolve(); //processed all callflows so we're done + }); + }); + done.then(() => { + callback && callback(faxboxNumbers); + }); + }); + }); + } //getFaxboxNumbers() }; //app diff --git a/i18n/de-DE.json b/i18n/de-DE.json index 0d484a4..e0abe89 100644 --- a/i18n/de-DE.json +++ b/i18n/de-DE.json @@ -78,15 +78,19 @@ "storage": "Speicher" }, "outbound": { + "allNumbers": "Admin Action: All numbers in the account are now visible for fax from_number.", "enterToNumber": "Enter Fax To Number", + "fromNumber": "From Number", + "fromNumberAll": "From Number [All Numbers]", "missingFile": "You must choose a PDF or TIFF file to send", "missingFrom": "You must select the source number.", "missingTo": "You must enter the destination fax number.", "selectFile": "Upload your file (PDF or TIFF format)", - "selectNumber": "Select From Number", + "selectFromNumber": "Select From Number", "sendFax": "Send Fax", "sendAFax": "Send a Fax", - "success": "fax has been queued for sending" + "success": "fax has been queued for sending", + "toNumber": "To Number" }, "title": "Faxportal", "CDRPopup": { diff --git a/i18n/en-US.json b/i18n/en-US.json index 47b50bd..0002bed 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -8,13 +8,15 @@ "storage": "Storage" }, "outbound": { + "allNumbers": "Admin Action: All numbers in the account are now visible for fax from_number.", "enterToNumber": "Enter Fax To Number", "fromNumber": "From Number", + "fromNumberAll": "From Number [All Numbers]", "missingFile": "You must choose a PDF or TIFF file to send", "missingFrom": "You must select the source number.", "missingTo": "You must enter the destination fax number.", "selectFile": "Upload your file (PDF or TIFF format)", - "selectNumber": "Select From Number", + "selectFromNumber": "Select From Number", "sendFax": "Send Fax", "sendAFax": "Send a Fax", "success": "fax has been queued for sending", diff --git a/style/app.css b/style/app.css index 3dd5402..7dfc524 100644 --- a/style/app.css +++ b/style/app.css @@ -203,3 +203,17 @@ justify-content: space-between; padding-bottom: 4px; } + +.show-all-numbers { + font-size: +1.1em; + margin-bottom: 10px; + margin-left: 6px; + color: #2297FF; + display: none; +} + +.from-number-select { + display: flex; + flex-direction: row; + align-items: center; +} diff --git a/style/app.scss b/style/app.scss index 12401f9..1648aac 100644 --- a/style/app.scss +++ b/style/app.scss @@ -247,3 +247,17 @@ justify-content: space-between; padding-bottom: 4px; } + +.show-all-numbers { + font-size: +1.1em; + margin-bottom: 10px; + margin-left: 6px; + color: #2297FF; + display: none; +} + +.from-number-select { + display: flex; + flex-direction: row; + align-items: center; +} diff --git a/views/outbound-faxes.html b/views/outbound-faxes.html index f0835df..b81b67a 100644 --- a/views/outbound-faxes.html +++ b/views/outbound-faxes.html @@ -29,15 +29,15 @@ {{ i18n.fax.outbound.toNumber }}