Created
January 20, 2015 13:34
-
-
Save adhamankar/69751a5ab133a23ec8c7 to your computer and use it in GitHub Desktop.
AngularJs modalService - Popup service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../references.ts" /> | |
module Common.Framework { | |
"use strict"; | |
export interface IControllerScope<T> extends ng.IScope { | |
vm: T; | |
} | |
export class BaseCtrl { | |
public static $inject = ["$scope"]; | |
constructor(public $scope: IControllerScope<any> | |
) { | |
$scope.vm = this; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../References.ts" /> | |
module Common.Framework { | |
"use strict"; | |
export interface IModalContainer { | |
modalInstance: ng.ui.bootstrap.IModalServiceInstance; | |
openModal(settings: ng.ui.bootstrap.IModalSettings, onClosingModal: any): void; | |
closeModal(success?: any): void; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../References.ts" /> | |
module Common.Framework { | |
"use strict"; | |
export class ModalService implements Common.Framework.IModalContainer { | |
public static $inject = ["$modal"]; | |
public static Factory($modal: ng.ui.bootstrap.IModalService) { | |
return new ModalService($modal); | |
} | |
private dismissCallback: (reason: any) => any; | |
public modalInstance: ng.ui.bootstrap.IModalServiceInstance; | |
constructor(public $modal: ng.ui.bootstrap.IModalService) { | |
} | |
public openModal = (settings: ng.ui.bootstrap.IModalSettings, onClosingModal?: (reason: any) => any | |
, onDismissingModal?: (reason: any) => any) => { | |
if (this.modalInstance) { | |
return; | |
} | |
this.dismissCallback = onDismissingModal; | |
this.modalInstance = this.$modal.open(settings); | |
this.modalInstance.result.then(onClosingModal, this.dismissModal); | |
}; | |
public dismissModal = () => { | |
this.modalInstance = null; | |
if (this.dismissCallback !== null && this.dismissCallback !== undefined) { | |
this.dismissCallback("dismissed"); | |
} | |
}; | |
public closeModal = (success) => { | |
if (this.modalInstance) { | |
this.modalInstance.close(success); | |
} | |
this.modalInstance = null; | |
}; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../references.ts" /> | |
module Sample { | |
"use strict"; | |
export class SampleCtrl extends BaseCtrl { | |
public static $inject = ["$scope", "$http", "popup", "container"]; | |
constructor(public $scope: Common.Framework.IControllerScope<SampleCtrl>, public $http: ng.IHttpService, | |
public popup: Common.Framework.ModalService, public container: Common.Framework.IModalContainer) { | |
//TODO: custom initiatilization... | |
} | |
editRecord = (index: number) => { | |
this.popup.openModal(this.prepareAddMissionModalSettings(), this.onModalClose, this.onModalDismiss); | |
}; | |
close = () => { | |
this.container.closeModal(); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment