(function() { 'use strict'; angular.module('shared') .service('LazModalService', ['ModalService', '$q', '$templateRequest', function(ModalService, $q, $templateRequest) { var service = this; service.showModal = function(options) { return getTemplate(options.template, options.templateUrl) .then(function(template) { options.template = wrapTemplateInLazModal(template, options); return ModalService.showModal(options); }); }; function getTemplate(template, templateUrl) { var deferred = $q.defer(); if (template) { deferred.resolve(template); } else if (templateUrl) { $templateRequest(templateUrl, true) .then(function(template) { deferred.resolve(template); }, function(error) { deferred.reject(error); }); } else { deferred.reject("No template or templateUrl has been specified."); } return deferred.promise; } function wrapTemplateInLazModal(template, options) { var attributes = getLazModalAttributes(options); return '' + template + ''; } function getLazModalAttributes(options) { var onCloseHtmlAttribute = getOnCloseHtmlAttribute(options); var overrideClassAttribute = getOverrideClassHtmlAttribute(options); var overrideStyleHtmlAttribute = getOverrideStyleHtmlAttribute(options); var hideCloseButtonHtmlAttribute = getHideCloseButtonHtmlAttribute(options); return onCloseHtmlAttribute + ' ' + overrideClassAttribute + ' ' + overrideStyleHtmlAttribute + ' ' + hideCloseButtonHtmlAttribute; } function getOnCloseHtmlAttribute(options) { if (options.hasOwnProperty('onClose')) { return 'on-close="' + options.onClose + '"'; } else { return 'on-close="$ctrl.close"'; } } function getOverrideClassHtmlAttribute(options) { if (options.hasOwnProperty('overrideClass')) { return 'override-class="' + options.overrideClass + '"'; } else { return ''; } } function getOverrideStyleHtmlAttribute(options) { if (options.hasOwnProperty('overrideStyle')) { return 'override-style="' + options.overrideStyle + '"'; } else { return ''; } } function getHideCloseButtonHtmlAttribute(options) { if (options.hasOwnProperty('hideCloseButton')) { return 'hide-close-button="' + options.hideCloseButton + '"'; } else { return ''; } } }]); })();