@ -108,9 +108,9 @@ define(function(require){
} ,
vmboxesRenderVmbox : function ( data , callback ) {
var self = this
var self = this ,
mode = data . id ? 'edit' : 'add' ,
popupTitle = mode === 'edit' ? monster . template ( self , '!' + self . i18n . active ( ) . vmboxes . editTitle , { name : data . name } ) : self . i18n . active ( ) . vmboxes . addTitle ;
popupTitle = mode === 'edit' ? monster . template ( self , '!' + self . i18n . active ( ) . vmboxes . editTitle , { name : data . name } ) : self . i18n . active ( ) . vmboxes . addTitle ,
templateVMBox = $ ( monster . template ( self , 'vmboxes-edit' , data ) ) ,
callbacks = {
afterSave : function ( vmbox ) {
@ -128,6 +128,8 @@ define(function(require){
}
} ;
console . log ( data ) ;
_ . each ( data . notify_email_addresses , function ( recipient ) {
templateVMBox . find ( '.saved-entities' )
. append ( monster . template ( self , 'vmboxes-emailRow' , { name : recipient } ) ) ;
@ -231,6 +233,96 @@ define(function(require){
templateVMBox . find ( '.saved-entities' ) . on ( 'click' , '.delete-entity' , function ( ) {
$ ( this ) . parents ( '.entity-wrapper' ) . remove ( ) ;
} ) ;
//Greeting Media stuff
var mediaToUpload ,
greetingContainer = templateVMBox . find ( '.greeting-container' ) ,
closeUploadDiv = function ( newMedia ) {
mediaToUpload = undefined ;
greetingContainer . find ( '.upload-div input' ) . val ( '' ) ;
greetingContainer . find ( '.upload-div' ) . slideUp ( function ( ) {
greetingContainer . find ( '.upload-toggle' ) . removeClass ( 'active' ) ;
} ) ;
if ( newMedia ) {
var mediaSelect = greetingContainer . find ( '.media-dropdown' ) ;
mediaSelect . append ( '<option value="' + newMedia . id + '">' + newMedia . name + '</option>' ) ;
mediaSelect . val ( newMedia . id ) ;
}
} ;
greetingContainer . find ( '.upload-input' ) . fileUpload ( {
inputOnly : true ,
wrapperClass : 'file-upload input-append' ,
btnText : self . i18n . active ( ) . vmboxes . popupSettings . greeting . audioUploadButton ,
btnClass : 'monster-button' ,
maxSize : 5 ,
success : function ( results ) {
mediaToUpload = results [ 0 ] ;
} ,
error : function ( errors ) {
if ( errors . hasOwnProperty ( 'size' ) && errors . size . length > 0 ) {
monster . ui . alert ( self . i18n . active ( ) . vmboxes . popupSettings . greeting . fileTooBigAlert ) ;
}
greetingContainer . find ( '.upload-div input' ) . val ( '' ) ;
mediaToUpload = undefined ;
}
} ) ;
greetingContainer . find ( '.upload-toggle' ) . on ( 'click' , function ( ) {
if ( $ ( this ) . hasClass ( 'active' ) ) {
greetingContainer . find ( '.upload-div' ) . stop ( true , true ) . slideUp ( ) ;
} else {
greetingContainer . find ( '.upload-div' ) . stop ( true , true ) . slideDown ( ) ;
}
} ) ;
greetingContainer . find ( '.upload-cancel' ) . on ( 'click' , function ( ) {
closeUploadDiv ( ) ;
} ) ;
greetingContainer . find ( '.upload-submit' ) . on ( 'click' , function ( ) {
if ( mediaToUpload ) {
self . callApi ( {
resource : 'media.create' ,
data : {
accountId : self . accountId ,
data : {
streamable : true ,
name : mediaToUpload . name ,
media_source : "upload" ,
description : mediaToUpload . name
}
} ,
success : function ( data , status ) {
var media = data . data ;
self . callApi ( {
resource : 'media.upload' ,
data : {
accountId : self . accountId ,
mediaId : media . id ,
data : mediaToUpload . file
} ,
success : function ( data , status ) {
closeUploadDiv ( media ) ;
} ,
error : function ( data , status ) {
self . callApi ( {
resource : 'media.delete' ,
data : {
accountId : self . accountId ,
mediaId : media . id ,
data : { }
} ,
success : function ( data , status ) { }
} ) ;
}
} ) ;
}
} ) ;
} else {
monster . ui . alert ( self . i18n . active ( ) . vmboxes . popupSettings . greeting . emptyUploadAlert ) ;
}
} ) ;
} ,
vmboxesMergeData : function ( originalData , template ) {
@ -272,7 +364,9 @@ define(function(require){
} ,
formattedData = $ . extend ( true , { } , defaults , data . vmbox ) ;
formattedData . extra = { } ;
formattedData . extra = {
mediaList : data . mediaList
} ;
return formattedData ;
} ,
@ -335,6 +429,17 @@ define(function(require){
else {
callback ( null , { } ) ;
}
} ,
mediaList : function ( callback ) {
self . callApi ( {
resource : 'media.list' ,
data : {
accountId : self . accountId
} ,
success : function ( data ) {
callback ( null , data . data ) ;
}
} ) ;
}
} ,
function ( error , results ) {