Browse Source

Faxbox number selection on outbound fax

outbound-fax
Ruel Tmeizeh - RuhNet 2 weeks ago
parent
commit
9b9f83236d
6 changed files with 174 additions and 24 deletions
  1. +130
    -14
      app.js
  2. +6
    -2
      i18n/de-DE.json
  3. +3
    -1
      i18n/en-US.json
  4. +14
    -0
      style/app.css
  5. +14
    -0
      style/app.scss
  6. +7
    -7
      views/outbound-faxes.html

+ 130
- 14
app.js View File

@ -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($('<option>', { value: "none", text: self.i18n.active().fax.outbound.selectFromNumber }));
}
_.each(numbers, function(number) {
$phoneNumberSelect.append($('<option>', { value: number, text: number }));
});
}
},
maybeShowAllNumbersOption: function(template) {
var self = this;
$('#from_number_header').text(self.i18n.active().fax.outbound.fromNumber);
if (monster.util.isAdmin()) {
$('.show-all-numbers').show();
}
},
sendFaxUpload: function(template) {
var self = this;
var toNumber = template.find('#sendfax_to_number').val();
@ -804,28 +837,111 @@ define(function(require) {
},
error: function(err) {
console.log(err);
monster.ui.alert('<h3>Error</h3><p><pre>err.responseText</pre></p>');
monster.ui.alert('<h3>Error</h3><p><pre>' + err.responseText + '</pre></p>');
}
});
},
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


+ 6
- 2
i18n/de-DE.json View File

@ -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": {


+ 3
- 1
i18n/en-US.json View File

@ -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",


+ 14
- 0
style/app.css View File

@ -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;
}

+ 14
- 0
style/app.scss View File

@ -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;
}

+ 7
- 7
views/outbound-faxes.html View File

@ -29,15 +29,15 @@
{{ i18n.fax.outbound.toNumber }}
</div>
<input id="sendfax_to_number" name="sendfax_to_number" type="text" maxlength=16 placeholder="{{i18n.fax.outbound.enterToNumber}}"><br />
<div class="select-header">
<div id="from_number_header" class="select-header">
{{ i18n.fax.outbound.fromNumber }}
</div>
<select id="sendfax_from_number">
<option value="none">{{i18n.fax.outbound.selectNumber}}</option>
{{#each faxnumbers}}
<option value="{{number}}">{{number}}</option>
{{/each}}
</select>
<div class="from-number-select">
<select id="sendfax_from_number">
<option value="none">{{i18n.fax.outbound.selectFromNumber}}</option>
</select>
<i class="fa fa-plus show-all-numbers"></i>
</div>
</div>
<button class="monster-button-primary send-fax-button outbound-hidden" disabled>{{i18n.fax.outbound.sendFax}}</button>
</div>


Loading…
Cancel
Save