123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- (function()
- {
- angular.module('appSdk')
- .factory('DataShareBusiness', ['$location', '$state', function ($location, $state) {
-
- var data = {
- Groups: null,
-
- Staffs: null,
-
- Rooms: null,
-
- SearchSeparator: "~",
-
- CurrentGroups: [],
-
- DateFormat: "dd MMM yyyy",
-
- TimeFormat: "HH'h'mm",
-
- DateTimeFormat: "DD MMM YYYY HH[h]mm",
-
- EntitiesType: "Rooms",
-
- makeParents: function(group, type)
- {
- if (group[type] != null) {
- group[type].forEach(function (g) {
- g.Parent = group;
- data.makeParents(g, type);
- });
- }
- },
-
- goToGroup: function(group)
- {
- var search = data.getSearchString(group);
- $state.go(data.EntitiesType == "Groups" ? 'home' : 'rooms', {group: search.length == 0 ? undefined : search});
- },
-
- setCurrentGroup: function(group)
- {
- data.CurrentGroups = [];
- while (group != null) {
- data.CurrentGroups.push(group);
- group = group.Parent;
- }
- data.CurrentGroups.reverse();
- },
-
- getCurrentGroup: function()
- {
- if (data.CurrentGroups.length == 0) {
- return null;
- }
- return data.CurrentGroups[data.CurrentGroups.length - 1];
- },
-
- getSearchString: function(group)
- {
- if (group == -1 && data.CurrentGroups.length != 0) {
- group = data.CurrentGroups[data.CurrentGroups.length - 1];
- }
- if (group == null) {
- return "";
- }
- var search = [];
- while (group != null){
- search.push(group.Name);
- group = group.Parent;
- }
- var str = search.reverse().join(data.SearchSeparator);
- return str;
- },
-
- setFromSearchString: function(string)
- {
- if (data[data.EntitiesType] == null) {
- return;
- }
- if (string == null) {
- data.setCurrentGroup(null);
- return;
- }
- var group = null;
- var names = string.split(data.SearchSeparator);
- names.forEach(function(name)
- {
- var g = (group || data)[data.EntitiesType].find(function(g)
- {
- return g.Name == name;
- });
- if (g != null) {
- group = g;
- }
- });
- data.setCurrentGroup(group);
- },
-
- upCurrentGroup: function()
- {
- if (data.CurrentGroups.length > 1) {
- data.goToGroup(data.CurrentGroups[data.CurrentGroups.length - 2]);
- }
- else if (data.CurrentGroups.length == 1) {
- data.goToGroup(null);
- }
- }
- };
-
- return data;
- }]);
- })();
|