Welcome to mirror list, hosted at ThFree Co, Russian Federation.

listcontroller.js « controllers « app « js - github.com/nextcloud/tasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fbf3470b8ba431cfb169c4c96f44c2ad60119ad3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
 * ownCloud - Tasks
 *
 * @author Raimund Schlüßler
 * @copyright 2016 Raimund Schlüßler <raimund.schluessler@googlemail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

(function() {
  angular.module('Tasks').controller('ListController', [
	'$scope', '$window', '$routeParams', 'ListsModel', 'TasksBusinessLayer', 'CollectionsModel', 'ListsBusinessLayer', '$location', 'SearchBusinessLayer', 'CalendarService', function($scope, $window, $routeParams, ListsModel, TasksBusinessLayer, CollectionsModel, ListsBusinessLayer, $location, SearchBusinessLayer, CalendarService) {
	  var ListController;
	  ListController = (function() {
		function ListController(_$scope, _$window, _$routeParams, _$listsmodel, _$tasksbusinesslayer, _$collectionsmodel, _$listsbusinesslayer, $location, _$searchbusinesslayer, _$calendarservice) {
		  this._$scope = _$scope;
		  this._$window = _$window;
		  this._$routeParams = _$routeParams;
		  this._$listsmodel = _$listsmodel;
		  this._$tasksbusinesslayer = _$tasksbusinesslayer;
		  this._$collectionsmodel = _$collectionsmodel;
		  this._$listsbusinesslayer = _$listsbusinesslayer;
		  this.$location = $location;
		  this._$searchbusinesslayer = _$searchbusinesslayer;
		  this._$calendarservice = _$calendarservice;
		  this._$scope.collections = this._$collectionsmodel.getAll();
		  this._$scope.calendars = this._$listsmodel.getAll();
		  this._$scope.draggedTasks = [];
		  this._$scope.TasksBusinessLayer = this._$tasksbusinesslayer;
		  this._$scope.status.listNameBackup = '';
		  this._$scope.deleteList = function(calendar) {
			var really;
			really = confirm(t('tasks', 'This will delete the Calendar "%s" and all of its entries.').replace('%s', calendar.displayname));
			if (really) {
			  return _$listsbusinesslayer["delete"](calendar).then(function() {
				$location.path('/calendars/' + _$listsmodel.getStandardList().uri);
				return $scope.$apply();
			  });
			}
		  };
		  this._$scope.startAddingList = function() {
			return _$scope.status.addingList = true;
		  };
		  this._$scope.endAddingList = function() {
			_$scope.status.addingList = false;
			return _$scope.status.newListName = "";
		  };
		  this._$scope.checkListInput = function(event) {
			if (event.keyCode === 13) {
			  event.preventDefault();
			  _$scope.submitNewList();
			}
			if (event.keyCode === 27) {
			  return _$scope.endAddingList();
			}
		  };
		  this._$scope.submitNewList = function() {
			var list;
			if (_$scope.status.newListName) {
			  if (_$listsmodel.checkName(_$scope.status.newListName)) {
				_$scope.status.addingList = false;
				_$scope.isAddingList = true;
				list = {
				  tmpID: 'newList' + Date.now(),
				  displayname: _$scope.status.newListName,
				  notLoaded: 0
				};
				_$listsbusinesslayer.add(_$scope.status.newListName).then(function(calendar) {
				  $location.path('/calendars/' + calendar.uri);
				  return $scope.$apply();
				});
				return _$scope.status.newListName = '';
			  } else {
				return alert(t('tasks', 'The name "%s" is already used.').replace('%s', _$scope.status.newListName));
			  }
			} else {
			  return alert(t('tasks', 'An empty name is not allowed.'));
			}
		  };
		  this._$scope.editName = function(listID) {
			_$scope.status.addingList = false;
			_$scope.status.listNameBackup = _$listsmodel.getById(listID).displayname;
			return $location.path('/lists/' + _$scope.route.listID + '/edit/name');
		  };
		  this._$scope.checkName = function(event) {
			if (!_$scope.status.listNameBackup) {
			  _$scope.status.listNameBackup = _$listsmodel.getById(_$scope.route.listID).displayname;
			}
			if (event.keyCode === 13) {
			  event.preventDefault();
			  _$scope.submitNewName();
			}
			if (event.keyCode === 27) {
			  _$listsmodel.getById(_$scope.route.listID).displayname = _$scope.status.listNameBackup;
			  return _$scope.endEditList();
			}
		  };
		  this._$scope.submitNewName = function() {
			var name;
			name = _$listsmodel.getById(_$scope.route.listID).displayname;
			if (name) {
			  if (_$listsmodel.checkName(name, _$scope.route.listID)) {
				_$listsbusinesslayer.setListName(_$scope.route.listID);
				return _$scope.endEditList();
			  } else {
				return alert(t('tasks', 'The name "%s" is already used.').replace('%s', name));
			  }
			} else {
			  return alert(t('tasks', 'An empty name is not allowed.'));
			}
		  };
		  this._$scope.endEditList = function() {
			return $location.path('/lists/' + _$scope.route.listID);
		  };
		  this._$scope.setListName = function(listID, listName) {
			return _$listsbusinesslayer.setListName(listID(listName));
		  };
		  this._$scope.getCollectionCount = function(collectionID) {
			var filter;
			filter = _$searchbusinesslayer.getFilter();
			return _$collectionsmodel.getCount(collectionID, filter);
		  };
		  this._$scope.hideCollection = function(collectionID) {
			var collection;
			collection = _$collectionsmodel.getById(collectionID);
			switch (collection.show) {
			  case 0:
				return true;
			  case 1:
				return false;
			  case 2:
				return this.getCollectionCount(collectionID) < 1;
			}
		  };
		  this._$scope.getCollectionString = function(collectionID) {
			var filter;
			if (collectionID !== 'completed') {
			  filter = _$searchbusinesslayer.getFilter();
			  return _$collectionsmodel.getCount(collectionID, filter);
			} else {
			  return '';
			}
		  };
		  this._$scope.getListCount = function(listID, type) {
			var filter;
			filter = _$searchbusinesslayer.getFilter();
			return _$listsmodel.getCount(listID, type, filter);
		  };
		  this._$scope.showDelete = function(listID) {
			var _ref;
			return (_ref = _$scope.route.listID) !== 'starred' && _ref !== 'today' && _ref !== 'completed' && _ref !== 'week' && _ref !== 'all' && _ref !== 'current';
		  };
		  this._$scope.update = function() {
			if (!_$scope.isLoading()) {
			  _$tasksbusinesslayer.updateModel();
			  return _$listsbusinesslayer.updateModel();
			}
		  };
		  this._$scope.dragoverList = function($event, item, index) {
			return true;
		  };
		  this._$scope.dropList = function($event, item, index) {
			var listID, taskID;
			taskID = item.id;
			listID = $($event.target).closest('li.list').attr('listID');
			_$tasksbusinesslayer.changeCalendarId(taskID, listID);
			return true;
		  };
		  this._$scope.dragoverCollection = function($event, item, index) {
			var collectionID;
			collectionID = $($event.target).closest('li.collection').attr('collectionID');
			return collectionID === 'starred' || collectionID === 'completed' || collectionID === 'today';
		  };
		  this._$scope.dropCollection = function($event, item, index) {
			var collectionID, taskID;
			taskID = item.id;
			collectionID = $($event.target).closest('li.collection').attr('collectionID');
			console.log(taskID, collectionID);
			_$tasksbusinesslayer.changeCollection(taskID, collectionID);
			return true;
		  };
		}

		return ListController;

	  })();
	  return new ListController($scope, $window, $routeParams, ListsModel, TasksBusinessLayer, CollectionsModel, ListsBusinessLayer, $location, SearchBusinessLayer, CalendarService);
	}
  ]);

}).call(this);