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 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. EntitiesType: "Rooms",
  15. makeParents: function(group, type)
  16. {
  17. if (group[type] != null) {
  18. group[type].forEach(function (g) {
  19. g.Parent = group;
  20. data.makeParents(g, type);
  21. });
  22. }
  23. },
  24. goToGroup: function(group)
  25. {
  26. var search = data.getSearchString(group);
  27. $state.go(data.EntitiesType == "Groups" ? 'home' : 'rooms', {group: search.length == 0 ? undefined : search});
  28. },
  29. setCurrentGroup: function(group)
  30. {
  31. data.CurrentGroups = [];
  32. while (group != null) {
  33. data.CurrentGroups.push(group);
  34. group = group.Parent;
  35. }
  36. data.CurrentGroups.reverse();
  37. },
  38. getCurrentGroup: function()
  39. {
  40. if (data.CurrentGroups.length == 0) {
  41. return null;
  42. }
  43. return data.CurrentGroups[data.CurrentGroups.length - 1];
  44. },
  45. getSearchString: function(group)
  46. {
  47. if (group == -1 && data.CurrentGroups.length != 0) {
  48. group = data.CurrentGroups[data.CurrentGroups.length - 1];
  49. }
  50. if (group == null) {
  51. return "";
  52. }
  53. var search = [];
  54. while (group != null){
  55. search.push(group.Name);
  56. group = group.Parent;
  57. }
  58. var str = search.reverse().join(data.SearchSeparator);
  59. return str;
  60. },
  61. setFromSearchString: function(string)
  62. {
  63. if (data[data.EntitiesType] == null) {
  64. return;
  65. }
  66. if (string == null) {
  67. data.setCurrentGroup(null);
  68. return;
  69. }
  70. var group = null;
  71. var names = string.split(data.SearchSeparator);
  72. names.forEach(function(name)
  73. {
  74. var g = (group || data)[data.EntitiesType].find(function(g)
  75. {
  76. return g.Name == name;
  77. });
  78. if (g != null) {
  79. group = g;
  80. }
  81. });
  82. data.setCurrentGroup(group);
  83. },
  84. upCurrentGroup: function()
  85. {
  86. if (data.CurrentGroups.length > 1) {
  87. data.goToGroup(data.CurrentGroups[data.CurrentGroups.length - 2]);
  88. }
  89. else if (data.CurrentGroups.length == 1) {
  90. data.goToGroup(null);
  91. }
  92. }
  93. };
  94. return data;
  95. }]);
  96. })();