您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

itemTracker.business.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Created by robin on 12/29/16.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('appSdk')
  7. .factory('itemTracker', ['$q', '$mdDialog', 'AppUtilsBusiness',
  8. function($q, $mdDialog, AppUtilsBusiness) {
  9. var itemTrackerBuilder = {};
  10. itemTrackerBuilder.create = function(callback) {
  11. var itemTracker = {};
  12. itemTracker.item = null;
  13. itemTracker.savedItem = null;
  14. itemTracker.setItem = function (item) {
  15. itemTracker.savedItem = angular.copy(item);
  16. itemTracker.item = item;
  17. if (callback) {
  18. callback(item);
  19. }
  20. };
  21. itemTracker.hasChanged = function () {
  22. return (itemTracker.savedItem != null && itemTracker.savedItem.id == null) || !angular.equals(itemTracker.item, itemTracker.savedItem);
  23. };
  24. itemTracker.askExitConfirm = function () {
  25. var confirm = $mdDialog.confirm()
  26. .title(AppUtilsBusiness.tr('common.confirmExit.title'))
  27. .textContent(AppUtilsBusiness.tr('common.confirmExit.content'))
  28. .ok(AppUtilsBusiness.tr('common.yes'))
  29. .cancel(AppUtilsBusiness.tr('common.cancel'));
  30. return $mdDialog.show(confirm);
  31. };
  32. itemTracker.mayAskExitConfirm = function () {
  33. if (itemTracker.hasChanged()) {
  34. return itemTracker.askExitConfirm();
  35. }
  36. else {
  37. var deferred = $q.defer();
  38. deferred.resolve(null);
  39. return deferred.promise;
  40. }
  41. };
  42. return itemTracker;
  43. };
  44. return itemTrackerBuilder;
  45. }]);
  46. })();