module Sfx { export class Action { private _running : boolean ; public get running ( ) : boolean { return this . _running ; } public get displayTitle ( ) : string { return this . _running ? this . runningTitle : this . title ; } constructor ( public name , public title , public runningTitle , protected execute , public canRun ) { this . _running = false ; } public run ( ... params ) { return this . runInternal ( ng . noop , ng . noop , params ) ; } public runWithCallbacks ( success , error , ... params ) { return this . runInternal ( success , error , params ) ; } protected runInternal ( success , error , ... params ) { if ( this . canRun ( ) ) { this . _running = true ; return this . execute ( params ) . then ( success , error ) . finally ( ( ) => { this . _running = false ; } ) ; } } } export class ActionWithDialog extends Action { param name param title param runningTitle param execute param canRun param modalSettings param beforeOpen constructor ( public $uibModal , public $q , public name , public title , public runningTitle , protected execute , public canRun , public modalSettings , public beforeOpen ? ) { super ( name , title , runningTitle , execute , canRun ) ; } protected runInternal ( success , error , ... params ) { if ( this . canRun ( ) ) { return this . $q . when ( this . beforeOpen ? this . beforeOpen ( ) : true ) . then ( ( ) => { return this . $uibModal . open ( this . modalSettings ) . result . then ( ( ) => { return super . runInternal ( success , error , params ) ; } ) ; } ) ; } } } export class ActionWithConfirmationDialog extends ActionWithDialog { constructor ( public $uibModal , public $q , public name , public title , public runningTitle , protected execute , public canRun , public confirmationDialogTitle ? , public confirmationDialogMessage ? , public confirmationKeyword ? ) { super ( $uibModal , $q , name , title , runningTitle , execute , canRun , { templateUrl : "partials/action-confirmation-dialog.html" , controller : ActionController , resolve : { action : ( ) => this } } ) ; } } }