sgDialogService

Needing a -simple- dialog system for Angular-JS supporting modals, dynamic templates, dragging, and a consisten skin for ALL the dialogs i wrote this small module.

The library is able to open nested modal dialogs, alerts and confirm.

The source is here: sgDialog.1.0.0.zip.

Screenshot

Notes

The sample can be run with Firefox, in general or by running, into the directory,

Installation

var myApp = angular.module('myApp',['sgDialogService']);
myApp.run(["sgDialogService.config",function(sgDialogServiceConfig){
    sgDialogServiceConfig.dialogTemplate = "app/sgDialogService/sgDialogTemplate.html";
}]);

To use the service into a service, controller or else, must be included the dependency for "sgDialogService"

Into the controllers inside the dialog service must be included the dependency on "modalInstance"

Usage

Dialog

To open a dialog. At least one between template and templateUrl must be specified. the parameters are

    var modalInstance = sgDialogService.openModal({
            templateUrl:'sample/dialogContent.html',
            data:{fromParent:dialogParam},
            callback: function(result){ $scope.callbackResult=result;}
        });
    }

The returned modalInstance is the one passed as parameter to the child controller. These are its members

To show buttons into the dialog, on its controller, we can do like the following. The member of the buttons are

    $scope.title = $scope.fromParent;
    $scope.modalButtons =[
        {
            action:function(){modalInstance.dismiss();},
            text:"Cancel",class:"btn-default"
        },
        {
            action:function(){modalInstance.closeModal($scope.forCallback);},
            text:"Ok",class:"btn-primary",
            disabled: function(){ if($scope.callbackForm) return $scope.callbackForm.$invalid || !$scope.callbackForm.$dirty;}
        }
    ];

Alert

To show an alert

    sgDialogService.alert(text);

Confirm

To show a confirm

    sgDialogService.confirm(text,function(result){
        alert("The user responded: "+result);
    });

History


Last modified on: August 18, 2015