diff --git a/app.js b/app.js index b9dc493..ee9f878 100644 --- a/app.js +++ b/app.js @@ -2,7 +2,8 @@ define(function(require){ var $ = require('jquery'), _ = require('underscore'), monster = require('monster'), - chosen = require('chosen'); + chosen = require('chosen'), + toastr = require('toastr'); var app = { name: 'fax', @@ -68,20 +69,27 @@ define(function(require){ }); }, - renderInbound: function(pArgs) { + renderFaxes: function(pArgs) { var self = this, args = pArgs || {}, parent = args.container || $('#fax_app_container .app-content-wrapper'), dates = monster.util.getDefaultRangeDates(self.appFlags.ranges.default), fromDate = dates.from, - toDate = dates.to; + toDate = dates.to, + type = pArgs.type; - var template = $(monster.template(self, 'inbound-faxes', { faxboxes: self.appFlags.faxboxes })); + var template = $(monster.template(self, type + '-faxes', { faxboxes: self.appFlags.faxboxes })); self.bindCommon(template); - self.bindInbound(template); - self.initDatePicker('inbound', template, fromDate, toDate); + if(type === 'inbound') { + self.bindInbound(template); + } + else { + self.bindOutbound(template); + } + + self.initDatePicker(template, fromDate, toDate); parent .fadeOut(function() { @@ -91,36 +99,26 @@ define(function(require){ .fadeIn(); }); - self.displayInboundFaxesList(template, fromDate, toDate); + self.displayFaxesList(type, template, fromDate, toDate); }, - renderOutbound: function(pArgs) { - var self = this, - args = pArgs || {}, - parent = args.container || $('#fax_app_container .app-content-wrapper'), - dates = monster.util.getDefaultRangeDates(self.appFlags.ranges.default), - fromDate = dates.from, - toDate = dates.to; + renderInbound: function(pArgs) { + var self = this; - var template = $(monster.template(self, 'outbound-faxes', { faxboxes: self.appFlags.faxboxes })); + pArgs.type = 'inbound'; - self.bindCommon(template); - self.bindOutbound(template); + self.renderFaxes(pArgs); + }, - self.initDatePicker('outbound', template, fromDate, toDate); + renderOutbound: function(pArgs) { + var self = this; - parent - .fadeOut(function() { - $(this) - .empty() - .append(template) - .fadeIn(); - }); + pArgs.type = 'outbound'; - self.displayOutboundFaxesList(template, fromDate, toDate); + self.renderFaxes(pArgs); }, - displayInboundFaxesList: function(container, fromDate, toDate) { + displayFaxesList: function(type, container, fromDate, toDate, selectedFaxbox) { var self = this; container.find('.data-state') @@ -129,19 +127,14 @@ define(function(require){ container.find('.loading-state') .show(); - self.getInboundData(fromDate, toDate, function(data) { - var dataTemplate = self.formatInboundData(data); + self.getTemplateData(type, container, fromDate, toDate, selectedFaxbox, function(template) { + monster.ui.footable(template.find('.footable')); + self.bindTableCommon(template); container.removeClass('empty'); container.find('.main-select-message').prop('checked', false); - var template = $(monster.template(self, 'inbound-faxes-list', { faxes: dataTemplate })); - - monster.ui.footable(template.find('.footable')); - - self.bindTableCommon(template); - container.find('.data-state') .empty() .append(template) @@ -149,39 +142,32 @@ define(function(require){ container.find('.loading-state') .hide(); + + if(selectedFaxbox) { + container.find('#select_faxbox').val(selectedFaxbox).trigger('change'); + } }); }, - displayOutboundFaxesList: function(container, fromDate, toDate) { + getTemplateData: function(type, container, fromDate, toDate, selectedFaxbox, callback) { var self = this; - container.find('.data-state') - .hide(); - - container.find('.loading-state') - .show(); - - self.getOutboundData(fromDate, toDate, function(data) { - var dataTemplate = self.formatOutboundData(data); - - container.removeClass('empty'); - - container.find('.main-select-message').prop('checked', false); - - var template = $(monster.template(self, 'outbound-faxes-list', { faxes: dataTemplate })); - - monster.ui.footable(template.find('.footable')); - - self.bindTableCommon(template); + if(type === 'inbound') { + self.getInboundData(fromDate, toDate, function(data) { + var dataTemplate = self.formatInboundData(data), + template = $(monster.template(self, 'inbound-faxes-list', { faxes: dataTemplate })); - container.find('.data-state') - .empty() - .append(template) - .show(); + callback && callback(template); + }); + } + else { + self.getOutboundData(fromDate, toDate, function(data) { + var dataTemplate = self.formatOutboundData(data), + template = $(monster.template(self, 'outbound-faxes-list', { faxes: dataTemplate })); - container.find('.loading-state') - .hide(); - }); + callback && callback(template); + }); + } }, bindTableCommon: function(template) { @@ -208,23 +194,7 @@ define(function(require){ }); }, - getInboundData: function(fromDate, toDate, callback) { - var self = this; - - self.getInboundFaxes(fromDate, toDate, function(faxes) { - callback && callback(faxes) - }); - }, - - getOutboundData: function(fromDate, toDate, callback) { - var self = this; - - self.getOutboundFaxes(fromDate, toDate, function(faxes) { - callback && callback(faxes) - }); - }, - - initDatePicker: function(type, template, fromDate, toDate) { + initDatePicker: function(template, fromDate, toDate) { var self = this; var optionsDatePicker = { @@ -238,17 +208,18 @@ define(function(require){ template.find('#endDate').datepicker('setDate', toDate); template.find('.apply-filter').on('click', function(e) { - self.refreshFaxes(type, template); + self.refreshFaxes(template); }); }, - refreshFaxes: function(type, template) { + refreshFaxes: function(template) { var self = this, - fnName = type === 'inbound' ? 'displayInboundFaxesList' : 'displayOutboundFaxesList', + type = template.hasClass('inbound-faxes') ? 'inbound' : 'outbound', fromDate = template.find('input.filter-from').datepicker("getDate"), - toDate = template.find('input.filter-to').datepicker("getDate"); + toDate = template.find('input.filter-to').datepicker("getDate"), + selectedFaxbox = template.find('#select_faxbox').val(); - self[fnName](template, fromDate, toDate); + self.displayFaxesList(type, template, fromDate, toDate, selectedFaxbox) }, bindCommon: function(template) { @@ -272,6 +243,8 @@ define(function(require){ } filtering.filter(); + + afterSelect(); }); function afterSelect() { @@ -285,6 +258,10 @@ define(function(require){ } } + template.find('#refresh_faxbox').on('click', function() { + self.refreshFaxes(template); + }); + template.on('click', '.select-fax', function() { afterSelect(); }); @@ -315,21 +292,72 @@ define(function(require){ afterSelect(); }); + + template.find('#delete_faxes').on('click', function() { + var listSelected = []; + template.find('.select-fax:checked').each(function(a, el) { + listSelected.push($(el).data('id')); + }); + var content = monster.template(self, '!'+ self.i18n.active().fax.deleteConfirm.content, { variable: listSelected.length }); + + monster.ui.confirm(content, function() { + template.find('.select-fax:checked').each(function(a, el) { + listSelected.push($(el).data('id')); + }); + + self.deleteFaxes(listSelected, function() { + toastr.success(self.i18n.active().fax.deleteConfirm.success); + + self.refreshFaxes(template); + }); + }, undefined, { + title: self.i18n.active().fax.deleteConfirm.title, + confirmButtonText: self.i18n.active().fax.deleteConfirm.confirmButtonText, + confirmButtonClass: 'monster-button-danger' + }); + }); }, bindInbound: function(template) { var self = this; + }, - template.find('#refresh_faxbox').on('click', function() { - self.refreshInboundFaxes(template); + bindOutbound: function(template) { + var self = this; + + template.find('#resend_faxes').on('click', function() { + var listSelected = []; + template.find('.select-fax:checked').each(function(a, el) { + listSelected.push($(el).data('id')); + }); + var content = monster.template(self, '!'+ self.i18n.active().fax.resendConfirm.content, { variable: listSelected.length }); + + monster.ui.confirm(content, function() { + self.resendFaxes(listSelected, function() { + toastr.success(self.i18n.active().fax.resendConfirm.success); + + self.refreshFaxes(template); + }); + }, undefined, { + title: self.i18n.active().fax.resendConfirm.title, + confirmButtonText: self.i18n.active().fax.resendConfirm.confirmButtonText + }); }); }, - bindOutbound: function(template) { + getInboundData: function(fromDate, toDate, callback) { var self = this; - template.find('#refresh_faxbox').on('click', function() { - self.refreshOutboundFaxes(template); + self.getInboundFaxes(fromDate, toDate, function(faxes) { + callback && callback(faxes) + }); + }, + + getOutboundData: function(fromDate, toDate, callback) { + var self = this; + + self.getOutboundFaxes(fromDate, toDate, function(faxes) { + callback && callback(faxes) }); }, @@ -370,21 +398,6 @@ define(function(require){ return self.apiUrl + 'accounts/' + self.accountId + '/faxes/' + mediaId + '/attachments?auth_token=' + self.authToken; }, -/* getFaxbox: function(faxboxId, callback) { - var self = this; - - self.callApi({ - resource: 'faxbox.get', - data: { - accountId: self.accountId, - faxboxId: faxboxId - }, - success: function(data) { - callback && callback(data.data); - } - }); - }, -*/ getInboundFaxes: function(fromDate, toDate, callback) { var self = this; @@ -511,6 +524,14 @@ define(function(require){ callback && callback(data.data); } }); + }, + + deleteFaxes: function(listFaxes, callback) { + callback && callback(); + }, + + resendFaxes: function(listFaxes, callback) { + callback && callback(); } }; diff --git a/i18n/en-US.json b/i18n/en-US.json index 333f2d8..5926c47 100644 --- a/i18n/en-US.json +++ b/i18n/en-US.json @@ -54,6 +54,18 @@ }, "CDRPopup": { "title": "Fax Details" + }, + "deleteConfirm": { + "content": "Deleting the {{variable}} selected voicemail(s) will permanently remove them from the system. This action can not be undone or reversed, and the affected files will be gone forever.", + "title": "Are you sure?", + "confirmButtonText": "Delete Selected Files", + "success": "You successfully deleted the selected faxes from the system!" + }, + "resendConfirm": { + "content": "You are attempting to redeliver {{variable}} faxes. Are you sure you want to attempt re-delivery?", + "confirmButtonText": "Re-send Faxes", + "title": "Are you sure?", + "success": "You successfully tried to re-send the selected faxes!" } } } \ No newline at end of file diff --git a/views/inbound-faxes-list.html b/views/inbound-faxes-list.html index d3f8f8a..73ecaa1 100644 --- a/views/inbound-faxes-list.html +++ b/views/inbound-faxes-list.html @@ -17,7 +17,7 @@ {{#monsterCheckbox}} - + {{/monsterCheckbox}} {{formatted.timestamp}} diff --git a/views/outbound-faxes-list.html b/views/outbound-faxes-list.html index 319fc30..fc90da5 100644 --- a/views/outbound-faxes-list.html +++ b/views/outbound-faxes-list.html @@ -18,7 +18,7 @@ {{#monsterCheckbox}} - + {{/monsterCheckbox}} {{status}}