From 9b9f83236d940bd3ae5331836a7e107e6f436d8f Mon Sep 17 00:00:00 2001
From: Ruel Tmeizeh - RuhNet
' + 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 }}