diff --git a/app.js b/app.js index eb19d2a..3cc3252 100644 --- a/app.js +++ b/app.js @@ -29,7 +29,9 @@ define(function(require) { default: 7, max: 31 }, - faxboxes: {} + faxboxes: {}, + allnumbers: [], // list of all numbers in the account + faxboxnumbers: {} // { "somefaxboxid": [array of DIDs that go to this faxbox] } }, initApp: function(callback) { @@ -46,7 +48,9 @@ define(function(require) { self.getFaxData(function(results) { self.appFlags.faxboxes = _.keyBy(results.faxboxes, 'id'); -console.log(_.size(self.appFlags.faxboxes)); + //console.log(_.size(self.appFlags.faxboxes)); + self.appFlags.faxboxnumbers = results.faxboxnumbers; + var menus = [ { tabs: [ @@ -90,6 +94,11 @@ console.log(_.size(self.appFlags.faxboxes)); callback(null, faxboxes); }); }, + faxboxnumbers: function(callback) { + self.getFaxboxNumbers(function(faxboxnumbers) { + callback(null, faxboxnumbers); + }); + }, storage: function(callback) { self.getStorage(function(storage) { callback(null, storage); @@ -182,6 +191,9 @@ console.log(_.size(self.appFlags.faxboxes)); 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); }); @@ -315,6 +327,39 @@ console.log(_.size(self.appFlags.faxboxes)); cb.prop('checked', !cb.prop('checked')); afterSelect(); }); + + template.on('change', '#sendfax_uploaded_file', function() { + $('.outbound-hidden').show(); + $('.outbound-expand').hide(); + if ($(this).val()) { // Check if a file is selected + $('.send-fax-button').prop('disabled', false); + } else { + $('.send-fax-button').prop('disabled', true); + } + }); + + template.on('click', '.outbound-expand', function() { + $('.outbound-hidden').slideDown(); + $('.outbound-expand').hide(); + }); + template.on('click', '.outbound-contract', function() { + $('.outbound-hidden').slideUp(); + $('.outbound-contract').hide(); + $('.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(); + self.sendFaxUpload(template); + }); + }, displayListFaxes: function(type, container, faxboxId) { @@ -734,8 +779,171 @@ console.log(_.size(self.appFlags.faxboxes)); callback && callback(data.data); } }); - } - }; + }, + + 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($('