Remove useless javascript
This commit is contained in:
parent
75ec539b2d
commit
341ec97c20
4 changed files with 0 additions and 863 deletions
|
@ -1,272 +0,0 @@
|
|||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('Tasks').controller('ListController', [
|
||||
'$scope', '$rootScope', '$window', '$routeParams', 'ListsModel', 'TasksBusinessLayer', 'CollectionsModel', 'ListsBusinessLayer', '$location',
|
||||
'SearchBusinessLayer', 'CalendarService', 'TasksModel', '$timeout',
|
||||
function($scope, $rootScope, $window, $routeParams, ListsModel, TasksBusinessLayer, CollectionsModel, ListsBusinessLayer, $location,
|
||||
SearchBusinessLayer, CalendarService, TasksModel, $timeout) {
|
||||
'use strict';
|
||||
var ListController;
|
||||
ListController = (function() {
|
||||
function ListController(_$scope, $rootScope, _$window, _$routeParams, _$listsmodel, _$tasksbusinesslayer, _$collectionsmodel, _$listsbusinesslayer, $location,
|
||||
_$searchbusinesslayer, _$calendarservice, _$tasksmodel, _$timeout) {
|
||||
|
||||
this._$scope = _$scope;
|
||||
this._$window = _$window;
|
||||
this._$routeParams = _$routeParams;
|
||||
this._$listsmodel = _$listsmodel;
|
||||
this._$tasksmodel = _$tasksmodel;
|
||||
this._$tasksbusinesslayer = _$tasksbusinesslayer;
|
||||
this._$collectionsmodel = _$collectionsmodel;
|
||||
this._$listsbusinesslayer = _$listsbusinesslayer;
|
||||
this.$location = $location;
|
||||
this._$timeout = _$timeout;
|
||||
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.nameError = false;
|
||||
this._$scope.color = '#31CC7C';
|
||||
|
||||
this._$scope.deleteMessage = function (calendar) {
|
||||
return t('tasks', 'This will delete the calendar "%s" and all corresponding events and tasks.').replace('%s', calendar.displayname);
|
||||
};
|
||||
|
||||
this._$scope["delete"] = function(calendar) {
|
||||
return _$listsbusinesslayer["delete"](calendar).then(function() {
|
||||
$location.path('/calendars/' + _$listsmodel.getStandardList().uri);
|
||||
return $scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
this._$scope.startCreate = function(e) {
|
||||
_$scope.status.addingList = true;
|
||||
_$scope.nameError = false;
|
||||
$('.hasTooltip').tooltip('hide');
|
||||
_$timeout(function() {
|
||||
$('#newList').focus();
|
||||
}, 50);
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
this._$scope.create = function() {
|
||||
var check = _$scope.isNameAllowed(_$scope.status.newListName);
|
||||
if (check.allowed) {
|
||||
_$scope.status.addingList = false;
|
||||
_$scope.isAddingList = true;
|
||||
_$listsbusinesslayer.add(_$scope.status.newListName, _$scope.color).then(function(calendar) {
|
||||
$location.path('/calendars/' + calendar.uri);
|
||||
return $scope.$apply();
|
||||
});
|
||||
_$scope.status.newListName = '';
|
||||
}
|
||||
};
|
||||
|
||||
this._$scope.cancelCreate = function() {
|
||||
$('.hasTooltip').tooltip('hide');
|
||||
_$scope.nameError = false;
|
||||
_$scope.status.addingList = false;
|
||||
_$scope.status.newListName = "";
|
||||
};
|
||||
|
||||
this._$scope.startEdit = function(e, calendar) {
|
||||
_$scope.status.addingList = false;
|
||||
_$scope.nameError = false;
|
||||
$('.hasTooltip').tooltip('hide');
|
||||
calendar.prepareUpdate();
|
||||
$location.path('/calendars/' + _$scope.route.calendarID + '/edit/name');
|
||||
_$timeout(function() {
|
||||
$('#list_' + calendar.uri + ' input.edit').focus();
|
||||
}, 50);
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
this._$scope.showCalDAVUrl = function(e, calendar) {
|
||||
_$scope.status.addingList = false;
|
||||
_$scope.nameError = false;
|
||||
$location.path('/calendars/' + _$scope.route.calendarID + '/edit/caldav');
|
||||
_$timeout(function() {
|
||||
$('#list_' + calendar.uri + ' input.caldav').focus();
|
||||
}, 50);
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
this._$scope.hideCalDAVUrl = function() {
|
||||
$location.path('/calendars/' + _$scope.route.calendarID);
|
||||
};
|
||||
|
||||
this._$scope.download = function (calendar) {
|
||||
var url = calendar.url;
|
||||
// cut off last slash to have a fancy name for the ics
|
||||
if (url.slice(url.length - 1) === '/') {
|
||||
url = url.slice(0, url.length - 1);
|
||||
}
|
||||
url += '?export';
|
||||
$window.open(url);
|
||||
};
|
||||
|
||||
this._$scope.checkNew = function(event,name) {
|
||||
_$scope.checkName(event,name);
|
||||
};
|
||||
|
||||
this._$scope.checkEdit = function(event,calendar) {
|
||||
_$scope.checkName(event,calendar.displayname,calendar.uri);
|
||||
if (event.keyCode === 27) {
|
||||
_$scope.cancelEdit(calendar);
|
||||
}
|
||||
};
|
||||
|
||||
this._$scope.checkName = function(event,name,uri) {
|
||||
var check = _$scope.isNameAllowed(name,uri);
|
||||
var $input = $(event.currentTarget);
|
||||
if (!check.allowed) {
|
||||
$input.attr('title', check.msg)
|
||||
.tooltip({placement: 'bottom', trigger: 'manual'})
|
||||
.tooltip('fixTitle').tooltip('show');
|
||||
_$scope.nameError = true;
|
||||
} else {
|
||||
$input.tooltip('hide');
|
||||
_$scope.nameError = false;
|
||||
}
|
||||
if (event.keyCode === 27) {
|
||||
event.preventDefault();
|
||||
$input.tooltip('hide');
|
||||
_$scope.status.addingList = false;
|
||||
_$scope.status.newListName = "";
|
||||
_$scope.nameError = false;
|
||||
}
|
||||
};
|
||||
|
||||
$rootScope.$on('cancelEditCalendar', function(s, calendarUri) {
|
||||
var calendar = _$listsmodel.getByUri(calendarUri);
|
||||
_$scope.cancelEdit(calendar);
|
||||
});
|
||||
|
||||
this._$scope.cancelEdit = function(calendar) {
|
||||
calendar.resetToPreviousState();
|
||||
$('.hasTooltip').tooltip('hide');
|
||||
_$scope.nameError = false;
|
||||
$location.path('/calendars/' + _$scope.route.calendarID);
|
||||
};
|
||||
|
||||
this._$scope.saveEdit = function(calendar) {
|
||||
var check = _$scope.isNameAllowed(calendar.displayname, calendar.uri);
|
||||
if (check.allowed) {
|
||||
_$listsbusinesslayer.rename(calendar);
|
||||
$location.path('/calendars/' + _$scope.route.calendarID);
|
||||
}
|
||||
};
|
||||
|
||||
this._$scope.isNameAllowed = function(name, uri) {
|
||||
var check = {
|
||||
allowed: false,
|
||||
msg: ''
|
||||
};
|
||||
if (_$listsmodel.isNameAlreadyTaken(name, uri)) {
|
||||
check.msg = t('tasks', 'The name "%s" is already used.').replace('%s', name);
|
||||
} else if (!name) {
|
||||
check.msg = t('tasks', 'An empty name is not allowed.');
|
||||
} else {
|
||||
check.allowed = true;
|
||||
}
|
||||
return check;
|
||||
};
|
||||
|
||||
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.dragoverList = function($event, index) {
|
||||
var calendarID = $($event.target).closest('li.list').attr('calendarID');
|
||||
var calendar = _$listsmodel.getByUri(calendarID);
|
||||
return calendar.writable;
|
||||
};
|
||||
|
||||
this._$scope.dropList = function($event, index, item) {
|
||||
if ($event.dataTransfer.dropEffect === 'move') {
|
||||
// we can't simply use item as task, since the directive seems to not copy all properties --> task.calendar.uri == undefined
|
||||
var task = _$tasksmodel.getByUri(item.uri);
|
||||
var calendarID = $($event.target).closest('li.list').attr('calendarID');
|
||||
var calendar = _$listsmodel.getByUri(calendarID);
|
||||
_$tasksbusinesslayer.changeCalendar(task, calendar).then(function() {
|
||||
_$scope.$apply();
|
||||
});
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this._$scope.dragoverCollection = function($event, index) {
|
||||
if ($event.dataTransfer.effectAllowed === 'copy' || ($event.dataTransfer.effectAllowed === 'copyMove' && $event.ctrlKey)) {
|
||||
return false;
|
||||
}
|
||||
var collectionID;
|
||||
collectionID = $($event.target).closest('li.collection').attr('collectionID');
|
||||
return collectionID === 'starred' || collectionID === 'completed' || collectionID === 'today';
|
||||
};
|
||||
|
||||
this._$scope.dropCollection = function($event, index, item) {
|
||||
if ($event.dataTransfer.dropEffect === 'move') {
|
||||
var collectionID = $($event.target).closest('li.collection').attr('collectionID');
|
||||
_$tasksbusinesslayer.changeCollection(item.uri, collectionID);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
return ListController;
|
||||
})();
|
||||
return new ListController($scope, $rootScope, $window, $routeParams, ListsModel, TasksBusinessLayer, CollectionsModel, ListsBusinessLayer, $location,
|
||||
SearchBusinessLayer, CalendarService, TasksModel, $timeout);
|
||||
}
|
||||
]);
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('Tasks').directive('confirmation', function() {
|
||||
'use strict';
|
||||
return {
|
||||
priority: -1,
|
||||
restrict: 'A',
|
||||
templateUrl: OC.generateUrl('/apps/tasks/templates/confirmation', {}),
|
||||
scope: {
|
||||
confirmationFunction: "&confirmation",
|
||||
confirmationMessage: "&confirmationMessage",
|
||||
|
||||
},
|
||||
controller: 'ConfirmationController'
|
||||
};
|
||||
});
|
||||
|
||||
angular.module('Tasks').controller('ConfirmationController', [
|
||||
'$scope', '$rootScope', '$element', '$attrs', '$compile', '$document', '$window', '$timeout', function($scope, $rootScope, $element, $attrs, $compile, $document, $window, $timeout) {
|
||||
'use strict';
|
||||
var ConfirmationController = (function() {
|
||||
function ConfirmationController(_$scope, $rootScope, $element, $attrs, $compile, $document, $window, $timeout) {
|
||||
this._$scope = _$scope;
|
||||
this._$scope.countdown = 3;
|
||||
|
||||
$element.bind( 'click', function( e ){
|
||||
_$scope.countdown = 3;
|
||||
$element.removeClass('active');
|
||||
var message = _$scope.confirmationMessage() ? _$scope.confirmationMessage() : "Are you sure?";
|
||||
if ($element.hasClass('confirmed')) {
|
||||
return;
|
||||
}
|
||||
e.stopPropagation();
|
||||
_$scope.activate();
|
||||
$element.tooltip({title: message, container: 'body', placement: 'right', trigger: 'manual'}).tooltip('show');
|
||||
$element.addClass("confirmed");
|
||||
});
|
||||
|
||||
$element.children('.confirmation-confirm').bind( 'click', function (e) {
|
||||
if ($element.hasClass('confirmed active')) {
|
||||
_$scope.confirmationFunction();
|
||||
return;
|
||||
} else{
|
||||
e.stopPropagation();
|
||||
}
|
||||
});
|
||||
|
||||
this._$scope.documentClick = function () {
|
||||
$element.removeClass("confirmed");
|
||||
$element.tooltip('hide');
|
||||
};
|
||||
|
||||
this._$scope.activate = function () {
|
||||
if (_$scope.countdown) {
|
||||
$element.find('.countdown').html(_$scope.countdown+' s');
|
||||
$timeout(function() {
|
||||
_$scope.activate();
|
||||
}, 1000);
|
||||
_$scope.countdown--;
|
||||
} else {
|
||||
$element.addClass('active');
|
||||
}
|
||||
};
|
||||
|
||||
$document.bind('click', _$scope.documentClick);
|
||||
$document.bind('touchend', _$scope.documentClick);
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
$document.unbind('click', _$scope.documentClick);
|
||||
$document.unbind('touchend', _$scope.documentClick);
|
||||
});
|
||||
}
|
||||
return ConfirmationController;
|
||||
})();
|
||||
return new ConfirmationController($scope, $rootScope, $element, $attrs, $compile, $document, $window, $timeout);
|
||||
}
|
||||
]);
|
|
@ -1,92 +0,0 @@
|
|||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* 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() {
|
||||
'use strict';
|
||||
var __bind = function(fn, me){
|
||||
return function(){
|
||||
return fn.apply(me, arguments);
|
||||
};
|
||||
};
|
||||
|
||||
angular.module('Tasks').factory('SearchBusinessLayer', [
|
||||
'ListsModel', 'Persistence', 'TasksModel', '$rootScope', '$routeParams', '$location', function(ListsModel, Persistence, TasksModel, $rootScope, $routeParams, $location) {
|
||||
var SearchBusinessLayer;
|
||||
SearchBusinessLayer = (function() {
|
||||
function SearchBusinessLayer(_$listsmodel, _persistence, _$tasksmodel, _$rootScope, _$routeparams, _$location) {
|
||||
this._$listsmodel = _$listsmodel;
|
||||
this._persistence = _persistence;
|
||||
this._$tasksmodel = _$tasksmodel;
|
||||
this._$rootScope = _$rootScope;
|
||||
this._$routeparams = _$routeparams;
|
||||
this._$location = _$location;
|
||||
this.getFilter = __bind(this.getFilter, this);
|
||||
this.setFilter = __bind(this.setFilter, this);
|
||||
this.cleanSearch = __bind(this.cleanSearch, this);
|
||||
this.attach = __bind(this.attach, this);
|
||||
this.initialize();
|
||||
this._$searchString = '';
|
||||
}
|
||||
|
||||
SearchBusinessLayer.prototype.attach = function(search) {
|
||||
var _this = this;
|
||||
search.setFilter('tasks', function(query) {
|
||||
return _this.setFilter(query);
|
||||
});
|
||||
};
|
||||
|
||||
SearchBusinessLayer.prototype.setFilter = function(query) {
|
||||
var _this = this;
|
||||
return _this._$rootScope.$apply(function() {
|
||||
_this._$searchString = query;
|
||||
});
|
||||
};
|
||||
|
||||
SearchBusinessLayer.prototype.cleanSearch = function() {
|
||||
var _this = this;
|
||||
return _this._$rootScope.$apply(function() {
|
||||
_this._$searchString = '';
|
||||
});
|
||||
};
|
||||
|
||||
SearchBusinessLayer.prototype.getFilter = function() {
|
||||
return this._$searchString;
|
||||
};
|
||||
|
||||
SearchBusinessLayer.prototype.initialize = function() {
|
||||
|
||||
var version = OC.config.version.split('.');
|
||||
|
||||
if (version[0] >= 14) {
|
||||
OC.Search = new OCA.Search(this.setFilter, this.cleanSearch);
|
||||
} else {
|
||||
OC.Plugins.register('OCA.Search', this);
|
||||
}
|
||||
};
|
||||
|
||||
return SearchBusinessLayer;
|
||||
|
||||
})();
|
||||
return new SearchBusinessLayer(ListsModel, Persistence, TasksModel, $rootScope, $routeParams, $location);
|
||||
}
|
||||
]);
|
||||
|
||||
}).call(this);
|
|
@ -1,403 +0,0 @@
|
|||
/**
|
||||
* Nextcloud - Tasks
|
||||
*
|
||||
* @author Raimund Schlüßler
|
||||
* @copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>
|
||||
*
|
||||
* 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() {
|
||||
'use strict';
|
||||
var __hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) {
|
||||
for (var key in parent) {
|
||||
if (__hasProp.call(parent, key)) {
|
||||
child[key] = parent[key];
|
||||
}
|
||||
}
|
||||
function Ctor() {
|
||||
this.constructor = child;
|
||||
}
|
||||
Ctor.prototype = parent.prototype;
|
||||
child.prototype = new Ctor();
|
||||
child.__super__ = parent.prototype;
|
||||
return child;
|
||||
},
|
||||
__indexOf = [].indexOf || function(item) {
|
||||
for (var i = 0, l = this.length; i < l; i++) {
|
||||
if (i in this && this[i] === item) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
angular.module('Tasks').factory('TasksModel', [
|
||||
'_Model', function(_Model) {
|
||||
var TasksModel = (function(_super) {
|
||||
|
||||
function TasksModel() {
|
||||
this._tmpIdCache = {};
|
||||
TasksModel.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
__extends(TasksModel, _super);
|
||||
|
||||
TasksModel.prototype.ad = function(task, clearCache) {
|
||||
if (clearCache === null) {
|
||||
clearCache = true;
|
||||
}
|
||||
var updateByUri = angular.isDefined(task.uri) && angular.isDefined(this.getByUri(task.uri));
|
||||
if (updateByUri) {
|
||||
return this.update(task, clearCache);
|
||||
} else {
|
||||
if (angular.isDefined(task.uri)) {
|
||||
if (clearCache) {
|
||||
this._invalidateCache();
|
||||
}
|
||||
if (!angular.isDefined(this._dataMap[task.uri])) {
|
||||
this._data.push(task);
|
||||
this._dataMap[task.uri] = task;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TasksModel.prototype.getByUri = function(uri) {
|
||||
return this._dataMap[uri];
|
||||
};
|
||||
|
||||
TasksModel.prototype.update = function(task, clearCache) {
|
||||
|
||||
var entry, key, value, _results;
|
||||
if (clearCache === null) {
|
||||
clearCache = true;
|
||||
}
|
||||
if (clearCache) {
|
||||
this._invalidateCache();
|
||||
}
|
||||
entry = this.getByUri(task.uri);
|
||||
entry.components = task.components;
|
||||
entry.components.toString();
|
||||
return entry;
|
||||
};
|
||||
|
||||
TasksModel.prototype.removeById = function(taskID) {
|
||||
return TasksModel.__super__.removeById.call(this, taskID);
|
||||
};
|
||||
|
||||
TasksModel.prototype["delete"] = function(task, clearCache) {
|
||||
var counter, data, entry, _i, _len, _ref;
|
||||
if (clearCache === null) {
|
||||
clearCache = true;
|
||||
}
|
||||
_ref = this._data;
|
||||
for (counter = _i = 0, _len = _ref.length; _i < _len; counter = ++_i) {
|
||||
entry = _ref[counter];
|
||||
if (entry === task) {
|
||||
this._data.splice(counter, 1);
|
||||
data = this._dataMap[task.uri];
|
||||
delete this._dataMap[task.uri];
|
||||
if (clearCache) {
|
||||
this._invalidateCache();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TasksModel.prototype.removeByList = function(listID) {
|
||||
var id, task, taskIDs, tasks, _results;
|
||||
tasks = this.getAll();
|
||||
taskIDs = [];
|
||||
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
|
||||
task = tasks[_i];
|
||||
if (task.calendarid === listID) {
|
||||
taskIDs.push(task.uid);
|
||||
}
|
||||
}
|
||||
_results = [];
|
||||
for (var _j = 0, _len1 = taskIDs.length; _j < _len1; _j++) {
|
||||
id = taskIDs[_j];
|
||||
_results.push(this.removeById(id));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
TasksModel.prototype.taskAtDay = function(task, date) {
|
||||
var diff, due, duediff, start, startdiff;
|
||||
start = moment(task.start, "YYYYMMDDTHHmmss");
|
||||
due = moment(task.due, "YYYYMMDDTHHmmss");
|
||||
if (start.isValid() && !due.isValid()) {
|
||||
diff = start.diff(moment().startOf('day'), 'days', true);
|
||||
if (!date && diff < date + 1) {
|
||||
return true;
|
||||
} else if (diff < date + 1 && diff >= date) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (due.isValid() && !start.isValid()) {
|
||||
diff = due.diff(moment().startOf('day'), 'days', true);
|
||||
if (!date && diff < date + 1) {
|
||||
return true;
|
||||
} else if (diff < date + 1 && diff >= date) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (start.isValid() && due.isValid()) {
|
||||
startdiff = start.diff(moment().startOf('day'), 'days', true);
|
||||
duediff = due.diff(moment().startOf('day'), 'days', true);
|
||||
if (!date && (startdiff < date + 1 || duediff < date + 1)) {
|
||||
return true;
|
||||
} else if (startdiff < date + 1 && startdiff >= date && duediff >= date) {
|
||||
return true;
|
||||
} else if (duediff < date + 1 && duediff >= date && startdiff >= date) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.isLoaded = function(task) {
|
||||
if (this.getByUid(task.uid)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
TasksModel.prototype.hasSubtasks = function(uid) {
|
||||
var tasks = this.getAll();
|
||||
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
|
||||
var task = tasks[_i];
|
||||
if (task.related === uid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.hasCompletedSubtasks = function(uid) {
|
||||
var tasks = this.getAll();
|
||||
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
|
||||
var task = tasks[_i];
|
||||
if (task.related === uid && task.completed) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.hasNoParent = function(task) {
|
||||
if (!task.related) {
|
||||
return true;
|
||||
} else {
|
||||
var tasks = this.getAll();
|
||||
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
|
||||
var t = tasks[_i];
|
||||
if (task.related === t.uid && task !== t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
TasksModel.prototype.getUriByUid = function(uid) {
|
||||
var tasks = this.getAll();
|
||||
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
|
||||
var task = tasks[_i];
|
||||
if (task.uid === uid) {
|
||||
return task.uri;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.getByUid = function(uid) {
|
||||
var tasks = this.getAll();
|
||||
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
|
||||
var task = tasks[_i];
|
||||
if (task.uid === uid) {
|
||||
return task;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
TasksModel.prototype.getChildren = function(task) {
|
||||
var children, t, tasks;
|
||||
tasks = this.getAll();
|
||||
children = [];
|
||||
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
|
||||
t = tasks[_i];
|
||||
if (t.related === task.uid && t !== task) {
|
||||
children.push(t);
|
||||
}
|
||||
}
|
||||
return children;
|
||||
};
|
||||
|
||||
TasksModel.prototype.getDescendantIDs = function(task) {
|
||||
var child, children, descendantIDs;
|
||||
children = this.getChildren(task);
|
||||
descendantIDs = [];
|
||||
for (var _i = 0, _len = children.length; _i < _len; _i++) {
|
||||
child = children[_i];
|
||||
descendantIDs = descendantIDs.concat(child.uri);
|
||||
descendantIDs = descendantIDs.concat(this.getDescendantIDs(child));
|
||||
}
|
||||
return descendantIDs;
|
||||
};
|
||||
|
||||
TasksModel.prototype.filterTasks = function(task, filter) {
|
||||
switch (filter) {
|
||||
case 'completed':
|
||||
return task.completed === true;
|
||||
case 'all':
|
||||
return task.completed === false;
|
||||
case 'current':
|
||||
return task.completed === false && this.current(task.start, task.due);
|
||||
case 'starred':
|
||||
return task.completed === false && task.priority > 5;
|
||||
case 'today':
|
||||
return task.completed === false && (this.today(task.start) || this.today(task.due));
|
||||
case 'week':
|
||||
return task.completed === false && (this.week(task.start) || this.week(task.due));
|
||||
default:
|
||||
return '' + task.calendar.uri === '' + filter;
|
||||
}
|
||||
};
|
||||
|
||||
TasksModel.prototype.filteredTasks = function(needle) {
|
||||
var ancestors, parentID, ret, task, tasks;
|
||||
ret = [];
|
||||
tasks = this.getAll();
|
||||
if (!needle) {
|
||||
ret = tasks;
|
||||
} else {
|
||||
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
|
||||
task = tasks[_i];
|
||||
if (this.filterTasksByString(task, needle)) {
|
||||
if (this.objectExists(task, ret)) {
|
||||
continue;
|
||||
}
|
||||
ret.push(task);
|
||||
parentID = this.getUriByUid(task.related);
|
||||
ancestors = this.getAncestor(parentID, ret);
|
||||
if (ancestors) {
|
||||
ret = ret.concat(ancestors);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
TasksModel.prototype.objectExists = function(task, ret) {
|
||||
for (var _i = 0, _len = ret.length; _i < _len; _i++) {
|
||||
var re = ret[_i];
|
||||
if (re.uid === task.uid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.filterTasksByString = function(task, filter) {
|
||||
var key, keys, value;
|
||||
keys = ['summary', 'note', 'location', 'categories'];
|
||||
filter = filter.toLowerCase();
|
||||
for (key in task) {
|
||||
value = task[key];
|
||||
if (__indexOf.call(keys, key) >= 0) {
|
||||
if (key === 'categories') {
|
||||
if (this.searchCategories(task.categories, filter)) {
|
||||
return true;
|
||||
}
|
||||
} else if (value.toLowerCase().indexOf(filter) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.getAncestor = function(taskUri, ret) {
|
||||
var ancestors, parentUri, task, tasks;
|
||||
tasks = [];
|
||||
task = this.getByUri(taskUri);
|
||||
if (task) {
|
||||
if (this.objectExists(task, ret)) {
|
||||
return tasks;
|
||||
}
|
||||
tasks.push(task);
|
||||
if (this.hasNoParent(task)) {
|
||||
return tasks;
|
||||
}
|
||||
parentUri = this.getUriByUid(task.related);
|
||||
ancestors = this.getAncestor(parentUri, ret);
|
||||
if (ancestors) {
|
||||
tasks = tasks.concat(ancestors);
|
||||
}
|
||||
}
|
||||
return tasks;
|
||||
};
|
||||
|
||||
TasksModel.prototype.searchCategories = function(categories, filter) {
|
||||
for (var _i = 0, _len = categories.length; _i < _len; _i++) {
|
||||
var category = categories[_i];
|
||||
if (category.toLowerCase().indexOf(filter) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.setReminder = function(taskID, reminder) {
|
||||
return this.update({
|
||||
id: taskID,
|
||||
reminder: reminder
|
||||
});
|
||||
};
|
||||
|
||||
TasksModel.prototype.overdue = function(due) {
|
||||
return moment(due, "YYYYMMDDTHHmmss").isValid() && moment(due, "YYYYMMDDTHHmmss").diff(moment()) < 0;
|
||||
};
|
||||
|
||||
TasksModel.prototype.due = function(due) {
|
||||
return moment(due, 'YYYYMMDDTHHmmss').isValid();
|
||||
};
|
||||
|
||||
TasksModel.prototype.today = function(due) {
|
||||
return moment(due, "YYYYMMDDTHHmmss").isValid() && moment(due, "YYYYMMDDTHHmmss").diff(moment().startOf('day'), 'days', true) < 1;
|
||||
};
|
||||
|
||||
TasksModel.prototype.week = function(due) {
|
||||
return moment(due, "YYYYMMDDTHHmmss").isValid() && moment(due, "YYYYMMDDTHHmmss").diff(moment().startOf('day'), 'days', true) < 7;
|
||||
};
|
||||
|
||||
TasksModel.prototype.current = function(start, due) {
|
||||
return !moment(start, "YYYYMMDDTHHmmss").isValid() || moment(start, "YYYYMMDDTHHmmss").diff(moment(), 'days', true) < 0 || moment(due, "YYYYMMDDTHHmmss").diff(moment(), 'days', true) < 0;
|
||||
};
|
||||
|
||||
return TasksModel;
|
||||
|
||||
})(_Model);
|
||||
return new TasksModel();
|
||||
}
|
||||
]);
|
||||
}).call(this);
|
Loading…
Reference in a new issue