/** * Created by robin on 11/2/15. */ (function () { 'use strict'; angular.module('luticateUtils') .directive('dialogOkCancel', ['luticateDialogErrorHelper', function (luticateDialogErrorHelper) { return { restrict: 'EA', transclude: true, templateUrl: '/luticateUtils/dialogokcancel-directive.html', link: function link($scope, element, attrs) { $scope.title = attrs.title; $scope.model = {}; $scope.pending = false; $scope.submitted = false; $scope.__submit = function() { $scope.submitted = true; if ($scope.form.$valid) { $scope.pending = true; $scope.promise = $scope.submitForm(); if ($scope.promise) { $scope.promise.then(function(data) { if ($scope.onDone) { $scope.onDone(data); } $scope.$close(data); $scope.pending = false; }) .catch(function(error) { if ($scope.onError) { $scope.onError(error); } luticateDialogErrorHelper.errorDialog(error) .result.then(function(data) { }, function(error2) { $scope.$dismiss(error); }); $scope.pending = false; }); } else { $scope.$close(); $scope.pending = false; } } }; $scope.__cancel = function() { if ($scope.onCanceled) { $scope.onCanceled(); } $scope.$dismiss(); $scope.pending = false; }; } }; }]); angular.module("luticateUtils").run(["$templateCache", function($templateCache) { $templateCache.put("/luticateUtils/dialogokcancel-directive.html", ''); }]); })();