You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DataShareBusiness.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. (function()
  2. {
  3. angular.module('appSdk')
  4. .factory('DataShareBusiness', ['$location', '$state', function ($location, $state) {
  5. var data = {
  6. Groups: null,
  7. Staffs: null,
  8. Rooms: null,
  9. SearchSeparator: "~",
  10. CurrentGroups: [],
  11. DateFormat: "dd MMM yyyy",
  12. TimeFormat: "HH'h'mm",
  13. DateTimeFormat: "DD MMM YYYY HH[h]mm",
  14. makeParents: function(group)
  15. {
  16. if (group.Groups != null) {
  17. group.Groups.forEach(function (g) {
  18. g.Parent = group;
  19. data.makeParents(g);
  20. });
  21. }
  22. },
  23. goToGroup: function(group)
  24. {
  25. var search = data.getSearchString(group);
  26. $state.go('home', {group: search.length == 0 ? undefined : search});
  27. },
  28. setCurrentGroup: function(group)
  29. {
  30. data.CurrentGroups = [];
  31. while (group != null) {
  32. data.CurrentGroups.push(group);
  33. group = group.Parent;
  34. }
  35. data.CurrentGroups.reverse();
  36. },
  37. getCurrentGroup: function()
  38. {
  39. if (data.CurrentGroups.length == 0) {
  40. return null;
  41. }
  42. return data.CurrentGroups[data.CurrentGroups.length - 1];
  43. },
  44. getCurrentGroupOrRoot: function()
  45. {
  46. var group = data.getCurrentGroup();
  47. if (group == null) {
  48. return {
  49. Id: null,
  50. Groups: data.Groups,
  51. Name: "Root",
  52. Type: 1,
  53. ParentId: -1
  54. }
  55. }
  56. return group;
  57. },
  58. getSearchString: function(group)
  59. {
  60. if (group == -1 && data.CurrentGroups.length != 0) {
  61. group = data.CurrentGroups[data.CurrentGroups.length - 1];
  62. }
  63. if (group == null) {
  64. return "";
  65. }
  66. var search = [];
  67. while (group != null){
  68. search.push(group.Name);
  69. group = group.Parent;
  70. }
  71. var str = search.reverse().join(data.SearchSeparator);
  72. return str;
  73. },
  74. getGroupUrl: function(group)
  75. {
  76. var search = data.getSearchString(group);
  77. return $state.href('home', {group: (search.length != 0 ? search : undefined)});
  78. },
  79. setFromSearchString: function(string)
  80. {
  81. if (data.Groups == null) {
  82. return;
  83. }
  84. if (string == null) {
  85. data.setCurrentGroup(null);
  86. return;
  87. }
  88. var group = null;
  89. var names = string.split(data.SearchSeparator);
  90. names.forEach(function(name)
  91. {
  92. var g = (group || data).Groups.find(function(g)
  93. {
  94. return g.Name == name;
  95. });
  96. if (g != null) {
  97. group = g;
  98. }
  99. });
  100. data.setCurrentGroup(group);
  101. },
  102. upCurrentGroup: function()
  103. {
  104. if (data.CurrentGroups.length > 1) {
  105. data.setCurrentGroup(data.CurrentGroups[data.CurrentGroups.length - 2]);
  106. }
  107. else if (data.CurrentGroups.length == 1) {
  108. data.setCurrentGroup(null);
  109. }
  110. }
  111. };
  112. return data;
  113. }]);
  114. })();