123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- (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",
-
- makeParents: function(group)
- {
- if (group.Groups != null) {
- group.Groups.forEach(function (g) {
- g.Parent = group;
- data.makeParents(g);
- });
- }
- },
-
- goToGroup: function(group)
- {
- var search = data.getSearchString(group);
- $state.go('home', {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];
- },
-
- getCurrentGroupOrRoot: function()
- {
- var group = data.getCurrentGroup();
- if (group == null) {
- return {
- Id: null,
- Groups: data.Groups,
- Name: "Root",
- Type: 1,
- ParentId: -1
- }
- }
- return group;
- },
-
- 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;
- },
-
- getGroupUrl: function(group)
- {
- var search = data.getSearchString(group);
- return $state.href('home', {group: (search.length != 0 ? search : undefined)});
- },
-
- setFromSearchString: function(string)
- {
- if (data.Groups == 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).Groups.find(function(g)
- {
- return g.Name == name;
- });
- if (g != null) {
- group = g;
- }
- });
- data.setCurrentGroup(group);
- },
-
- upCurrentGroup: function()
- {
- if (data.CurrentGroups.length > 1) {
- data.setCurrentGroup(data.CurrentGroups[data.CurrentGroups.length - 2]);
- }
- else if (data.CurrentGroups.length == 1) {
- data.setCurrentGroup(null);
- }
- }
- };
-
- return data;
- }]);
- })();
|