1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /**
- * Created by robin on 12/29/16.
- */
-
- (function () {
- 'use strict';
-
- angular.module('appSdk')
- .factory('itemTracker', ['$q', '$mdDialog', 'AppUtilsBusiness',
- function($q, $mdDialog, AppUtilsBusiness) {
-
- var itemTrackerBuilder = {};
-
- itemTrackerBuilder.create = function(callback) {
- var itemTracker = {};
-
- itemTracker.item = null;
- itemTracker.savedItem = null;
-
- itemTracker.setItem = function (item) {
- itemTracker.savedItem = angular.copy(item);
- itemTracker.item = item;
- if (callback) {
- callback(item);
- }
- };
-
- itemTracker.hasChanged = function () {
- return (itemTracker.savedItem != null && itemTracker.savedItem.id == null) || !angular.equals(itemTracker.item, itemTracker.savedItem);
- };
-
- itemTracker.askExitConfirm = function () {
- var confirm = $mdDialog.confirm()
- .title(AppUtilsBusiness.tr('common.confirmExit.title'))
- .textContent(AppUtilsBusiness.tr('common.confirmExit.content'))
- .ok(AppUtilsBusiness.tr('common.yes'))
- .cancel(AppUtilsBusiness.tr('common.cancel'));
- return $mdDialog.show(confirm);
- };
-
- itemTracker.mayAskExitConfirm = function () {
- if (itemTracker.hasChanged()) {
- return itemTracker.askExitConfirm();
- }
- else {
- var deferred = $q.defer();
- deferred.resolve(null);
- return deferred.promise;
- }
- };
-
- return itemTracker;
- };
- return itemTrackerBuilder;
- }]);
- })();
|