@ -45,32 +45,120 @@ define(function(require){
render : function ( container ) {
var self = this ;
self . listFaxboxes ( function ( faxboxes ) {
self . appFlags . faxboxes = _ . indexBy ( faxboxes , 'id' ) ;
self . getFaxData ( function ( results ) {
self . appFlags . faxboxes = _ . indexBy ( results . faxboxes , 'id' ) ;
var menus = [
{
tabs : [
{
text : self . i18n . active ( ) . fax . menuTitles . inbound ,
callback : self . renderInbound
} ,
{
text : self . i18n . active ( ) . fax . menuTitles . outbound ,
callback : self . renderOutbound
} ,
{
text : self . i18n . active ( ) . fax . menuTitles . logs ,
callback : self . renderLogs
}
]
}
] ;
if ( results . storage ) {
var tabStorage = {
text : self . i18n . active ( ) . fax . menuTitles . storage ,
callback : self . renderStorage
} ;
menus [ 0 ] . tabs . push ( tabStorage ) ;
}
monster . ui . generateAppLayout ( self , {
menus : [
{
tabs : [
{
text : self . i18n . active ( ) . fax . menuTitles . inbound ,
callback : self . renderInbound
} ,
{
text : self . i18n . active ( ) . fax . menuTitles . outbound ,
callback : self . renderOutbound
} ,
{
text : self . i18n . active ( ) . fax . menuTitles . logs ,
callback : self . renderLogs
}
]
}
]
menus : menus
} ) ;
} ) ;
} ,
getFaxData : function ( callback ) {
var self = this ;
monster . parallel ( {
faxboxes : function ( callback ) {
self . listFaxboxes ( function ( faxboxes ) {
callback ( null , faxboxes ) ;
} ) ;
} ,
storage : function ( callback ) {
self . getStorage ( function ( storage ) {
callback ( null , storage ) ;
} ) ;
}
} ,
function ( err , results ) {
callback && callback ( results ) ;
} ) ;
} ,
getStorage : function ( callback ) {
var self = this ;
self . callApi ( {
resource : 'storage.get' ,
data : {
accountId : self . accountId ,
generateError : false
} ,
success : function ( data ) {
callback ( data . data ) ;
} ,
error : function ( data , error , globalHandler ) {
if ( error . status === 404 ) {
callback ( undefined ) ;
} else {
globalHandler ( data ) ;
}
}
} ) ;
} ,
renderStorage : function ( pArgs ) {
var self = this ,
args = pArgs || { } ,
parent = args . container || $ ( '#fax_app_container .app-content-wrapper' ) ;
self . getStorage ( function ( storage ) {
var formattedData = self . storageFormatData ( storage ) ,
template = $ ( monster . template ( self , 'storage' , formattedData ) ) ;
self . storageBindEvents ( template ) ;
monster . pub ( 'common.storagePlanManager.render' , {
container : template . find ( '.control-container' ) ,
forceTypes : [ 'fax' ] ,
hideOtherTypes : true
} ) ;
parent
. fadeOut ( function ( ) {
$ ( this )
. empty ( )
. append ( template )
. fadeIn ( ) ;
} ) ;
} ) ;
} ,
storageBindEvents : function ( template ) {
var self = this ;
} ,
storageFormatData : function ( data ) {
return data ;
} ,
renderFaxes : function ( pArgs ) {
var self = this ,
args = pArgs || { } ,
@ -392,12 +480,12 @@ define(function(require){
fax . formatted . error = details . result_text ;
}
fax . formatted . timestamp = monster . util . toFriendlyDate ( fax . hasOwnProperty ( 'timestamp' ) ? fax . timestamp : details . pvt_delivered_date ) ;
fax . formatted . timestamp = monster . util . toFriendlyDate ( fax . created ) ;
fax . formatted . receivingFaxbox = self . appFlags . faxboxes . hasOwnProperty ( fax . faxbox_id ) ? self . appFlags . faxboxes [ fax . faxbox_id ] . name : '-' ;
fax . formatted . receivingNumber = monster . util . formatPhoneNumber ( fax . to_number ) ;
fax . formatted . sendingFaxbox = self . appFlags . faxboxes . hasOwnProperty ( fax . faxbox_id ) ? self . appFlags . faxboxes [ fax . faxbox_id ] . name : '-' ;
fax . formatted . sendingNumber = monster . util . formatPhoneNumber ( fax . from_number ) ;
fax . formatted . pages = details . hasOwnProperty ( 'total_pages' ) ? details . total_pages : self . i18n . active ( ) . fax . table . noData ;
fax . formatted . pages = details . hasOwnProperty ( 'total_pages' ) ? details . total_pages : 0 ;
fax . formatted . uri = self . formatFaxURI ( fax . id , type ) ;
} ) ;