Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DataShareBusiness.js 3.9KB

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