diff options
87 files changed, 9247 insertions, 7643 deletions
diff --git a/.editorconfig b/.editorconfig index aee39726..1c47fb6e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,9 +7,11 @@ end_of_line = lf insert_final_newline = true # Set default charset and indentation -[*.{php,coffee,less}] +[*.{php,js}] charset = utf-8 indent_style = tab +tab_width = 4 +indent_size = 4 # Indentation override for PHP templates [templates/**.php] diff --git a/js/.jshintrc b/js/.jshintrc new file mode 100644 index 00000000..dd19c68c --- /dev/null +++ b/js/.jshintrc @@ -0,0 +1,43 @@ +{ + "esnext": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 4, + "latedef": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonew": true, + "plusplus": false, + "node": true, + "undef": true, + "unused": false, + "strict": true, + "maxparams": false, + "maxdepth": 4, + "browser": true, + "devel": true, + "jquery": true, + "jasmine": true, + "globals": { + "jQuery": true, + "ICAL": true, + "jstz": true, + "moment": true, + "angular": true, + "app": true, + "OC": true, + "oc_current_user":true, + "oc_requesttoken": true, + "requestToken": true, + "inject": true, + "module": true, + "t": true, + "it": true, + "exports": true, + "escapeHTML": true, + "possible": true, + "dav": true + } +} diff --git a/js/Gruntfile.coffee b/js/Gruntfile.coffee deleted file mode 100644 index 934a187d..00000000 --- a/js/Gruntfile.coffee +++ /dev/null @@ -1,136 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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/>. - -### - - -module.exports = (grunt) -> - - grunt.loadNpmTasks('grunt-contrib-concat') - grunt.loadNpmTasks('grunt-contrib-watch') - grunt.loadNpmTasks('grunt-contrib-coffee') - grunt.loadNpmTasks('grunt-coffeelint') - grunt.loadNpmTasks('grunt-wrap') - grunt.loadNpmTasks('grunt-phpunit') - grunt.loadNpmTasks('grunt-karma') - grunt.loadNpmTasks('grunt-newer') - grunt.loadNpmTasks('grunt-phpdocumentor') - - grunt.initConfig - - meta: - pkg: grunt.file.readJSON('package.json') - version: '<%= meta.pkg.version %>' - banner: '/**\n' + - ' * <%= meta.pkg.description %> - v<%= meta.version %>\n' + - ' *\n' + - ' * Copyright (c) <%= grunt.template.today("yyyy") %> - ' + - '<%= meta.pkg.author.name %> <<%= meta.pkg.author.email %>>\n' + - ' *\n' + - ' * This file is licensed under the Affero General Public License version 3 or later.\n' + - ' * See the COPYING file\n' + - ' *\n' + - ' */\n\n' - build: 'build/' - production: 'public/' - - coffee: - default: - expand: true - cwd: "./app" - src: ["**/*.coffee"] - dest: "./build/app" - ext: ".js" - - concat: - default: - options: - banner: '<%= meta.banner %>\n' - stripBanners: - options: 'block' - src: [ - '<%= meta.build %>app/app.js' - '<%= meta.build %>app/directives/*.js' - '<%= meta.build %>app/controllers/*.js' - '<%= meta.build %>app/services/**/*.js' - '<%= meta.build %>app/filters/**/*.js' - ] - dest: '<%= meta.production %>app.js' - wrap: - default: - src: '<%= meta.production %>app.js' - dest: '' - wrapper: [ - '(function(angular, $, moment, undefined){\n\n' - '\n})(window.angular, window.jQuery, window.moment);' - ] - - coffeelint: - default: [ - 'app/**/*.coffee' - 'tests/**/*.coffee' - ] - options: - 'no_tabs': - 'level': 'ignore' - 'indentation': - 'level': 'ignore' - 'no_trailing_whitespace': - 'level': 'warn' - - - watch: - js: - files: ['app/**/*.coffee'] - tasks: 'js' - - karma: - unit: - configFile: 'config/karma.js' - continuous: - configFile: 'config/karma.js' - singleRun: true - browsers: ['PhantomJS'] - reporters: ['progress', 'junit'] - junitReporter: - outputFile: 'test-results.xml' - unit_phantom: - configFile: 'config/karma.js' - browsers: ['PhantomJS'] - - - phpunit: - classes: - dir: '../tests' - options: - colors: true - - phpdocumentor: - default: - options: - directory : '../appinfo,../db,../controllers,../service' - target : '../docs' - - - grunt.registerTask('ci', ['karma:continuous']) - - grunt.registerTask('js', ['newer:coffeelint', 'newer:coffee', 'concat', 'wrap']) - - grunt.registerTask('default', 'js') diff --git a/js/Gruntfile.js b/js/Gruntfile.js new file mode 100644 index 00000000..9e6338f0 --- /dev/null +++ b/js/Gruntfile.js @@ -0,0 +1,124 @@ +/** + * 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/>. + * + */ + + +module.exports = function(grunt) { + 'use strict'; + + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-wrap'); + grunt.loadNpmTasks('grunt-phpunit'); + grunt.loadNpmTasks('grunt-karma'); + // grunt.loadNpmTasks('grunt-newer'); + grunt.loadNpmTasks('grunt-phpdocumentor'); + + grunt.initConfig({ + meta: { + pkg: grunt.file.readJSON('package.json'), + version: '<%= meta.pkg.version %>', + banner: '/**\n' + ' * <%= meta.pkg.description %> - v<%= meta.version %>\n' + ' *\n' + ' * Copyright (c) <%= grunt.template.today("yyyy") %> - ' + '<%= meta.pkg.author.name %> <<%= meta.pkg.author.email %>>\n' + ' *\n' + ' * This file is licensed under the Affero\ + General Public License version 3 or later.\n' + ' * See the COPYING file\n' + ' *\n' + ' */\n\n', + build: 'app/', + production: 'public/' + }, + concat: { + "default": { + options: { + banner: '<%= meta.banner %>\n', + stripBanners: { + options: 'block' + } + }, + src: '<%= meta.build %>/**/*.js', + dest: '<%= meta.production %>app.js' + } + }, + wrap: { + "default": { + src: '<%= meta.production %>app.js', + dest: '', + wrapper: ['(function(angular, $, oc_requesttoken, undefined){\n\n', '\n})(window.angular, window.jQuery, oc_requesttoken);'] + } + }, + + jshint: { + files: [ + 'Gruntfile.js', + '<%= meta.build %>**/*.js' + ], + options: { + jshintrc: '.jshintrc', + reporter: require('jshint-stylish') + } + }, + + watch: { + concat: { + files: [ + '<%= meta.build %>**/*.js' + ], + options: { + livereload: true + }, + tasks: ['js'] + } + }, + karma: { + unit: { + configFile: 'config/karma.js' + }, + continuous: { + configFile: 'config/karma.js', + singleRun: true, + browsers: ['PhantomJS'], + reporters: ['progress', 'junit'], + junitReporter: { + outputFile: 'test-results.xml' + } + }, + unit_phantom: { + configFile: 'config/karma.js', + browsers: ['PhantomJS'] + } + }, + phpunit: { + classes: { + dir: '../tests' + }, + options: { + colors: true + } + }, + phpdocumentor: { + "default": { + options: { + directory: '../appinfo,../db,../controllers,../service', + target: '../docs' + } + } + } + }); + grunt.registerTask('ci', ['karma:continuous']); + grunt.registerTask('js', ['concat', 'wrap']); + grunt.registerTask('default', 'js'); +}; diff --git a/js/app/app.coffee b/js/app/app.coffee deleted file mode 100644 index 4af369a2..00000000 --- a/js/app/app.coffee +++ /dev/null @@ -1,155 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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',['ngRoute','ngAnimate','ui.select', - 'ngSanitize', 'dndLists']) -.config ['$provide','$routeProvider', '$interpolateProvider', '$httpProvider' -($provide, $routeProvider, $interpolateProvider, $httpProvider) -> - $provide.value 'Config', config = - markReadTimeout: 500 - taskUpdateInterval: 1000*600 - - $httpProvider.defaults.headers.common['requesttoken'] = oc_requesttoken - - $routeProvider - .when('/calendars/:calendarID',{}) - .when('/calendars/:calendarID/edit/:listparameter',{}) - .when('/calendars/:calendarID/tasks/:taskID',{}) - .when('/calendars/:calendarID/tasks/:taskID/settings',{}) - .when('/calendars/:calendarID/tasks/:taskID/edit/:parameter',{}) - .when('/collections/:collectionID',{}) - .when('/search/:searchString',{}) - .when('/search/:searchString/tasks/:taskID',{}) - .when('/search/:searchString/tasks/:taskID/edit/:parameter',{}) - # .otherwise({ - # redirectTo: '/collections/all' - # }) - - return -] - -angular.module('Tasks').run ['$document', '$rootScope', 'Config', '$timeout', -'ListsBusinessLayer', 'TasksBusinessLayer', 'SearchBusinessLayer' -($document, $rootScope, Config, $timeout,TasksBusinessLayer, - ListsBusinessLayer, SearchBusinessLayer) -> - - init = false - do update = -> - timeOutUpdate = -> - $timeout update, Config.taskUpdateInterval - # if init - # CollectionsBusinessLayer.updateModel() - # ListsBusinessLayer.updateModel() - # TasksBusinessLayer.updateModel() - init = true - timeOutUpdate() - - OCA.Search.tasks = SearchBusinessLayer - - $('link[rel="shortcut icon"]') - .attr('href', OC.filePath('tasks', 'img', 'favicon.png')) - - $document.click (event) -> - $rootScope.$broadcast 'documentClicked', event - return - - moment.locale('details', { - calendar: { - lastDay : '['+t('tasks','Due yesterday')+'], HH:mm' - sameDay : '['+t('tasks','Due today')+'], HH:mm' - nextDay : '['+t('tasks','Due tomorrow')+'], HH:mm' - lastWeek : '['+t('tasks', 'Due on')+'] MMM DD, YYYY, HH:mm' - nextWeek : '['+t('tasks', 'Due on')+'] MMM DD, YYYY, HH:mm' - sameElse : '['+t('tasks', 'Due on')+'] MMM DD, YYYY, HH:mm' - } - }) - moment.locale('start', { - calendar: { - lastDay : '['+t('tasks','Started yesterday')+'], HH:mm' - sameDay : '['+t('tasks','Starts today')+'], HH:mm' - nextDay : '['+t('tasks','Starts tomorrow')+'], HH:mm' - lastWeek : '['+t('tasks', 'Started on')+'] MMM DD, YYYY, HH:mm' - nextWeek : '['+t('tasks', 'Starts on')+'] MMM DD, YYYY, HH:mm' - sameElse : () -> - if this.diff(moment()) > 0 - '['+t('tasks', 'Starts on')+'] MMM DD, YYYY, HH:mm' - else - '['+t('tasks', 'Started on')+'] MMM DD, YYYY, HH:mm' - } - }) - moment.locale('reminder', { - calendar: { - lastDay : t('tasks', '[Remind me yesterday at ]HH:mm') - sameDay : t('tasks', '[Remind me today at ]HH:mm') - nextDay : t('tasks', '[Remind me tomorrow at ]HH:mm') - lastWeek : t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm') - nextWeek : t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm') - sameElse : t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm') - } - }) - moment.locale('tasks', { - calendar: { - lastDay : '['+t('tasks','Yesterday')+']' - sameDay : '['+t('tasks','Today')+']' - nextDay : '['+t('tasks','Tomorrow')+']' - lastWeek : 'DD.MM.YYYY' - nextWeek : 'DD.MM.YYYY' - sameElse : 'DD.MM.YYYY' - } - }) - moment.locale('details_short', { - calendar: { - lastDay : '['+t('tasks','Yesterday')+']' - sameDay : '['+t('tasks','Today')+']' - nextDay : '['+t('tasks','Tomorrow')+']' - lastWeek : 'MMM DD, YYYY' - nextWeek : 'MMM DD, YYYY' - sameElse : 'MMM DD, YYYY' - } - }) - moment.locale('list_week', { - calendar: { - lastDay : '['+t('tasks','Yesterday')+']' - sameDay : '['+t('tasks','Today')+'], MMM. DD' - nextDay : '['+t('tasks','Tomorrow')+'], MMM. DD' - lastWeek : 'ddd, MMM. DD' - nextWeek : 'ddd, MMM. DD' - sameElse : 'ddd, MMM. DD' - } - }) - moment.locale('en', { - relativeTime: { - future: t('tasks', "in %s") - past: t('tasks', "%s ago") - s: t('tasks', "seconds") - m: t('tasks', "a minute") - mm: t('tasks', "%d minutes") - h: t('tasks', "an hour") - hh: t('tasks', "%d hours") - d: t('tasks', "a day") - dd: t('tasks', "%d days") - M: t('tasks', "a month") - MM: t('tasks', "%d months") - y: t('tasks', "a year") - yy: t('tasks', "%d years") - } - }) -] diff --git a/js/app/app.js b/js/app/app.js new file mode 100644 index 00000000..0ccd10ee --- /dev/null +++ b/js/app/app.js @@ -0,0 +1,138 @@ +/** + * 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', ['ngRoute', 'ngAnimate', 'ui.select', 'ngSanitize', 'dndLists']).config([ + '$provide', '$routeProvider', '$interpolateProvider', '$httpProvider', function($provide, $routeProvider, $interpolateProvider, $httpProvider) { + var config; + $provide.value('Config', config = { + markReadTimeout: 500, + taskUpdateInterval: 1000 * 600 + }); + $httpProvider.defaults.headers.common['requesttoken'] = oc_requesttoken; + $routeProvider.when('/calendars/:calendarID', {}).when('/calendars/:calendarID/edit/:listparameter', {}).when('/calendars/:calendarID/tasks/:taskID', {}).when('/calendars/:calendarID/tasks/:taskID/settings', {}).when('/calendars/:calendarID/tasks/:taskID/edit/:parameter', {}).when('/collections/:collectionID', {}).when('/search/:searchString', {}).when('/search/:searchString/tasks/:taskID', {}).when('/search/:searchString/tasks/:taskID/edit/:parameter', {}); + } + ]); + + angular.module('Tasks').run([ + '$document', '$rootScope', 'Config', '$timeout', 'ListsBusinessLayer', 'TasksBusinessLayer', 'SearchBusinessLayer', function($document, $rootScope, Config, $timeout, TasksBusinessLayer, ListsBusinessLayer, SearchBusinessLayer) { + var init, update; + init = false; + (update = function() { + var timeOutUpdate; + timeOutUpdate = function() { + return $timeout(update, Config.taskUpdateInterval); + }; + init = true; + return timeOutUpdate(); + })(); + OCA.Search.tasks = SearchBusinessLayer; + $('link[rel="shortcut icon"]').attr('href', OC.filePath('tasks', 'img', 'favicon.png')); + $document.click(function(event) { + $rootScope.$broadcast('documentClicked', event); + }); + moment.locale('details', { + calendar: { + lastDay: '[' + t('tasks', 'Due yesterday') + '], HH:mm', + sameDay: '[' + t('tasks', 'Due today') + '], HH:mm', + nextDay: '[' + t('tasks', 'Due tomorrow') + '], HH:mm', + lastWeek: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm', + nextWeek: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm', + sameElse: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm' + } + }); + moment.locale('start', { + calendar: { + lastDay: '[' + t('tasks', 'Started yesterday') + '], HH:mm', + sameDay: '[' + t('tasks', 'Starts today') + '], HH:mm', + nextDay: '[' + t('tasks', 'Starts tomorrow') + '], HH:mm', + lastWeek: '[' + t('tasks', 'Started on') + '] MMM DD, YYYY, HH:mm', + nextWeek: '[' + t('tasks', 'Starts on') + '] MMM DD, YYYY, HH:mm', + sameElse: function() { + if (this.diff(moment()) > 0) { + return '[' + t('tasks', 'Starts on') + '] MMM DD, YYYY, HH:mm'; + } else { + return '[' + t('tasks', 'Started on') + '] MMM DD, YYYY, HH:mm'; + } + } + } + }); + moment.locale('reminder', { + calendar: { + lastDay: t('tasks', '[Remind me yesterday at ]HH:mm'), + sameDay: t('tasks', '[Remind me today at ]HH:mm'), + nextDay: t('tasks', '[Remind me tomorrow at ]HH:mm'), + lastWeek: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm'), + nextWeek: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm'), + sameElse: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm') + } + }); + moment.locale('tasks', { + calendar: { + lastDay: '[' + t('tasks', 'Yesterday') + ']', + sameDay: '[' + t('tasks', 'Today') + ']', + nextDay: '[' + t('tasks', 'Tomorrow') + ']', + lastWeek: 'DD.MM.YYYY', + nextWeek: 'DD.MM.YYYY', + sameElse: 'DD.MM.YYYY' + } + }); + moment.locale('details_short', { + calendar: { + lastDay: '[' + t('tasks', 'Yesterday') + ']', + sameDay: '[' + t('tasks', 'Today') + ']', + nextDay: '[' + t('tasks', 'Tomorrow') + ']', + lastWeek: 'MMM DD, YYYY', + nextWeek: 'MMM DD, YYYY', + sameElse: 'MMM DD, YYYY' + } + }); + moment.locale('list_week', { + calendar: { + lastDay: '[' + t('tasks', 'Yesterday') + ']', + sameDay: '[' + t('tasks', 'Today') + '], MMM. DD', + nextDay: '[' + t('tasks', 'Tomorrow') + '], MMM. DD', + lastWeek: 'ddd, MMM. DD', + nextWeek: 'ddd, MMM. DD', + sameElse: 'ddd, MMM. DD' + } + }); + return moment.locale('en', { + relativeTime: { + future: t('tasks', "in %s"), + past: t('tasks', "%s ago"), + s: t('tasks', "seconds"), + m: t('tasks', "a minute"), + mm: t('tasks', "%d minutes"), + h: t('tasks', "an hour"), + hh: t('tasks', "%d hours"), + d: t('tasks', "a day"), + dd: t('tasks', "%d days"), + M: t('tasks', "a month"), + MM: t('tasks', "%d months"), + y: t('tasks', "a year"), + yy: t('tasks', "%d years") + } + }); + } + ]); + +}).call(this); diff --git a/js/app/controllers/appcontroller.coffee b/js/app/controllers/appcontroller.coffee deleted file mode 100644 index f14cdd3f..00000000 --- a/js/app/controllers/appcontroller.coffee +++ /dev/null @@ -1,91 +0,0 @@ -### - -ownCloud - News - -@author Alessandro Cosentino -@copyright 2013 Alessandro Cosentino cosenal@gmail.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/>. - -### - - -angular.module('Tasks').controller 'AppController', -['$scope', 'ListsBusinessLayer', '$route', 'Status', '$timeout', -'$location', '$routeParams', 'Loading', 'SettingsModel', 'Persistence', -($scope, ListsBusinessLayer, $route, status, $timeout, $location, -$routeParams, Loading, SettingsModel, Persistence) -> - - class AppController - - constructor: (@_$scope, @_$listsbusinesslayer, @_$route, @_$status, - @_$timeout, @_$location, @_$routeparams, @_Loading, - @_$settingsmodel, @_persistence) -> - - @_$scope.initialized = false - - @_$scope.status = @_$status.getStatus() - - @_$scope.route = @_$routeparams - - @_$scope.status.newListName = "" - - @_$scope.settingsmodel = @_$settingsmodel - - @_$listsbusinesslayer.init().then(()-> - $scope.$apply() - ) - - @_persistence.init() - - # successCallback = => - # @_$scope.initialized = true - # @_$scope.$apply() - # console.log('initialized') - - # @_$listsbusinesslayer.init().then((calendars) -> - # $scope.calendars = calendars - # console.log($scope.calendars) - # $scope.$apply() - # ) - # console.log($scope.calendars) - - @_$scope.closeAll = ($event) -> - if $($event.target).closest('.close-all').length || - $($event.currentTarget).is($($event.target).closest('.handler')) - if not angular.isUndefined(_$scope.route.calendarID) - _$location.path('/calendars/'+_$scope.route.calendarID) - else if not angular.isUndefined(_$scope.route.collectionID) - _$location.path('/collections/'+_$scope.route.collectionID) - else - _$location.path('/collections/all') - _$scope.status.addingList = false - _$scope.status.focusTaskInput = false - _$scope.status.newListName = "" - if !$($event.target).closest('.newList').length - _$scope.status.addingList = false - _$scope.status.newListName = "" - if !$($event.target).closest('.add-subtask').length - _$scope.status.addSubtaskTo = '' - _$scope.status.focusSubtaskInput = false - else - return - - @_$scope.isLoading = () -> - return _Loading.isLoading() - - return new AppController($scope, ListsBusinessLayer, $route, status, $timeout, - $location, $routeParams, Loading, SettingsModel, Persistence) - -] diff --git a/js/app/controllers/appcontroller.js b/js/app/controllers/appcontroller.js new file mode 100644 index 00000000..4ab9379c --- /dev/null +++ b/js/app/controllers/appcontroller.js @@ -0,0 +1,84 @@ +/** + * 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('AppController', [ + '$scope', 'ListsBusinessLayer', '$route', 'Status', '$timeout', '$location', '$routeParams', 'Loading', 'SettingsModel', 'Persistence', function($scope, ListsBusinessLayer, $route, status, $timeout, $location, $routeParams, Loading, SettingsModel, Persistence) { + var AppController; + AppController = (function() { + function AppController(_$scope, _$listsbusinesslayer, _$route, _$status, _$timeout, _$location, _$routeparams, _Loading, _$settingsmodel, _persistence) { + this._$scope = _$scope; + this._$listsbusinesslayer = _$listsbusinesslayer; + this._$route = _$route; + this._$status = _$status; + this._$timeout = _$timeout; + this._$location = _$location; + this._$routeparams = _$routeparams; + this._Loading = _Loading; + this._$settingsmodel = _$settingsmodel; + this._persistence = _persistence; + this._$scope.initialized = false; + this._$scope.status = this._$status.getStatus(); + this._$scope.route = this._$routeparams; + this._$scope.status.newListName = ""; + this._$scope.settingsmodel = this._$settingsmodel; + this._$listsbusinesslayer.init().then(function() { + return $scope.$apply(); + }); + + this._persistence.init(); + this._$scope.closeAll = function($event) { + if ($($event.target).closest('.close-all').length || $($event.currentTarget).is($($event.target).closest('.handler'))) { + if (!angular.isUndefined(_$scope.route.calendarID)) { + _$location.path('/calendars/' + _$scope.route.calendarID); + } else if (!angular.isUndefined(_$scope.route.collectionID)) { + _$location.path('/collections/' + _$scope.route.collectionID); + } else { + _$location.path('/collections/all'); + } + _$scope.status.addingList = false; + _$scope.status.focusTaskInput = false; + _$scope.status.newListName = ""; + } + if (!$($event.target).closest('.newList').length) { + _$scope.status.addingList = false; + _$scope.status.newListName = ""; + } + if (!$($event.target).closest('.add-subtask').length) { + _$scope.status.addSubtaskTo = ''; + return _$scope.status.focusSubtaskInput = false; + } else { + + } + }; + this._$scope.isLoading = function() { + return _Loading.isLoading(); + }; + } + + return AppController; + + })(); + return new AppController($scope, ListsBusinessLayer, $route, status, $timeout, $location, $routeParams, Loading, SettingsModel, Persistence); + } + ]); + +}).call(this); diff --git a/js/app/controllers/detailscontroller.coffee b/js/app/controllers/detailscontroller.coffee deleted file mode 100644 index 2a087d7a..00000000 --- a/js/app/controllers/detailscontroller.coffee +++ /dev/null @@ -1,380 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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 'DetailsController', -['$scope', '$window', 'TasksModel', 'TasksBusinessLayer', -'$route', '$location', '$timeout', '$routeParams', -'SettingsModel', 'Loading', -($scope, $window, TasksModel, TasksBusinessLayer, $route, $location, -$timeout, $routeParams, SettingsModel, Loading) -> - - class DetailsController - - constructor: (@_$scope, @_$window, @_$tasksmodel, - @_tasksbusinesslayer, @_$route, @_$location, @_$timeout, - @_$routeparams, @_$settingsmodel, @_Loading) -> - - @_$scope.task = _$tasksmodel.getById(_$scope.route.taskID) - - @_$scope.found = true - - @_$scope.$on('$routeChangeSuccess', () -> - task = _$tasksmodel.getById(_$scope.route.taskID) - if !(angular.isUndefined(task) || task == null) - _$scope.task = task - _$scope.found = true - else if (_$scope.route.taskID != undefined) - _$scope.found = false - _tasksbusinesslayer.getTask _$scope.route.taskID - , (data) => - _$scope.loadTask(_$scope.route.taskID) - ) - - @_$scope.settingsmodel = @_$settingsmodel - - # workaroung till https://github.com/angular-ui/ui-select/issues/587 - # is resolved - @_$scope.settingsmodel.add({ - 'id': 'various', - 'categories': [] - }) - - @_$scope.isAddingComment = false - - @_$scope.timers = [] - - @_$scope.durations = [ - { - name: t('tasks','week'), - names: t('tasks','weeks'), - id: 'week'}, - { - name: t('tasks','day'), - names: t('tasks','days'), - id: 'day'}, - { - name: t('tasks','hour'), - names: t('tasks','hours'), - id: 'hour'}, - { - name: t('tasks','minute'), - names: t('tasks','minutes'), - id: 'minute'}, - { - name: t('tasks','second'), - names: t('tasks','seconds'), - id: 'second'} - ] - - @_$scope.loadTask = (taskID) -> - task = _$tasksmodel.getById(_$scope.route.taskID) - if !(angular.isUndefined(task) || task == null) - _$scope.task = task - _$scope.found = true - - @_$scope.TaskState = () -> - if _$scope.found - return 'found' - else - if _Loading.isLoading() - return 'loading' - else - return null - - @_$scope.params = [ - { - name: t('tasks','before beginning'), - invert: true - related:'START', - id: "10"}, - { - name: t('tasks','after beginning'), - invert: false - related:'START', - id: "00"}, - { - name: t('tasks','before end'), - invert: true - related:'END', - id: "11"}, - { - name: t('tasks','after end'), - invert: false - related:'END', - id: "01"} - ] - - @_$scope.filterParams = (params) -> - task = _$tasksmodel.getById(_$scope.route.taskID) - if !(angular.isUndefined(task) || task == null) - if task.due && task.start - return params - else if task.start - return params.slice(0,2) - else - return params.slice(2) - - @_$scope.deleteTask = (taskID) -> - _$timeout(() -> - _tasksbusinesslayer.deleteTask taskID - ,500) - - @_$scope.editName = ($event) -> - if $($event.target).is('a') - return - else - console.log('open edit page') - _$location.path('/lists/'+_$scope.route.listID + - '/tasks/' + _$scope.route.taskID + '/edit/name') - - @_$scope.editDueDate = ($event) -> - if $($event.currentTarget).is($($event.target).closest('.handler')) - _$location.path('/lists/'+_$scope.route.listID + - '/tasks/' + _$scope.route.taskID + '/edit/duedate') - _tasksbusinesslayer.initDueDate(_$scope.route.taskID) - else - return - - @_$scope.editStart = ($event) -> - if $($event.currentTarget).is($($event.target).closest('.handler')) - _$location.path('/lists/'+_$scope.route.listID + - '/tasks/' + _$scope.route.taskID + '/edit/startdate') - _tasksbusinesslayer.initStartDate(_$scope.route.taskID) - else - return - - @_$scope.editReminder = ($event) -> - if $($event.currentTarget).is($($event.target).closest('.handler')) - _$location.path('/lists/'+_$scope.route.listID + - '/tasks/' + _$scope.route.taskID + '/edit/reminder') - _tasksbusinesslayer.initReminder(_$scope.route.taskID) - else - return - - @_$scope.editNote = ($event) -> - if $($event.currentTarget).is($($event.target).closest('.handler')) - if $($event.target).is('a') - return - else - _$location.path('/lists/'+_$scope.route.listID + - '/tasks/' + _$scope.route.taskID + '/edit/note') - else - return - - @_$scope.editPriority = ($event) -> - if $($event.currentTarget).is($($event.target).closest('.handler')) - _$location.path('/lists/'+_$scope.route.listID + - '/tasks/' + _$scope.route.taskID + '/edit/priority') - else - return - - @_$scope.editPercent = ($event) -> - if $($event.currentTarget).is($($event.target).closest('.handler')) - _$location.path('/lists/'+_$scope.route.listID + - '/tasks/' + _$scope.route.taskID + '/edit/percent') - else - return - - @_$scope.endEdit = ($event) -> - if $($event.target).closest('.end-edit').length || - $($event.currentTarget).is($($event.target).closest('.handler')) - _$scope.resetRoute() - else - return - - @_$scope.endName = ($event) -> - if ($event.keyCode == 13) - $event.preventDefault() - _$scope.resetRoute() - if($event.keyCode == 27) - _$scope.resetRoute() - - @_$scope.resetRoute = () -> - _$location.path('/lists/'+_$scope.route.listID + - '/tasks/' + _$scope.route.taskID) - - @_$scope.deleteDueDate = () -> - _tasksbusinesslayer.deleteDueDate(_$scope.route.taskID) - - @_$scope.deletePercent = () -> - _tasksbusinesslayer.setPercentComplete(_$scope.route.taskID,0) - - @_$scope.deleteStartDate = () -> - _tasksbusinesslayer.deleteStartDate(_$scope.route.taskID) - - @_$scope.deleteReminder = () -> - _tasksbusinesslayer.deleteReminderDate(_$scope.route.taskID) - - @_$scope.toggleCompleted = (taskID) -> - if _$tasksmodel.completed(taskID) - _tasksbusinesslayer.uncompleteTask(taskID) - else - _tasksbusinesslayer.completeTask(taskID) - - @_$scope.toggleStarred = (taskID) -> - if _$tasksmodel.starred(taskID) - _tasksbusinesslayer.unstarTask(taskID) - else - _tasksbusinesslayer.starTask(taskID) - - @_$scope.deletePriority = () -> - _tasksbusinesslayer.unstarTask(_$scope.route.taskID) - - @_$scope.isDue = (date) -> - return _$tasksmodel.due(date) - - @_$scope.isOverDue = (date) -> - return _$tasksmodel.overdue(date) - - @_$scope.$watch('task', (newVal, oldVal) -> - if newVal == oldVal || undefined in [newVal, oldVal] || - newVal.id != oldVal.id - return - else - if newVal.name != oldVal.name - if _$scope.timers['task'+newVal.id+'name'] - $timeout.cancel(_$scope.timers['task'+newVal.id+'name']) - _$scope.timers['task'+newVal.id+'name'] = $timeout( () -> - _tasksbusinesslayer.setTaskName(newVal.id,newVal.name) - ,3000) - if newVal.note != oldVal.note - if _$scope.timers['task'+newVal.id+'note'] - $timeout.cancel(_$scope.timers['task'+newVal.id+'note']) - _$scope.timers['task'+newVal.id+'note'] = $timeout( () -> - _tasksbusinesslayer.setTaskNote(newVal.id,newVal.note) - ,5000) - if newVal.complete != oldVal.complete - if _$scope.timers['task'+newVal.id+'complete'] - $timeout.cancel(_$scope.timers['task'+newVal.id+'complete']) - _$scope.timers['task'+newVal.id+'complete'] = $timeout( () -> - _tasksbusinesslayer.setPercentComplete(newVal.id, - newVal.complete) - ,1000) - if newVal.priority != oldVal.priority - if _$scope.timers['task'+newVal.id+'priority'] - $timeout.cancel(_$scope.timers['task'+newVal.id+'priority']) - _$scope.timers['task'+newVal.id+'priority'] = $timeout( () -> - _tasksbusinesslayer.setPriority(newVal.id, - newVal.priority) - ,1000) - ,true) - - @_$scope.setstartday = (date) -> - _tasksbusinesslayer.setStart(_$scope.route.taskID, - moment(date,'MM/DD/YYYY'),'day') - - @_$scope.setstarttime = (date) -> - _tasksbusinesslayer.setStart(_$scope.route.taskID, - moment(date,'HH:mm'),'time') - - @_$scope.setdueday = (date) -> - _tasksbusinesslayer.setDue(_$scope.route.taskID, - moment(date,'MM/DD/YYYY'),'day') - - @_$scope.setduetime = (date) -> - _tasksbusinesslayer.setDue(_$scope.route.taskID, - moment(date,'HH:mm'),'time') - - @_$scope.setreminderday = (date) -> - _tasksbusinesslayer.setReminderDate(_$scope.route.taskID, - moment(date,'MM/DD/YYYY'),'day') - - @_$scope.setremindertime = (date) -> - _tasksbusinesslayer.setReminderDate(_$scope.route.taskID, - moment(date,'HH:mm'),'time') - - @_$scope.reminderType = (task) -> - if !angular.isUndefined(task) - if task.reminder == null - if moment(task.start, "YYYYMMDDTHHmmss").isValid() || - moment(task.due, "YYYYMMDDTHHmmss").isValid() - return 'DURATION' - else - return 'DATE-TIME' - else - return task.reminder.type - - @_$scope.changeReminderType = (task) -> - _tasksbusinesslayer.checkReminderDate(task.id) - if @reminderType(task) == 'DURATION' - if task.reminder - task.reminder.type = 'DATE-TIME' - else - task.reminder = {type:'DATE-TIME'} - else - if task.reminder - task.reminder.type = 'DURATION' - else - task.reminder = {type:'DURATION'} - _tasksbusinesslayer.setReminder(task.id) - - - @_$scope.setReminderDuration = (taskID) -> - _tasksbusinesslayer.setReminder(_$scope.route.taskID) - - @_$scope.addComment = () -> - if _$scope.CommentContent - _$scope.isAddingComment = true - - comment = { - tmpID: 'newComment' + Date.now() - comment: _$scope.CommentContent - taskID: _$scope.route.taskID - time: moment().format('YYYYMMDDTHHmmss') - name: $('#expandDisplayName').text() - } - - _tasksbusinesslayer.addComment comment - , (data) => - _$tasksmodel.updateComment(data) - _$scope.isAddingComment = false - , => - _$scope.isAddingComment = false - - _$scope.CommentContent = '' - - @_$scope.sendComment = (event) -> - if (event.keyCode == 13) - _$scope.addComment() - - @_$scope.deleteComment = (commentID) -> - _tasksbusinesslayer.deleteComment(_$scope.route.taskID, commentID) - - @_$scope.commentStrings = () -> - { - button: t('tasks','Comment'), - input: t('tasks','Add a comment') - } - - @_$scope.addCategory = (category, model) -> - _tasksbusinesslayer.addCategory(_$scope.route.taskID, category) - categories = _$scope.settingsmodel.getById('various').categories - if !(categories.indexOf(category) > -1) - categories.push(category) - - @_$scope.removeCategory = (category, model) -> - _tasksbusinesslayer.removeCategory(_$scope.route.taskID, category) - _$scope.resetRoute() - - return new DetailsController($scope, $window, TasksModel, - TasksBusinessLayer, $route, $location, $timeout, $routeParams, - SettingsModel, Loading) -] diff --git a/js/app/controllers/detailscontroller.js b/js/app/controllers/detailscontroller.js new file mode 100644 index 00000000..366cd302 --- /dev/null +++ b/js/app/controllers/detailscontroller.js @@ -0,0 +1,404 @@ +/** + * 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('DetailsController', [ + '$scope', '$window', 'TasksModel', 'TasksBusinessLayer', '$route', '$location', '$timeout', '$routeParams', 'SettingsModel', 'Loading', function($scope, $window, TasksModel, TasksBusinessLayer, $route, $location, $timeout, $routeParams, SettingsModel, Loading) { + var DetailsController; + DetailsController = (function() { + function DetailsController(_$scope, _$window, _$tasksmodel, _tasksbusinesslayer, _$route, _$location, _$timeout, _$routeparams, _$settingsmodel, _Loading) { + this._$scope = _$scope; + this._$window = _$window; + this._$tasksmodel = _$tasksmodel; + this._tasksbusinesslayer = _tasksbusinesslayer; + this._$route = _$route; + this._$location = _$location; + this._$timeout = _$timeout; + this._$routeparams = _$routeparams; + this._$settingsmodel = _$settingsmodel; + this._Loading = _Loading; + this._$scope.task = _$tasksmodel.getById(_$scope.route.taskID); + this._$scope.found = true; + this._$scope.$on('$routeChangeSuccess', function() { + var task, + _this = this; + task = _$tasksmodel.getById(_$scope.route.taskID); + if (!(angular.isUndefined(task) || task === null)) { + _$scope.task = task; + return _$scope.found = true; + } else if (_$scope.route.taskID !== void 0) { + _$scope.found = false; + return _tasksbusinesslayer.getTask(_$scope.route.taskID, function(data) { + return _$scope.loadTask(_$scope.route.taskID); + }); + } + }); + this._$scope.settingsmodel = this._$settingsmodel; + this._$scope.settingsmodel.add({ + 'id': 'various', + 'categories': [] + }); + this._$scope.isAddingComment = false; + this._$scope.timers = []; + this._$scope.durations = [ + { + name: t('tasks', 'week'), + names: t('tasks', 'weeks'), + id: 'week' + }, { + name: t('tasks', 'day'), + names: t('tasks', 'days'), + id: 'day' + }, { + name: t('tasks', 'hour'), + names: t('tasks', 'hours'), + id: 'hour' + }, { + name: t('tasks', 'minute'), + names: t('tasks', 'minutes'), + id: 'minute' + }, { + name: t('tasks', 'second'), + names: t('tasks', 'seconds'), + id: 'second' + } + ]; + this._$scope.loadTask = function(taskID) { + var task; + task = _$tasksmodel.getById(_$scope.route.taskID); + if (!(angular.isUndefined(task) || task === null)) { + _$scope.task = task; + return _$scope.found = true; + } + }; + this._$scope.TaskState = function() { + if (_$scope.found) { + return 'found'; + } else { + if (_Loading.isLoading()) { + return 'loading'; + } else { + return null; + } + } + }; + this._$scope.params = [ + { + name: t('tasks', 'before beginning'), + invert: true, + related: 'START', + id: "10" + }, { + name: t('tasks', 'after beginning'), + invert: false, + related: 'START', + id: "00" + }, { + name: t('tasks', 'before end'), + invert: true, + related: 'END', + id: "11" + }, { + name: t('tasks', 'after end'), + invert: false, + related: 'END', + id: "01" + } + ]; + this._$scope.filterParams = function(params) { + var task; + task = _$tasksmodel.getById(_$scope.route.taskID); + if (!(angular.isUndefined(task) || task === null)) { + if (task.due && task.start) { + return params; + } else if (task.start) { + return params.slice(0, 2); + } else { + return params.slice(2); + } + } + }; + this._$scope.deleteTask = function(taskID) { + return _$timeout(function() { + return _tasksbusinesslayer.deleteTask(taskID); + }, 500); + }; + this._$scope.editName = function($event) { + if ($($event.target).is('a')) { + + } else { + console.log('open edit page'); + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/name'); + } + }; + this._$scope.editDueDate = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/duedate'); + return _tasksbusinesslayer.initDueDate(_$scope.route.taskID); + } else { + + } + }; + this._$scope.editStart = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/startdate'); + return _tasksbusinesslayer.initStartDate(_$scope.route.taskID); + } else { + + } + }; + this._$scope.editReminder = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/reminder'); + return _tasksbusinesslayer.initReminder(_$scope.route.taskID); + } else { + + } + }; + this._$scope.editNote = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + if ($($event.target).is('a')) { + + } else { + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/note'); + } + } else { + + } + }; + this._$scope.editPriority = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/priority'); + } else { + + } + }; + this._$scope.editPercent = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/percent'); + } else { + + } + }; + this._$scope.endEdit = function($event) { + if ($($event.target).closest('.end-edit').length || $($event.currentTarget).is($($event.target).closest('.handler'))) { + return _$scope.resetRoute(); + } else { + + } + }; + this._$scope.endName = function($event) { + if ($event.keyCode === 13) { + $event.preventDefault(); + _$scope.resetRoute(); + } + if ($event.keyCode === 27) { + return _$scope.resetRoute(); + } + }; + this._$scope.resetRoute = function() { + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID); + }; + this._$scope.deleteDueDate = function() { + return _tasksbusinesslayer.deleteDueDate(_$scope.route.taskID); + }; + this._$scope.deletePercent = function() { + return _tasksbusinesslayer.setPercentComplete(_$scope.route.taskID, 0); + }; + this._$scope.deleteStartDate = function() { + return _tasksbusinesslayer.deleteStartDate(_$scope.route.taskID); + }; + this._$scope.deleteReminder = function() { + return _tasksbusinesslayer.deleteReminderDate(_$scope.route.taskID); + }; + this._$scope.toggleCompleted = function(taskID) { + if (_$tasksmodel.completed(taskID)) { + return _tasksbusinesslayer.uncompleteTask(taskID); + } else { + return _tasksbusinesslayer.completeTask(taskID); + } + }; + this._$scope.toggleStarred = function(taskID) { + if (_$tasksmodel.starred(taskID)) { + return _tasksbusinesslayer.unstarTask(taskID); + } else { + return _tasksbusinesslayer.starTask(taskID); + } + }; + this._$scope.deletePriority = function() { + return _tasksbusinesslayer.unstarTask(_$scope.route.taskID); + }; + this._$scope.isDue = function(date) { + return _$tasksmodel.due(date); + }; + this._$scope.isOverDue = function(date) { + return _$tasksmodel.overdue(date); + }; + this._$scope.$watch('task', function(newVal, oldVal) { + if (newVal === oldVal || (void 0 === newVal || void 0 === oldVal) || newVal.id !== oldVal.id) { + + } else { + if (newVal.name !== oldVal.name) { + if (_$scope.timers['task' + newVal.id + 'name']) { + $timeout.cancel(_$scope.timers['task' + newVal.id + 'name']); + } + _$scope.timers['task' + newVal.id + 'name'] = $timeout(function() { + return _tasksbusinesslayer.setTaskName(newVal.id, newVal.name); + }, 3000); + } + if (newVal.note !== oldVal.note) { + if (_$scope.timers['task' + newVal.id + 'note']) { + $timeout.cancel(_$scope.timers['task' + newVal.id + 'note']); + } + _$scope.timers['task' + newVal.id + 'note'] = $timeout(function() { + return _tasksbusinesslayer.setTaskNote(newVal.id, newVal.note); + }, 5000); + } + if (newVal.complete !== oldVal.complete) { + if (_$scope.timers['task' + newVal.id + 'complete']) { + $timeout.cancel(_$scope.timers['task' + newVal.id + 'complete']); + } + _$scope.timers['task' + newVal.id + 'complete'] = $timeout(function() { + return _tasksbusinesslayer.setPercentComplete(newVal.id, newVal.complete); + }, 1000); + } + if (newVal.priority !== oldVal.priority) { + if (_$scope.timers['task' + newVal.id + 'priority']) { + $timeout.cancel(_$scope.timers['task' + newVal.id + 'priority']); + } + return _$scope.timers['task' + newVal.id + 'priority'] = $timeout(function() { + return _tasksbusinesslayer.setPriority(newVal.id, newVal.priority); + }, 1000); + } + } + }, true); + this._$scope.setstartday = function(date) { + return _tasksbusinesslayer.setStart(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); + }; + this._$scope.setstarttime = function(date) { + return _tasksbusinesslayer.setStart(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); + }; + this._$scope.setdueday = function(date) { + return _tasksbusinesslayer.setDue(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); + }; + this._$scope.setduetime = function(date) { + return _tasksbusinesslayer.setDue(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); + }; + this._$scope.setreminderday = function(date) { + return _tasksbusinesslayer.setReminderDate(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); + }; + this._$scope.setremindertime = function(date) { + return _tasksbusinesslayer.setReminderDate(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); + }; + this._$scope.reminderType = function(task) { + if (!angular.isUndefined(task)) { + if (task.reminder === null) { + if (moment(task.start, "YYYYMMDDTHHmmss").isValid() || moment(task.due, "YYYYMMDDTHHmmss").isValid()) { + return 'DURATION'; + } else { + return 'DATE-TIME'; + } + } else { + return task.reminder.type; + } + } + }; + this._$scope.changeReminderType = function(task) { + _tasksbusinesslayer.checkReminderDate(task.id); + if (this.reminderType(task) === 'DURATION') { + if (task.reminder) { + task.reminder.type = 'DATE-TIME'; + } else { + task.reminder = { + type: 'DATE-TIME' + }; + } + } else { + if (task.reminder) { + task.reminder.type = 'DURATION'; + } else { + task.reminder = { + type: 'DURATION' + }; + } + } + return _tasksbusinesslayer.setReminder(task.id); + }; + this._$scope.setReminderDuration = function(taskID) { + return _tasksbusinesslayer.setReminder(_$scope.route.taskID); + }; + this._$scope.addComment = function() { + var comment, + _this = this; + if (_$scope.CommentContent) { + _$scope.isAddingComment = true; + comment = { + tmpID: 'newComment' + Date.now(), + comment: _$scope.CommentContent, + taskID: _$scope.route.taskID, + time: moment().format('YYYYMMDDTHHmmss'), + name: $('#expandDisplayName').text() + }; + _tasksbusinesslayer.addComment(comment, function(data) { + _$tasksmodel.updateComment(data); + return _$scope.isAddingComment = false; + }, function() { + return _$scope.isAddingComment = false; + }); + return _$scope.CommentContent = ''; + } + }; + this._$scope.sendComment = function(event) { + if (event.keyCode === 13) { + return _$scope.addComment(); + } + }; + this._$scope.deleteComment = function(commentID) { + return _tasksbusinesslayer.deleteComment(_$scope.route.taskID, commentID); + }; + this._$scope.commentStrings = function() { + return { + button: t('tasks', 'Comment'), + input: t('tasks', 'Add a comment') + }; + }; + this._$scope.addCategory = function(category, model) { + var categories; + _tasksbusinesslayer.addCategory(_$scope.route.taskID, category); + categories = _$scope.settingsmodel.getById('various').categories; + if (!(categories.indexOf(category) > -1)) { + return categories.push(category); + } + }; + this._$scope.removeCategory = function(category, model) { + _tasksbusinesslayer.removeCategory(_$scope.route.taskID, category); + return _$scope.resetRoute(); + }; + } + + return DetailsController; + + })(); + return new DetailsController($scope, $window, TasksModel, TasksBusinessLayer, $route, $location, $timeout, $routeParams, SettingsModel, Loading); + } + ]); + +}).call(this); diff --git a/js/app/controllers/listcontroller.coffee b/js/app/controllers/listcontroller.coffee deleted file mode 100644 index 94e2c25a..00000000 --- a/js/app/controllers/listcontroller.coffee +++ /dev/null @@ -1,207 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2016 - -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', '$window', '$routeParams', 'ListsModel', -'TasksBusinessLayer', 'CollectionsModel', 'ListsBusinessLayer', -'$location', 'SearchBusinessLayer', 'CalendarService' -($scope, $window, $routeParams, ListsModel, TasksBusinessLayer, -CollectionsModel, ListsBusinessLayer, $location, SearchBusinessLayer, -CalendarService) -> - - class ListController - - constructor: (@_$scope,@_$window,@_$routeParams, - @_$listsmodel, @_$tasksbusinesslayer, @_$collectionsmodel, - @_$listsbusinesslayer, @$location, @_$searchbusinesslayer, - @_$calendarservice) -> - - @_$scope.collections = @_$collectionsmodel.getAll() - @_$scope.calendars = @_$listsmodel.getAll() - - @_$scope.draggedTasks = [] - - @_$scope.TasksBusinessLayer = @_$tasksbusinesslayer - - @_$scope.status.listNameBackup = '' - - @_$scope.deleteList = (calendar) -> - really = confirm(t('tasks', - 'This will delete the Calendar "%s" and all of its entries.') - .replace('%s',calendar.displayname)) - if really - _$listsbusinesslayer.delete(calendar).then(()-> - $location.path('/calendars/'+ - _$listsmodel.getStandardList().uri) - $scope.$apply() - ) - - @_$scope.startAddingList = () -> - # $location.path('/calendars/'+_$scope.route.calendarID) - _$scope.status.addingList = true - - @_$scope.endAddingList = () -> - _$scope.status.addingList = false - _$scope.status.newListName = "" - - @_$scope.checkListInput = (event) -> - if (event.keyCode == 13) - event.preventDefault() - _$scope.submitNewList() - if(event.keyCode == 27) - _$scope.endAddingList() - - @_$scope.submitNewList = () -> - - 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((calendar) -> - $location.path('/calendars/'+calendar.uri) - $scope.$apply() - ) - - # list - # , (data) => - # _$listsmodel.add(data.list) - # $location.path('/lists/'+data.list.id) - # _$scope.isAddingList = false - # , => - # _$scope.status.addingList = false - # _$scope.isAddingList = false - - _$scope.status.newListName = '' - else - alert(t('tasks', - 'The name "%s" is already used.') - .replace('%s',_$scope.status.newListName)) - else - alert(t('tasks', - 'An empty name is not allowed.')) - - @_$scope.editName = (listID) -> - _$scope.status.addingList = false - _$scope.status.listNameBackup = _$listsmodel.getById(listID).displayname - $location.path('/lists/'+_$scope.route.listID+'/edit/name') - - @_$scope.checkName = (event) -> - if not _$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 - _$scope.endEditList() - - @_$scope.submitNewName = () -> - name = _$listsmodel.getById(_$scope.route.listID) - .displayname - if name - if _$listsmodel.checkName(name,_$scope.route.listID) - _$listsbusinesslayer.setListName(_$scope.route.listID) - _$scope.endEditList() - else - alert(t('tasks', - 'The name "%s" is already used.') - .replace('%s',name)) - else - alert(t('tasks', - 'An empty name is not allowed.')) - - @_$scope.endEditList = () -> - $location.path('/lists/'+_$scope.route.listID) - - @_$scope.setListName = (listID, listName) -> - _$listsbusinesslayer.setListName listID listName - - @_$scope.getCollectionCount = (collectionID) -> - filter = _$searchbusinesslayer.getFilter() - return _$collectionsmodel.getCount(collectionID,filter) - - @_$scope.hideCollection = (collectionID) -> - collection = _$collectionsmodel.getById(collectionID) - switch collection.show - when 0 - return true - when 1 - return false - when 2 - return (@getCollectionCount(collectionID) < 1) - - @_$scope.getCollectionString = (collectionID) -> - if collectionID != 'completed' - filter = _$searchbusinesslayer.getFilter() - return _$collectionsmodel.getCount(collectionID,filter) - else - return '' - - @_$scope.getListCount = (listID,type) -> - filter = _$searchbusinesslayer.getFilter() - return _$listsmodel.getCount(listID,type,filter) - - @_$scope.showDelete = (listID) -> - return _$scope.route.listID not in - ['starred', 'today', 'completed', 'week', 'all', 'current'] - - @_$scope.update = () -> - if not _$scope.isLoading() - # _$collectionsbusinesslayer.updateModel() - _$tasksbusinesslayer.updateModel() - _$listsbusinesslayer.updateModel() - - @_$scope.dragoverList = ($event, item, index) -> - return true - - @_$scope.dropList = ($event, item, index) -> - taskID = item.id - listID = $($event.target).closest('li.list').attr('listID') - _$tasksbusinesslayer.changeCalendarId(taskID,listID) - return true - - @_$scope.dragoverCollection = ($event, item, index) -> - collectionID = $($event.target).closest('li.collection') - .attr('collectionID') - return collectionID in ['starred', 'completed', 'today'] - - @_$scope.dropCollection = ($event, item, index) -> - taskID = item.id - collectionID = $($event.target).closest('li.collection') - .attr('collectionID') - console.log(taskID, collectionID) - _$tasksbusinesslayer.changeCollection(taskID, collectionID) - return true - - - return new ListController($scope, $window, $routeParams, - ListsModel, TasksBusinessLayer, CollectionsModel, - ListsBusinessLayer, $location, SearchBusinessLayer, - CalendarService) -] diff --git a/js/app/controllers/listcontroller.js b/js/app/controllers/listcontroller.js new file mode 100644 index 00000000..fbf3470b --- /dev/null +++ b/js/app/controllers/listcontroller.js @@ -0,0 +1,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); diff --git a/js/app/controllers/settingscontroller.coffee b/js/app/controllers/settingscontroller.coffee deleted file mode 100644 index 43d34e88..00000000 --- a/js/app/controllers/settingscontroller.coffee +++ /dev/null @@ -1,87 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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 'SettingsController', -['$scope', '$window', 'Status', '$location', -'CollectionsModel', 'SettingsBusinessLayer', 'SettingsModel' -($scope, $window, Status, $location, CollectionsModel, - SettingsBusinessLayer, SettingsModel) -> - - class SettingsController - - constructor: (@_$scope, @_$window, @_$status, - @_$location, @_$collectionsmodel, - @_$settingsbusinesslayer, @_$settingsmodel) -> - - @_$scope.status = @_$status.getStatus() - - @_$scope.collections = @_$collectionsmodel.getAll() - - @_$scope.settingsmodel = @_$settingsmodel - - @_$scope.collectionOptions = [ - { - id: 0, - name: t('tasks','Hidden')}, - { - id: 1, - name: t('tasks','Visible')}, - { - id: 2, - name: t('tasks','Automatic')} - ] - - @_$scope.startOfWeekOptions = [ - { - id: 0, - name: t('tasks','Sunday')}, - { - id: 1, - name: t('tasks','Monday')}, - { - id: 2, - name: t('tasks','Tuesday')}, - { - id: 3, - name: t('tasks','Wednesday')}, - { - id: 4, - name: t('tasks','Thursday')}, - { - id: 5, - name: t('tasks','Friday')}, - { - id: 6, - name: t('tasks','Saturday')} - ] - - @_$scope.setVisibility = (collectionID) => - collection = _$collectionsmodel.getById(collectionID) - _$settingsbusinesslayer.setVisibility(collectionID,collection.show) - - @_$scope.setStartOfWeek = () => - _$settingsbusinesslayer.set('various','startOfWeek', - _$settingsmodel.getById('various').startOfWeek) - - - return new SettingsController($scope, $window, Status, $location, - CollectionsModel, SettingsBusinessLayer, SettingsModel) -] diff --git a/js/app/controllers/settingscontroller.js b/js/app/controllers/settingscontroller.js new file mode 100644 index 00000000..baa583f2 --- /dev/null +++ b/js/app/controllers/settingscontroller.js @@ -0,0 +1,92 @@ +/** + * 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('SettingsController', [ + '$scope', '$window', 'Status', '$location', 'CollectionsModel', 'SettingsBusinessLayer', 'SettingsModel', function($scope, $window, Status, $location, CollectionsModel, SettingsBusinessLayer, SettingsModel) { + var SettingsController; + SettingsController = (function() { + function SettingsController(_$scope, _$window, _$status, _$location, _$collectionsmodel, _$settingsbusinesslayer, _$settingsmodel) { + var _this = this; + this._$scope = _$scope; + this._$window = _$window; + this._$status = _$status; + this._$location = _$location; + this._$collectionsmodel = _$collectionsmodel; + this._$settingsbusinesslayer = _$settingsbusinesslayer; + this._$settingsmodel = _$settingsmodel; + this._$scope.status = this._$status.getStatus(); + this._$scope.collections = this._$collectionsmodel.getAll(); + this._$scope.settingsmodel = this._$settingsmodel; + this._$scope.collectionOptions = [ + { + id: 0, + name: t('tasks', 'Hidden') + }, { + id: 1, + name: t('tasks', 'Visible') + }, { + id: 2, + name: t('tasks', 'Automatic') + } + ]; + this._$scope.startOfWeekOptions = [ + { + id: 0, + name: t('tasks', 'Sunday') + }, { + id: 1, + name: t('tasks', 'Monday') + }, { + id: 2, + name: t('tasks', 'Tuesday') + }, { + id: 3, + name: t('tasks', 'Wednesday') + }, { + id: 4, + name: t('tasks', 'Thursday') + }, { + id: 5, + name: t('tasks', 'Friday') + }, { + id: 6, + name: t('tasks', 'Saturday') + } + ]; + this._$scope.setVisibility = function(collectionID) { + var collection; + collection = _$collectionsmodel.getById(collectionID); + return _$settingsbusinesslayer.setVisibility(collectionID, collection.show); + }; + this._$scope.setStartOfWeek = function() { + return _$settingsbusinesslayer.set('various', 'startOfWeek', _$settingsmodel.getById('various').startOfWeek); + }; + } + + return SettingsController; + + })(); + return new SettingsController($scope, $window, Status, $location, CollectionsModel, SettingsBusinessLayer, SettingsModel); + } + ]); + +}).call(this); diff --git a/js/app/controllers/taskscontroller.coffee b/js/app/controllers/taskscontroller.coffee deleted file mode 100644 index dd07d735..00000000 --- a/js/app/controllers/taskscontroller.coffee +++ /dev/null @@ -1,299 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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 'TasksController', -['$scope', '$window', '$routeParams', 'TasksModel', 'ListsModel', -'CollectionsModel', 'TasksBusinessLayer', '$location', -'SettingsBusinessLayer', 'SearchBusinessLayer' -($scope, $window, $routeParams, TasksModel, ListsModel, -CollectionsModel, TasksBusinessLayer, $location, -SettingsBusinessLayer, SearchBusinessLayer) -> - - class TasksController - - constructor: (@_$scope,@_$window,@_$routeParams, - @_$tasksmodel,@_$listsmodel,@_$collectionsmodel, - @_tasksbusinesslayer, @$location, @_settingsbusinesslayer, - @_searchbusinesslayer) -> - - @_$scope.tasks = @_$tasksmodel.getAll() - @_$scope.draggedTasks = [] - @_$scope.lists = @_$listsmodel.getAll() - - @_$scope.days = [0,1,2,3,4,5,6] - - @_$scope.isAddingTask = false - - @_$scope.focusInputField = false - - @_$scope.TasksModel = @_$tasksmodel - - @_$scope.TasksBusinessLayer = @_tasksbusinesslayer - - @_$scope.getAddString = () -> - if angular.isDefined(calendar = - _$listsmodel.getStandardList()) - if angular.isDefined(_$scope.route.collectionID) - switch _$scope.route.collectionID - when 'starred' - return t('tasks','Add an important item in "%s"...') - .replace('%s',calendar.displayname) - when 'today' - return t('tasks','Add an item due today in "%s"...') - .replace('%s',calendar.displayname) - when 'all' - return t('tasks','Add an item in "%s"...') - .replace('%s',calendar.displayname) - when 'current' - return t('tasks','Add a current item in "%s"...') - .replace('%s',calendar.displayname) - when 'completed', 'week' - return null - else - if angular.isDefined(_$listsmodel.getByUri(_$scope.route.calendarID)) - return t('tasks','Add an item in "%s"...') - .replace('%s', - _$listsmodel.getByUri(_$scope.route.calendarID).displayname) - - @_$scope.getSubAddString = (taskname) -> - return t('tasks','Add a subtask to "%s"...') - .replace('%s', taskname) - - @_$scope.showSubtaskInput = (uid) -> - _$scope.status.addSubtaskTo = uid - - @_$scope.hideSubtasks = (task) -> - descendants = _$tasksmodel.getDescendantID(task.id) - if task.id == _$scope.route.taskID - return false - else if _$scope.route.taskID in descendants - return false - else - return task.hidesubtasks - - @_$scope.showInput = () -> - if _$scope.route.listID in ['completed', 'week'] - return false - else - return true - - @_$scope.focusTaskInput = () -> - _$scope.status.focusTaskInput = true - - @_$scope.focusSubtaskInput = () -> - _$scope.status.focusSubtaskInput = true - - @_$scope.openDetails = (id,$event) -> - if $($event.currentTarget).is($($event.target).closest('.handler')) - listID = _$scope.route.listID - $location.path('/lists/'+listID+'/tasks/'+id) - - @_$scope.toggleCompleted = (taskID) -> - if _$tasksmodel.completed(taskID) - _tasksbusinesslayer.uncompleteTask(taskID) - else - _tasksbusinesslayer.completeTask(taskID) - - @_$scope.toggleStarred = (taskID) -> - if _$tasksmodel.starred(taskID) - _tasksbusinesslayer.unstarTask(taskID) - else - _$tasksmodel.star(taskID) - _tasksbusinesslayer.starTask(taskID) - - @_$scope.toggleHidden = () -> - _settingsbusinesslayer.toggle('various','showHidden') - - @_$scope.filterTasks = (task, filter) -> - return (task) -> - return _$tasksmodel.filterTasks(task, filter) - - @_$scope.getSubTasks = (tasks,parent) -> - ret = [] - for task in tasks - if task.related == parent.uid - ret.push(task) - return ret - - @_$scope.hasNoParent = (task) -> - return (task) -> - return _$tasksmodel.hasNoParent(task) - - @_$scope.hasSubtasks = (task) -> - return _$tasksmodel.hasSubtasks(task.uid) - - @_$scope.toggleSubtasks = (taskID) -> - if _$tasksmodel.hideSubtasks(taskID) - _tasksbusinesslayer.unhideSubtasks(taskID) - else - _tasksbusinesslayer.hideSubtasks(taskID) - - @_$scope.filterTasksByString = (task) => - return (task) -> - filter = _searchbusinesslayer.getFilter() - return _$tasksmodel.filterTasksByString(task, filter) - - @_$scope.filteredTasks = () -> - filter = _searchbusinesslayer.getFilter() - return _$tasksmodel.filteredTasks(filter) - - @_$scope.dayHasEntry = () -> - return (date) -> - filter = _searchbusinesslayer.getFilter() - tasks = _$tasksmodel.filteredTasks(filter) - for task in tasks - if task.completed || !_$tasksmodel.hasNoParent(task) - continue - if _$tasksmodel.taskAtDay(task, date) - return true - return false - - @_$scope.taskAtDay = (task, day) => - return (task) -> - _$tasksmodel.taskAtDay(task, day) - - @_$scope.filterLists = () -> - return (list) -> - return _$scope.getCount(list.id,_$scope.route.listID) - - @_$scope.getCount = (listID,type) -> - filter = _searchbusinesslayer.getFilter() - return _$listsmodel.getCount(listID,type,filter) - - @_$scope.getCountString = (listID,type) -> - filter = _searchbusinesslayer.getFilter() - return n('tasks', '%n Completed Task', '%n Completed Tasks', - _$listsmodel.getCount(listID,type,filter)) - - @_$scope.addTask = (taskName,related='',calendarid='') -> - - _$scope.isAddingTask = true - - task = { - tmpID: 'newTask' + Date.now() - id: 'newTask' + Date.now() - calendarid: null - related: related - name: taskName - starred: false - priority: '0' - due: false - start: false - reminder: null - completed: false - complete: '0' - note: false - } - - if (_$scope.route.listID in - ['starred', 'today', 'week', 'all', 'completed', 'current']) - if related - task.calendarid = calendarid - else - task.calendarid = _$listsmodel.getStandardList() - if _$scope.route.listID == 'starred' - task.starred = true - if _$scope.route.listID == 'today' - task.due = moment().startOf('day').format("YYYYMMDDTHHmmss") - if _$scope.route.listID == 'current' - task.start = moment().format("YYYYMMDDTHHmmss") - else - task.calendarid = _$scope.route.listID - - _tasksbusinesslayer.addTask task - , (data) => - _$tasksmodel.add(data) - _$scope.isAddingTask = false - , => - _$scope.isAddingTask = false - - _$scope.status.focusTaskInput = false - _$scope.status.focusSubtaskInput = false - _$scope.status.addSubtaskTo = '' - _$scope.status.taskName = '' - _$scope.status.subtaskName = '' - - @_$scope.checkTaskInput = ($event) -> - if($event.keyCode == 27) - $($event.currentTarget).blur() - _$scope.status.taskName = '' - _$scope.status.subtaskName = '' - _$scope.status.addSubtaskTo = '' - _$scope.status.focusTaskInput = false - _$scope.status.focusSubtaskInput = false - - @_$scope.getCompletedTasks = (listID) -> - _tasksbusinesslayer.getCompletedTasks(listID) - - @_$scope.loadedAll = (listID) -> - return _$listsmodel.loadedAll(listID) - - @_$scope.sortDue = (task) -> - if task.due == null - return 'last' - else - return task.due - - @_$scope.getTaskColor = (listID) -> - return _$listsmodel.getColor(listID) - - @_$scope.getTaskList = (listID) -> - return _$listsmodel.getName(listID) - - @_$scope.dropCallback = ($event, item, index) -> - taskID = item.id - $('.subtasks-container').removeClass('dropzone-visible') - parentID = $('li.dndPlaceholder').closest('.task-item').attr('taskID') - parentID = parentID || "" - # Sometimes the detection of the parentID by the dndPlaceholder goes wrong - # (unclear why, atm). This catches the problem for now. - if parentID == taskID - parentID = "" - collectionID = $('li.dndPlaceholder').closest('ol[dnd-list]') - .attr('collectionID') - if collectionID - _tasksbusinesslayer.changeCollection(taskID, collectionID) - listID = $('li.dndPlaceholder').closest('ol[dnd-list]') - .attr('listID') - if listID - _tasksbusinesslayer.changeCalendarId(taskID,listID) - _tasksbusinesslayer.changeParent(taskID, parentID, collectionID) - return true - - @_$scope.dragover = ($event, item, index) -> - # remove this in favour of @_$scope.dragleave() - $('.subtasks-container').removeClass('dropzone-visible') - # - $($event.target).closest('.task-item') - .children('.subtasks-container') - .addClass('dropzone-visible') - return true - - # This should be used when angular dnd supports dnd-dragleave callback - # @_$scope.dragleave = ($event, item, index) -> - # $($event.target).closest('.task-item') - # .children('.subtasks-container').removeClass('dropzone-visible') - # return true - - return new TasksController($scope, $window, $routeParams, - TasksModel, ListsModel, CollectionsModel, TasksBusinessLayer, $location, - SettingsBusinessLayer, SearchBusinessLayer) -] diff --git a/js/app/controllers/taskscontroller.js b/js/app/controllers/taskscontroller.js new file mode 100644 index 00000000..176fe24f --- /dev/null +++ b/js/app/controllers/taskscontroller.js @@ -0,0 +1,327 @@ +/** + * 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() { + var __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').controller('TasksController', [ + '$scope', '$window', '$routeParams', 'TasksModel', 'ListsModel', 'CollectionsModel', 'TasksBusinessLayer', '$location', 'SettingsBusinessLayer', 'SearchBusinessLayer', function($scope, $window, $routeParams, TasksModel, ListsModel, CollectionsModel, TasksBusinessLayer, $location, SettingsBusinessLayer, SearchBusinessLayer) { + var TasksController; + TasksController = (function() { + function TasksController(_$scope, _$window, _$routeParams, _$tasksmodel, _$listsmodel, _$collectionsmodel, _tasksbusinesslayer, $location, _settingsbusinesslayer, _searchbusinesslayer) { + var _this = this; + this._$scope = _$scope; + this._$window = _$window; + this._$routeParams = _$routeParams; + this._$tasksmodel = _$tasksmodel; + this._$listsmodel = _$listsmodel; + this._$collectionsmodel = _$collectionsmodel; + this._tasksbusinesslayer = _tasksbusinesslayer; + this.$location = $location; + this._settingsbusinesslayer = _settingsbusinesslayer; + this._searchbusinesslayer = _searchbusinesslayer; + this._$scope.tasks = this._$tasksmodel.getAll(); + this._$scope.draggedTasks = []; + this._$scope.lists = this._$listsmodel.getAll(); + this._$scope.days = [0, 1, 2, 3, 4, 5, 6]; + this._$scope.isAddingTask = false; + this._$scope.focusInputField = false; + this._$scope.TasksModel = this._$tasksmodel; + this._$scope.TasksBusinessLayer = this._tasksbusinesslayer; + this._$scope.getAddString = function() { + var calendar; + if (angular.isDefined(calendar = _$listsmodel.getStandardList())) { + if (angular.isDefined(_$scope.route.collectionID)) { + switch (_$scope.route.collectionID) { + case 'starred': + return t('tasks', 'Add an important item in "%s"...').replace('%s', calendar.displayname); + case 'today': + return t('tasks', 'Add an item due today in "%s"...').replace('%s', calendar.displayname); + case 'all': + return t('tasks', 'Add an item in "%s"...').replace('%s', calendar.displayname); + case 'current': + return t('tasks', 'Add a current item in "%s"...').replace('%s', calendar.displayname); + case 'completed': + case 'week': + return null; + } + } else { + if (angular.isDefined(_$listsmodel.getByUri(_$scope.route.calendarID))) { + return t('tasks', 'Add an item in "%s"...').replace('%s', _$listsmodel.getByUri(_$scope.route.calendarID).displayname); + } + } + } + }; + this._$scope.getSubAddString = function(taskname) { + return t('tasks', 'Add a subtask to "%s"...').replace('%s', taskname); + }; + this._$scope.showSubtaskInput = function(uid) { + return _$scope.status.addSubtaskTo = uid; + }; + this._$scope.hideSubtasks = function(task) { + var descendants, _ref; + descendants = _$tasksmodel.getDescendantID(task.id); + if (task.id === _$scope.route.taskID) { + return false; + } else if (_ref = _$scope.route.taskID, __indexOf.call(descendants, _ref) >= 0) { + return false; + } else { + return task.hidesubtasks; + } + }; + this._$scope.showInput = function() { + var _ref; + if ((_ref = _$scope.route.listID) === 'completed' || _ref === 'week') { + return false; + } else { + return true; + } + }; + this._$scope.focusTaskInput = function() { + return _$scope.status.focusTaskInput = true; + }; + this._$scope.focusSubtaskInput = function() { + return _$scope.status.focusSubtaskInput = true; + }; + this._$scope.openDetails = function(id, $event) { + var listID; + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + listID = _$scope.route.listID; + return $location.path('/lists/' + listID + '/tasks/' + id); + } + }; + this._$scope.toggleCompleted = function(taskID) { + if (_$tasksmodel.completed(taskID)) { + return _tasksbusinesslayer.uncompleteTask(taskID); + } else { + return _tasksbusinesslayer.completeTask(taskID); + } + }; + this._$scope.toggleStarred = function(taskID) { + if (_$tasksmodel.starred(taskID)) { + return _tasksbusinesslayer.unstarTask(taskID); + } else { + _$tasksmodel.star(taskID); + return _tasksbusinesslayer.starTask(taskID); + } + }; + this._$scope.toggleHidden = function() { + return _settingsbusinesslayer.toggle('various', 'showHidden'); + }; + this._$scope.filterTasks = function(task, filter) { + return function(task) { + return _$tasksmodel.filterTasks(task, filter); + }; + }; + this._$scope.getSubTasks = function(tasks, parent) { + var ret, task, _i, _len; + ret = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.related === parent.uid) { + ret.push(task); + } + } + return ret; + }; + this._$scope.hasNoParent = function(task) { + return function(task) { + return _$tasksmodel.hasNoParent(task); + }; + }; + this._$scope.hasSubtasks = function(task) { + return _$tasksmodel.hasSubtasks(task.uid); + }; + this._$scope.toggleSubtasks = function(taskID) { + if (_$tasksmodel.hideSubtasks(taskID)) { + return _tasksbusinesslayer.unhideSubtasks(taskID); + } else { + return _tasksbusinesslayer.hideSubtasks(taskID); + } + }; + this._$scope.filterTasksByString = function(task) { + return function(task) { + var filter; + filter = _searchbusinesslayer.getFilter(); + return _$tasksmodel.filterTasksByString(task, filter); + }; + }; + this._$scope.filteredTasks = function() { + var filter; + filter = _searchbusinesslayer.getFilter(); + return _$tasksmodel.filteredTasks(filter); + }; + this._$scope.dayHasEntry = function() { + return function(date) { + var filter, task, tasks, _i, _len; + filter = _searchbusinesslayer.getFilter(); + tasks = _$tasksmodel.filteredTasks(filter); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.completed || !_$tasksmodel.hasNoParent(task)) { + continue; + } + if (_$tasksmodel.taskAtDay(task, date)) { + return true; + } + } + return false; + }; + }; + this._$scope.taskAtDay = function(task, day) { + return function(task) { + return _$tasksmodel.taskAtDay(task, day); + }; + }; + this._$scope.filterLists = function() { + return function(list) { + return _$scope.getCount(list.id, _$scope.route.listID); + }; + }; + this._$scope.getCount = function(listID, type) { + var filter; + filter = _searchbusinesslayer.getFilter(); + return _$listsmodel.getCount(listID, type, filter); + }; + this._$scope.getCountString = function(listID, type) { + var filter; + filter = _searchbusinesslayer.getFilter(); + return n('tasks', '%n Completed Task', '%n Completed Tasks', _$listsmodel.getCount(listID, type, filter)); + }; + this._$scope.addTask = function(taskName, related, calendarid) { + var task, _ref, + _this = this; + if (related == null) { + related = ''; + } + if (calendarid == null) { + calendarid = ''; + } + _$scope.isAddingTask = true; + task = { + tmpID: 'newTask' + Date.now(), + id: 'newTask' + Date.now(), + calendarid: null, + related: related, + name: taskName, + starred: false, + priority: '0', + due: false, + start: false, + reminder: null, + completed: false, + complete: '0', + note: false + }; + if (((_ref = _$scope.route.listID) === 'starred' || _ref === 'today' || _ref === 'week' || _ref === 'all' || _ref === 'completed' || _ref === 'current')) { + if (related) { + task.calendarid = calendarid; + } else { + task.calendarid = _$listsmodel.getStandardList(); + } + if (_$scope.route.listID === 'starred') { + task.starred = true; + } + if (_$scope.route.listID === 'today') { + task.due = moment().startOf('day').format("YYYYMMDDTHHmmss"); + } + if (_$scope.route.listID === 'current') { + task.start = moment().format("YYYYMMDDTHHmmss"); + } + } else { + task.calendarid = _$scope.route.listID; + } + _tasksbusinesslayer.addTask(task, function(data) { + _$tasksmodel.add(data); + return _$scope.isAddingTask = false; + }, function() { + return _$scope.isAddingTask = false; + }); + _$scope.status.focusTaskInput = false; + _$scope.status.focusSubtaskInput = false; + _$scope.status.addSubtaskTo = ''; + _$scope.status.taskName = ''; + return _$scope.status.subtaskName = ''; + }; + this._$scope.checkTaskInput = function($event) { + if ($event.keyCode === 27) { + $($event.currentTarget).blur(); + _$scope.status.taskName = ''; + _$scope.status.subtaskName = ''; + _$scope.status.addSubtaskTo = ''; + _$scope.status.focusTaskInput = false; + return _$scope.status.focusSubtaskInput = false; + } + }; + this._$scope.getCompletedTasks = function(listID) { + return _tasksbusinesslayer.getCompletedTasks(listID); + }; + this._$scope.loadedAll = function(listID) { + return _$listsmodel.loadedAll(listID); + }; + this._$scope.sortDue = function(task) { + if (task.due === null) { + return 'last'; + } else { + return task.due; + } + }; + this._$scope.getTaskColor = function(listID) { + return _$listsmodel.getColor(listID); + }; + this._$scope.getTaskList = function(listID) { + return _$listsmodel.getName(listID); + }; + this._$scope.dropCallback = function($event, item, index) { + var collectionID, listID, parentID, taskID; + taskID = item.id; + $('.subtasks-container').removeClass('dropzone-visible'); + parentID = $('li.dndPlaceholder').closest('.task-item').attr('taskID'); + parentID = parentID || ""; + if (parentID === taskID) { + parentID = ""; + } + collectionID = $('li.dndPlaceholder').closest('ol[dnd-list]').attr('collectionID'); + if (collectionID) { + _tasksbusinesslayer.changeCollection(taskID, collectionID); + } + listID = $('li.dndPlaceholder').closest('ol[dnd-list]').attr('listID'); + if (listID) { + _tasksbusinesslayer.changeCalendarId(taskID, listID); + } + _tasksbusinesslayer.changeParent(taskID, parentID, collectionID); + return true; + }; + this._$scope.dragover = function($event, item, index) { + $('.subtasks-container').removeClass('dropzone-visible'); + $($event.target).closest('.task-item').children('.subtasks-container').addClass('dropzone-visible'); + return true; + }; + } + + return TasksController; + + })(); + return new TasksController($scope, $window, $routeParams, TasksModel, ListsModel, CollectionsModel, TasksBusinessLayer, $location, SettingsBusinessLayer, SearchBusinessLayer); + } + ]); + +}).call(this); diff --git a/js/app/directives/appnavigationentryutils.coffee b/js/app/directives/appnavigationentryutils.coffee deleted file mode 100644 index dadbfd5b..00000000 --- a/js/app/directives/appnavigationentryutils.coffee +++ /dev/null @@ -1,17 +0,0 @@ -angular.module('Tasks').directive 'appNavigationEntryUtils', -> - 'use strict' - { - restrict: 'C' - link: (scope, elm) -> - menu = elm.siblings('.app-navigation-entry-menu') - button = $(elm).find('.app-navigation-entry-utils-menu-button button') - button.click -> - menu.toggleClass 'open' - return - scope.$on 'documentClicked', (scope, event) -> - if event.target != button[0] - menu.removeClass 'open' - return - return - } - diff --git a/js/app/directives/appnavigationentryutils.js b/js/app/directives/appnavigationentryutils.js new file mode 100644 index 00000000..68a865c1 --- /dev/null +++ b/js/app/directives/appnavigationentryutils.js @@ -0,0 +1,40 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').directive('appNavigationEntryUtils', function() { + 'use strict'; + return { + restrict: 'C', + link: function(scope, elm) { + var button, menu; + menu = elm.siblings('.app-navigation-entry-menu'); + button = $(elm).find('.app-navigation-entry-utils-menu-button button'); + button.click(function() { + menu.toggleClass('open'); + }); + scope.$on('documentClicked', function(scope, event) { + if (event.target !== button[0]) { + menu.removeClass('open'); + } + }); + } + }; +}); diff --git a/js/app/directives/autofocusoninsert.coffee b/js/app/directives/autofocusoninsert.coffee deleted file mode 100644 index cca55e8e..00000000 --- a/js/app/directives/autofocusoninsert.coffee +++ /dev/null @@ -1,4 +0,0 @@ -angular.module('Tasks').directive 'autofocusOnInsert', -> - 'use strict' - return (scope, elm) -> - elm.focus() diff --git a/js/app/directives/autofocusoninsert.js b/js/app/directives/autofocusoninsert.js new file mode 100644 index 00000000..92db2f7c --- /dev/null +++ b/js/app/directives/autofocusoninsert.js @@ -0,0 +1,27 @@ +/** + * 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/>. + * + */ + + angular.module('Tasks').directive('autofocusOnInsert', function() { + 'use strict'; + return function(scope, elm) { + return elm.focus(); + }; +}); diff --git a/js/app/directives/avatar.js b/js/app/directives/avatar.js new file mode 100644 index 00000000..9f71d3e0 --- /dev/null +++ b/js/app/directives/avatar.js @@ -0,0 +1,34 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').directive('avatar', function() { + return { + restrict: 'A', + scope: false, + link: function(scope, elm, attr) { + return attr.$observe('userid', function() { + if (attr.userid) { + return elm.avatar(attr.userid, attr.size); + } + }); + } + }; +}); diff --git a/js/app/directives/datepicker.coffee b/js/app/directives/datepicker.coffee deleted file mode 100644 index 08c18555..00000000 --- a/js/app/directives/datepicker.coffee +++ /dev/null @@ -1,45 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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 'datepicker', -> - restrict: 'A' - scope: false - link: (scope, elm, attr) -> - elm.datepicker({ - onSelect: (date, inst) -> - scope['set'+attr.datepicker+'day'](date) - scope.$apply() - beforeShow: (input, inst) -> - dp = $(inst).datepicker('widget') - marginLeft = -Math.abs($(input).outerWidth()-dp.outerWidth())/2+'px' - dp.css({'margin-left':marginLeft}) - $("div.ui-datepicker:before").css({'left':100+'px'}) - $('.hasDatepicker').datepicker("option", "firstDay", - scope.settingsmodel.getById('various').startOfWeek) - beforeShowDay: (date) -> - if (moment(date).startOf('day') - .diff(moment(scope.task[attr.datepicker], "YYYYMMDDTHHmmss") - .startOf('day'),'days') == 0) - return [1,"selected"] - else - return [1,""] - minDate: null - })
\ No newline at end of file diff --git a/js/app/directives/datepicker.js b/js/app/directives/datepicker.js new file mode 100644 index 00000000..67f0f2fe --- /dev/null +++ b/js/app/directives/datepicker.js @@ -0,0 +1,58 @@ +/** + * 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').directive('datepicker', function() { + return { + restrict: 'A', + scope: false, + link: function(scope, elm, attr) { + return elm.datepicker({ + onSelect: function(date, inst) { + scope['set' + attr.datepicker + 'day'](date); + return scope.$apply(); + }, + beforeShow: function(input, inst) { + var dp, marginLeft; + dp = $(inst).datepicker('widget'); + marginLeft = -Math.abs($(input).outerWidth() - dp.outerWidth()) / 2 + 'px'; + dp.css({ + 'margin-left': marginLeft + }); + $("div.ui-datepicker:before").css({ + 'left': 100 + 'px' + }); + return $('.hasDatepicker').datepicker("option", "firstDay", scope.settingsmodel.getById('various').startOfWeek); + }, + beforeShowDay: function(date) { + if (moment(date).startOf('day').diff(moment(scope.task[attr.datepicker], "YYYYMMDDTHHmmss").startOf('day'), 'days') === 0) { + return [1, "selected"]; + } else { + return [1, ""]; + } + }, + minDate: null + }); + } + }; + }); + +}).call(this); diff --git a/js/app/directives/occlickfocus.coffee b/js/app/directives/occlickfocus.coffee deleted file mode 100644 index d1eaf555..00000000 --- a/js/app/directives/occlickfocus.coffee +++ /dev/null @@ -1,36 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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 'ocClickFocus', ['$timeout', ($timeout) -> - (scope, elm, attr) -> - options = scope.$eval(attr.ocClickFocus) - if (angular.isDefined(options) && angular.isDefined(options.selector)) - elm.click( - ()-> - if angular.isDefined(options.timeout) - $timeout(() -> - $(options.selector).focus() - , options.timeout - ) - else - $(options.selector).focus() - ) -] diff --git a/js/app/directives/occlickfocus.js b/js/app/directives/occlickfocus.js new file mode 100644 index 00000000..cebab8f1 --- /dev/null +++ b/js/app/directives/occlickfocus.js @@ -0,0 +1,43 @@ +/** + * 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').directive('ocClickFocus', [ + '$timeout', function($timeout) { + return function(scope, elm, attr) { + var options; + options = scope.$eval(attr.ocClickFocus); + if (angular.isDefined(options) && angular.isDefined(options.selector)) { + return elm.click(function() { + if (angular.isDefined(options.timeout)) { + return $timeout(function() { + return $(options.selector).focus(); + }, options.timeout); + } else { + return $(options.selector).focus(); + } + }); + } + }; + } + ]); + +}).call(this); diff --git a/js/app/directives/timepicker.coffee b/js/app/directives/timepicker.coffee deleted file mode 100644 index 0232b0f3..00000000 --- a/js/app/directives/timepicker.coffee +++ /dev/null @@ -1,33 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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 'timepicker', -> - restrict: 'A' - link: (scope, elm, attr) -> - elm.timepicker({ - onSelect: (date, inst) -> - scope['set'+attr.timepicker+'time'](date) - scope.$apply() - myPosition: 'center top' - atPosition: 'center bottom' - hourText: t('tasks','Hours') - minuteText: t('tasks','Minutes') - })
\ No newline at end of file diff --git a/js/app/directives/timepicker.js b/js/app/directives/timepicker.js new file mode 100644 index 00000000..2827c999 --- /dev/null +++ b/js/app/directives/timepicker.js @@ -0,0 +1,41 @@ +/** + * 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').directive('timepicker', function() { + return { + restrict: 'A', + link: function(scope, elm, attr) { + return elm.timepicker({ + onSelect: function(date, inst) { + scope['set' + attr.timepicker + 'time'](date); + return scope.$apply(); + }, + myPosition: 'center top', + atPosition: 'center bottom', + hourText: t('tasks', 'Hours'), + minuteText: t('tasks', 'Minutes') + }); + } + }; + }); + +}).call(this); diff --git a/js/app/directives/watchtop.coffee b/js/app/directives/watchtop.coffee deleted file mode 100644 index 09d501bb..00000000 --- a/js/app/directives/watchtop.coffee +++ /dev/null @@ -1,30 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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 'watchTop', -> - restrict: 'A' - link: (scope, element, attr) -> - scope: { - "divTop": "=" - } - scope.$watch( () -> - scope.divTop = element.prev().outerHeight(true) - )
\ No newline at end of file diff --git a/js/app/directives/avatar.coffee b/js/app/directives/watchtop.js index e98760b9..d7c9608c 100644 --- a/js/app/directives/avatar.coffee +++ b/js/app/directives/watchtop.js @@ -1,9 +1,9 @@ -### +/* ownCloud - Tasks @author Raimund Schlüßler -@copyright 2013 +@copyright 2016 This library is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -17,13 +17,20 @@ 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 'avatar', -> - restrict: 'A' - scope: false - link: (scope, elm, attr) -> - attr.$observe('userid', () -> - if(attr.userid) - elm.avatar(attr.userid,attr.size) - )
\ No newline at end of file +angular.module('Tasks').directive('watchTop', function() { + return { + restrict: 'A', + link: function(scope, element, attr) { + ({ + scope: { + "divTop": "=" + } + }); + return scope.$watch(function() { + return scope.divTop = element.prev().outerHeight(true); + }); + } + }; +}); diff --git a/js/app/filters/counterFormatter.coffee b/js/app/filters/counterFormatter.coffee deleted file mode 100644 index 7d04126a..00000000 --- a/js/app/filters/counterFormatter.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').filter 'counterFormatter', () -> - (count) -> - return switch - when count == 0 then '' - when count > 999 then '999+' - else count diff --git a/js/app/filters/counterFormatter.js b/js/app/filters/counterFormatter.js new file mode 100644 index 00000000..fa15c58b --- /dev/null +++ b/js/app/filters/counterFormatter.js @@ -0,0 +1,33 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('counterFormatter', function() { + return function(count) { + switch (false) { + case count !== 0: + return ''; + case !(count > 999): + return '999+'; + default: + return count; + } + }; +}); diff --git a/js/app/filters/dateDetails.coffee b/js/app/filters/dateDetails.coffee deleted file mode 100644 index b629162a..00000000 --- a/js/app/filters/dateDetails.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'dateDetails', () -> - (due) -> - if moment(due, "YYYYMMDDTHHmmss").isValid() - return moment(due, "YYYYMMDDTHHmmss").locale('details').calendar() - else - return t('tasks', 'Set due date') diff --git a/js/app/filters/dateDetails.js b/js/app/filters/dateDetails.js new file mode 100644 index 00000000..2b441b43 --- /dev/null +++ b/js/app/filters/dateDetails.js @@ -0,0 +1,30 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('dateDetails', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").locale('details').calendar(); + } else { + return t('tasks', 'Set due date'); + } + }; +}); diff --git a/js/app/filters/dateDetailsShort.coffee b/js/app/filters/dateDetailsShort.coffee deleted file mode 100644 index c65a54a0..00000000 --- a/js/app/filters/dateDetailsShort.coffee +++ /dev/null @@ -1,28 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'dateDetailsShort', () -> - (reminder) -> - if moment(reminder, "YYYYMMDDTHHmmss").isValid() - return moment(reminder, "YYYYMMDDTHHmmss") - .locale('details_short').calendar() - else - return '' diff --git a/js/app/filters/dateDetailsShort.js b/js/app/filters/dateDetailsShort.js new file mode 100644 index 00000000..f6a6dc5b --- /dev/null +++ b/js/app/filters/dateDetailsShort.js @@ -0,0 +1,30 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('dateDetailsShort', function() { + return function(reminder) { + if (moment(reminder, "YYYYMMDDTHHmmss").isValid()) { + return moment(reminder, "YYYYMMDDTHHmmss").locale('details_short').calendar(); + } else { + return ''; + } + }; +}); diff --git a/js/app/filters/dateFromNow.coffee b/js/app/filters/dateFromNow.coffee deleted file mode 100644 index afaace6e..00000000 --- a/js/app/filters/dateFromNow.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'dateFromNow', () -> - (due) -> - if moment(due, "YYYYMMDDTHHmmss").isValid() - return moment(due, "YYYYMMDDTHHmmss").fromNow() - else - return ''
\ No newline at end of file diff --git a/js/app/filters/dateFromNow.js b/js/app/filters/dateFromNow.js new file mode 100644 index 00000000..1057f120 --- /dev/null +++ b/js/app/filters/dateFromNow.js @@ -0,0 +1,30 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('dateFromNow', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").fromNow(); + } else { + return ''; + } + }; +}); diff --git a/js/app/filters/dateTaskList.coffee b/js/app/filters/dateTaskList.coffee deleted file mode 100644 index c05f4eee..00000000 --- a/js/app/filters/dateTaskList.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'dateTaskList', () -> - (due) -> - if moment(due, "YYYYMMDDTHHmmss").isValid() - return moment(due, "YYYYMMDDTHHmmss").locale('tasks').calendar() - else - return '' diff --git a/js/app/filters/dateTaskList.js b/js/app/filters/dateTaskList.js new file mode 100644 index 00000000..011a1d67 --- /dev/null +++ b/js/app/filters/dateTaskList.js @@ -0,0 +1,30 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('dateTaskList', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").locale('tasks').calendar(); + } else { + return ''; + } + }; +}); diff --git a/js/app/filters/day.coffee b/js/app/filters/day.coffee deleted file mode 100644 index d114c552..00000000 --- a/js/app/filters/day.coffee +++ /dev/null @@ -1,24 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'day', () -> - (i) -> - return moment().add('days', i).locale('list_week').calendar() diff --git a/js/app/filters/day.js b/js/app/filters/day.js new file mode 100644 index 00000000..864fee31 --- /dev/null +++ b/js/app/filters/day.js @@ -0,0 +1,26 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('day', function() { + return function(i) { + return moment().add('days', i).locale('list_week').calendar(); + }; +}); diff --git a/js/app/filters/dayTaskList.coffee b/js/app/filters/dayTaskList.coffee deleted file mode 100644 index c7fa0ffc..00000000 --- a/js/app/filters/dayTaskList.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'dayTaskList', () -> - (due) -> - if moment(due, "YYYYMMDDTHHmmss").isValid() - return moment(due, "YYYYMMDDTHHmmss").locale('tasks').calendar() - else - return '' diff --git a/js/app/filters/dayTaskList.js b/js/app/filters/dayTaskList.js new file mode 100644 index 00000000..1586d6e0 --- /dev/null +++ b/js/app/filters/dayTaskList.js @@ -0,0 +1,30 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('dayTaskList', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").locale('tasks').calendar(); + } else { + return ''; + } + }; +}); diff --git a/js/app/filters/percentDetails.coffee b/js/app/filters/percentDetails.coffee deleted file mode 100644 index 0d082579..00000000 --- a/js/app/filters/percentDetails.coffee +++ /dev/null @@ -1,24 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'percentDetails', () -> - (percent) -> - t('tasks', '%s %% completed').replace('%s', percent).replace('%%', '%') diff --git a/js/app/filters/percentDetails.js b/js/app/filters/percentDetails.js new file mode 100644 index 00000000..d24c40cb --- /dev/null +++ b/js/app/filters/percentDetails.js @@ -0,0 +1,26 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('percentDetails', function() { + return function(percent) { + return t('tasks', '%s %% completed').replace('%s', percent).replace('%%', '%'); + }; +}); diff --git a/js/app/filters/priorityDetails.coffee b/js/app/filters/priorityDetails.coffee deleted file mode 100644 index 0844cf54..00000000 --- a/js/app/filters/priorityDetails.coffee +++ /dev/null @@ -1,32 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'priorityDetails', () -> - (priority) -> - string = t('tasks', 'priority %s: ').replace('%s', priority) - if +priority in [6,7,8,9] - return string+' '+t('tasks', 'high') - else if +priority == 5 - return string+' '+t('tasks', 'medium') - else if +priority in [1,2,3,4] - return string+' '+t('tasks', 'low') - else - return t('tasks', 'no priority assigned')
\ No newline at end of file diff --git a/js/app/filters/priorityDetails.js b/js/app/filters/priorityDetails.js new file mode 100644 index 00000000..2e7b0d9c --- /dev/null +++ b/js/app/filters/priorityDetails.js @@ -0,0 +1,37 @@ +/** + * 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/>. + * + */ + + +angular.module('Tasks').filter('priorityDetails', function() { + return function(priority) { + var string; + string = t('tasks', 'priority %s: ').replace('%s', priority); + if (+priority === 6 || +priority === 7 || +priority === 8 || +priority === 9) { + return string + ' ' + t('tasks', 'high'); + } else if (+priority === 5) { + return string + ' ' + t('tasks', 'medium'); + } else if (+priority === 1 || +priority === 2 || +priority === 3 || +priority === 4) { + return string + ' ' + t('tasks', 'low'); + } else { + return t('tasks', 'no priority assigned'); + } + }; +}); diff --git a/js/app/filters/reminderDetails.coffee b/js/app/filters/reminderDetails.coffee deleted file mode 100644 index 0ea9bac7..00000000 --- a/js/app/filters/reminderDetails.coffee +++ /dev/null @@ -1,59 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'reminderDetails', () -> - (reminder,scope) -> - if !(angular.isUndefined(reminder) || reminder == null) - if reminder.type == 'DATE-TIME' && - moment(reminder.date, "YYYYMMDDTHHmmss").isValid() - return moment(reminder.date, "YYYYMMDDTHHmmss") - .locale('reminder').calendar() - else if reminder.type == 'DURATION' && reminder.duration - ds = t('tasks', 'Remind me') - for token in scope.durations - if +reminder.duration[token.id] - time = 1 - ds+=' '+reminder.duration[token.id]+' ' - if +reminder.duration[token.id] == 1 - ds+=token.name - else - ds+=token.names - if !time - if reminder.duration.params.related == 'END' - ds+= ' '+t('tasks','at the end') - else - ds+= ' '+t('tasks','at the beginning') - else - if reminder.duration.params.invert - if reminder.duration.params.related == 'END' - ds+= ' '+t('tasks','before end') - else - ds+= ' '+t('tasks','before beginning') - else - if reminder.duration.params.related == 'END' - ds+= ' '+t('tasks','after end') - else - ds+= ' '+t('tasks','after beginning') - return ds - else - return t('tasks', 'Remind me') - else - return t('tasks', 'Remind me') diff --git a/js/app/filters/reminderDetails.js b/js/app/filters/reminderDetails.js new file mode 100644 index 00000000..400afb6c --- /dev/null +++ b/js/app/filters/reminderDetails.js @@ -0,0 +1,75 @@ +/** + * 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').filter('reminderDetails', function() { + return function(reminder, scope) { + var ds, time, token, _i, _len, _ref; + if (!(angular.isUndefined(reminder) || reminder === null)) { + if (reminder.type === 'DATE-TIME' && moment(reminder.date, "YYYYMMDDTHHmmss").isValid()) { + return moment(reminder.date, "YYYYMMDDTHHmmss").locale('reminder').calendar(); + } else if (reminder.type === 'DURATION' && reminder.duration) { + ds = t('tasks', 'Remind me'); + _ref = scope.durations; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + token = _ref[_i]; + if (+reminder.duration[token.id]) { + time = 1; + ds += ' ' + reminder.duration[token.id] + ' '; + if (+reminder.duration[token.id] === 1) { + ds += token.name; + } else { + ds += token.names; + } + } + } + if (!time) { + if (reminder.duration.params.related === 'END') { + ds += ' ' + t('tasks', 'at the end'); + } else { + ds += ' ' + t('tasks', 'at the beginning'); + } + } else { + if (reminder.duration.params.invert) { + if (reminder.duration.params.related === 'END') { + ds += ' ' + t('tasks', 'before end'); + } else { + ds += ' ' + t('tasks', 'before beginning'); + } + } else { + if (reminder.duration.params.related === 'END') { + ds += ' ' + t('tasks', 'after end'); + } else { + ds += ' ' + t('tasks', 'after beginning'); + } + } + } + return ds; + } else { + return t('tasks', 'Remind me'); + } + } else { + return t('tasks', 'Remind me'); + } + }; + }); + +}).call(this); diff --git a/js/app/filters/startDetails.coffee b/js/app/filters/startDetails.coffee deleted file mode 100644 index 9c95e3d5..00000000 --- a/js/app/filters/startDetails.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'startDetails', () -> - (due) -> - if moment(due, "YYYYMMDDTHHmmss").isValid() - return moment(due, "YYYYMMDDTHHmmss").locale('start').calendar() - else - return t('tasks', 'Set start date') diff --git a/js/app/filters/startDetails.js b/js/app/filters/startDetails.js new file mode 100644 index 00000000..3764652a --- /dev/null +++ b/js/app/filters/startDetails.js @@ -0,0 +1,30 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('startDetails', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").locale('start').calendar(); + } else { + return t('tasks', 'Set start date'); + } + }; +}); diff --git a/js/app/filters/timeTaskList.coffee b/js/app/filters/timeTaskList.coffee deleted file mode 100644 index 522a51cb..00000000 --- a/js/app/filters/timeTaskList.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').filter 'timeTaskList', () -> - (due) -> - if moment(due, "YYYYMMDDTHHmmss").isValid() - return moment(due, "YYYYMMDDTHHmmss").format('HH:mm') - else - return ''
\ No newline at end of file diff --git a/js/app/filters/timeTaskList.js b/js/app/filters/timeTaskList.js new file mode 100644 index 00000000..22e505a1 --- /dev/null +++ b/js/app/filters/timeTaskList.js @@ -0,0 +1,30 @@ +/** + * 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/>. + * + */ + +angular.module('Tasks').filter('timeTaskList', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").format('HH:mm'); + } else { + return ''; + } + }; +}); diff --git a/js/app/services/businesslayer/listsbusinesslayer.coffee b/js/app/services/businesslayer/listsbusinesslayer.coffee deleted file mode 100644 index b9fc5f96..00000000 --- a/js/app/services/businesslayer/listsbusinesslayer.coffee +++ /dev/null @@ -1,64 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').factory 'ListsBusinessLayer', -['ListsModel', 'Persistence', 'TasksBusinessLayer', 'CalendarService', -(ListsModel, Persistence, TasksBusinessLayer, CalendarService) -> - - class ListsBusinessLayer - - constructor: (@_$listsmodel, @_persistence, - @_$tasksbusinesslayer, @_$calendarservice) -> - - init: () -> - @_$calendarservice.getAll().then((calendars) -> - for calendar in calendars - ListsModel.add(calendar) - ) - - add: (calendar, onSuccess=null, onFailure=null) -> - @_$calendarservice.create(calendar, '#FF7A66', ['vtodo']) - .then((calendar) -> - ListsModel.add(calendar) - return calendar - ) - - delete: (calendar) -> - @_$calendarservice.delete(calendar) - .then(()-> - ListsModel.delete(calendar) - ) - - rename: (calendar) -> - @_persistence.setListName(@_$listsmodel.getById(listID)) - - # updateModel: () -> - # @_$listsmodel.voidAll() - # success = () => - # @_$listsmodel.removeVoid() - # @_persistence.getLists(success, true) - - return new ListsBusinessLayer(ListsModel, Persistence, - TasksBusinessLayer, CalendarService) - -] diff --git a/js/app/services/businesslayer/listsbusinesslayer.js b/js/app/services/businesslayer/listsbusinesslayer.js new file mode 100644 index 00000000..d18d1af9 --- /dev/null +++ b/js/app/services/businesslayer/listsbusinesslayer.js @@ -0,0 +1,76 @@ +/** + * 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').factory('ListsBusinessLayer', [ + 'ListsModel', 'Persistence', 'TasksBusinessLayer', 'CalendarService', function(ListsModel, Persistence, TasksBusinessLayer, CalendarService) { + var ListsBusinessLayer; + ListsBusinessLayer = (function() { + function ListsBusinessLayer(_$listsmodel, _persistence, _$tasksbusinesslayer, _$calendarservice) { + this._$listsmodel = _$listsmodel; + this._persistence = _persistence; + this._$tasksbusinesslayer = _$tasksbusinesslayer; + this._$calendarservice = _$calendarservice; + } + + ListsBusinessLayer.prototype.init = function() { + return this._$calendarservice.getAll().then(function(calendars) { + var calendar, _i, _len, _results; + _results = []; + for (_i = 0, _len = calendars.length; _i < _len; _i++) { + calendar = calendars[_i]; + _results.push(ListsModel.add(calendar)); + } + return _results; + }); + }; + + ListsBusinessLayer.prototype.add = function(calendar, onSuccess, onFailure) { + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + return this._$calendarservice.create(calendar, '#FF7A66', ['vtodo']).then(function(calendar) { + ListsModel.add(calendar); + return calendar; + }); + }; + + ListsBusinessLayer.prototype["delete"] = function(calendar) { + return this._$calendarservice["delete"](calendar).then(function() { + return ListsModel["delete"](calendar); + }); + }; + + ListsBusinessLayer.prototype.rename = function(calendar) { + return this._persistence.setListName(this._$listsmodel.getById(listID)); + }; + + return ListsBusinessLayer; + + })(); + return new ListsBusinessLayer(ListsModel, Persistence, TasksBusinessLayer, CalendarService); + } + ]); + +}).call(this); diff --git a/js/app/services/businesslayer/searchbusinesslayer.coffee b/js/app/services/businesslayer/searchbusinesslayer.coffee deleted file mode 100644 index c9a1012f..00000000 --- a/js/app/services/businesslayer/searchbusinesslayer.coffee +++ /dev/null @@ -1,87 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').factory 'SearchBusinessLayer', -['ListsModel', 'Persistence', 'TasksModel', '$rootScope', -'$routeParams', '$location', -(ListsModel, Persistence, TasksModel, $rootScope, -$routeParams, $location) -> - - class SearchBusinessLayer - - constructor: (@_$listsmodel, @_persistence, - @_$tasksmodel, @_$rootScope, @_$routeparams, @_$location) -> - @initialize() - @_$searchString = '' - - attach: (search) => - search.setFilter('tasks', (query) => - @_$rootScope.$apply( () => - @setFilter(query) - ) - ) - search.setRenderer('task', @renderTaskResult.bind(@)) - search.setHandler('task', @handleTaskClick.bind(@)) - - setFilter: (query) => - @_$searchString = query - - getFilter: () => - return @_$searchString - - initialize: () -> - @handleTaskClick = ($row, result, event) => - @_$location.path('/lists/'+ result.calendarid + - '/tasks/' + result.id) - - @renderTaskResult = ($row, result) => - if !@_$tasksmodel.filterTasks(result,@_$routeparams.listID) || - !@_$tasksmodel.isLoaded(result) - $template = $('div.task-item.template') - $template = $template.clone() - $row = $('<tr class="result"></tr>') - .append($template.removeClass('template')) - $row.data('result', result) - $row.find('span.title').text(result.name) - if result.starred - $row.find('span.task-star').addClass('task-starred') - if result.completed - $row.find('div.task-item').addClass('done') - $row.find('span.task-checkbox').addClass('task-checked') - if result.complete - $row.find('div.percentdone').css({'width':result.complete+'%', - 'background-color':''+@_$listsmodel.getColor(result.calendarid)}) - if result.note - $row.find('div.title-wrapper').addClass('attachment') - - return $row - else - return null - - OC.Plugins.register('OCA.Search', @) - - - return new SearchBusinessLayer(ListsModel, Persistence, - TasksModel, $rootScope, $routeParams, $location) - -] diff --git a/js/app/services/businesslayer/searchbusinesslayer.js b/js/app/services/businesslayer/searchbusinesslayer.js new file mode 100644 index 00000000..aa72d180 --- /dev/null +++ b/js/app/services/businesslayer/searchbusinesslayer.js @@ -0,0 +1,106 @@ +/** + * 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() { + 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.attach = __bind(this.attach, this); + this.initialize(); + this._$searchString = ''; + } + + SearchBusinessLayer.prototype.attach = function(search) { + var _this = this; + search.setFilter('tasks', function(query) { + return _this._$rootScope.$apply(function() { + return _this.setFilter(query); + }); + }); + search.setRenderer('task', this.renderTaskResult.bind(this)); + return search.setHandler('task', this.handleTaskClick.bind(this)); + }; + + SearchBusinessLayer.prototype.setFilter = function(query) { + return this._$searchString = query; + }; + + SearchBusinessLayer.prototype.getFilter = function() { + return this._$searchString; + }; + + SearchBusinessLayer.prototype.initialize = function() { + var _this = this; + this.handleTaskClick = function($row, result, event) { + return _this._$location.path('/lists/' + result.calendarid + '/tasks/' + result.id); + }; + this.renderTaskResult = function($row, result) { + var $template; + if (!_this._$tasksmodel.filterTasks(result, _this._$routeparams.listID) || !_this._$tasksmodel.isLoaded(result)) { + $template = $('div.task-item.template'); + $template = $template.clone(); + $row = $('<tr class="result"></tr>').append($template.removeClass('template')); + $row.data('result', result); + $row.find('span.title').text(result.name); + if (result.starred) { + $row.find('span.task-star').addClass('task-starred'); + } + if (result.completed) { + $row.find('div.task-item').addClass('done'); + $row.find('span.task-checkbox').addClass('task-checked'); + } + if (result.complete) { + $row.find('div.percentdone').css({ + 'width': result.complete + '%', + 'background-color': '' + _this._$listsmodel.getColor(result.calendarid) + }); + } + if (result.note) { + $row.find('div.title-wrapper').addClass('attachment'); + } + return $row; + } else { + return null; + } + }; + return OC.Plugins.register('OCA.Search', this); + }; + + return SearchBusinessLayer; + + })(); + return new SearchBusinessLayer(ListsModel, Persistence, TasksModel, $rootScope, $routeParams, $location); + } + ]); + +}).call(this); diff --git a/js/app/services/businesslayer/settingsbusinesslayer.coffee b/js/app/services/businesslayer/settingsbusinesslayer.coffee deleted file mode 100644 index 13b39b2a..00000000 --- a/js/app/services/businesslayer/settingsbusinesslayer.coffee +++ /dev/null @@ -1,50 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').factory 'SettingsBusinessLayer', -['Persistence', 'SettingsModel', -(Persistence, SettingsModel) -> - - class SettingsBusinessLayer - - constructor: (@_persistence, @_$settingsmodel) -> - - updateModel: () -> - success = () => - - @_persistence.getCollections(success, true) - - setVisibility: (collectionID, visibility) -> - @_persistence.setVisibility(collectionID, visibility) - - toggle: (type, setting) -> - @_$settingsmodel.toggle(type, setting) - value = @_$settingsmodel.getById(type)[setting] - @_persistence.setting(type, setting, value) - - set: (type, setting, value) -> - @_persistence.setting(type, setting, value) - - return new SettingsBusinessLayer(Persistence, SettingsModel) - -]
\ No newline at end of file diff --git a/js/app/services/businesslayer/settingsbusinesslayer.js b/js/app/services/businesslayer/settingsbusinesslayer.js new file mode 100644 index 00000000..3632f4f1 --- /dev/null +++ b/js/app/services/businesslayer/settingsbusinesslayer.js @@ -0,0 +1,61 @@ +/** + * 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').factory('SettingsBusinessLayer', [ + 'Persistence', 'SettingsModel', function(Persistence, SettingsModel) { + var SettingsBusinessLayer; + SettingsBusinessLayer = (function() { + function SettingsBusinessLayer(_persistence, _$settingsmodel) { + this._persistence = _persistence; + this._$settingsmodel = _$settingsmodel; + } + + SettingsBusinessLayer.prototype.updateModel = function() { + var success, + _this = this; + success = function() {}; + return this._persistence.getCollections(success, true); + }; + + SettingsBusinessLayer.prototype.setVisibility = function(collectionID, visibility) { + return this._persistence.setVisibility(collectionID, visibility); + }; + + SettingsBusinessLayer.prototype.toggle = function(type, setting) { + var value; + this._$settingsmodel.toggle(type, setting); + value = this._$settingsmodel.getById(type)[setting]; + return this._persistence.setting(type, setting, value); + }; + + SettingsBusinessLayer.prototype.set = function(type, setting, value) { + return this._persistence.setting(type, setting, value); + }; + + return SettingsBusinessLayer; + + })(); + return new SettingsBusinessLayer(Persistence, SettingsModel); + } + ]); + +}).call(this); diff --git a/js/app/services/businesslayer/tasksbusinesslayer.coffee b/js/app/services/businesslayer/tasksbusinesslayer.coffee deleted file mode 100644 index 4bf6c2f0..00000000 --- a/js/app/services/businesslayer/tasksbusinesslayer.coffee +++ /dev/null @@ -1,438 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').factory 'TasksBusinessLayer', -['TasksModel', 'Persistence', -(TasksModel, Persistence) -> - - class TasksBusinessLayer - - constructor: (@_$tasksmodel, @_persistence) -> - - addTask: (task, onSuccess=null, onFailure=null) -> - onSuccess or= -> - onFailure or= -> - - @_$tasksmodel.add(task) - - @uncompleteParents(task.related) - parentID = @_$tasksmodel.getIdByUid(task.related) - if parentID - @unhideSubtasks(parentID) - - success = (response) => - if response.status == 'error' - onFailure() - else - onSuccess(response.data) - @_persistence.addTask(task, success) - - getAll: (calendar) -> - # console.log(calendar) - - getTask: (taskID, onSuccess=null, onFailure=null) -> - onSuccess or= -> - - @_persistence.getTask(taskID, onSuccess, true) - - setPriority: (taskID, priority) -> - @_$tasksmodel.setPriority(taskID, priority) - if +priority in [6,7,8,9] - @_$tasksmodel.star(taskID) - else - @_$tasksmodel.unstar(taskID) - @_persistence.setPriority(taskID, priority) - - starTask: (taskID) -> - @setPriority(taskID, '9') - - unstarTask: (taskID) -> - @setPriority(taskID, '0') - - setPercentComplete: (taskID, percentComplete) -> - @_$tasksmodel.setPercentComplete(taskID, percentComplete) - if percentComplete < 100 - @_$tasksmodel.uncomplete(taskID) - task = @_$tasksmodel.getById(taskID) - @uncompleteParents(task.related) - else - @_$tasksmodel.complete(taskID) - @completeChildren(taskID) - @_persistence.setPercentComplete(taskID, percentComplete) - - completeTask: (taskID) -> - @setPercentComplete(taskID,100) - @hideSubtasks(taskID) - - uncompleteTask: (taskID) -> - @setPercentComplete(taskID,0) - - completeChildren: (taskID) -> - childrenID = @_$tasksmodel.getChildrenID(taskID) - for childID in childrenID - @setPercentComplete(childID,100) - - uncompleteParents: (uid) -> - if uid - parentID = @_$tasksmodel.getIdByUid(uid) - if @_$tasksmodel.completed(parentID) - @setPercentComplete(parentID,0) - - unhideSubtasks: (taskID) -> - @_$tasksmodel.setHideSubtasks(taskID,false) - @_persistence.setHideSubtasks(taskID,false) - - hideSubtasks: (taskID) -> - @_$tasksmodel.setHideSubtasks(taskID,true) - @_persistence.setHideSubtasks(taskID,true) - - deleteTask: (taskID) -> - childrenID = @_$tasksmodel.getChildrenID(taskID) - for childID in childrenID - @deleteTask(childID) - @_$tasksmodel.removeById(taskID) - @_persistence.deleteTask(taskID) - - initDueDate: (taskID) -> - due = moment(@_$tasksmodel.getById(taskID).due, "YYYYMMDDTHHmmss") - if !due.isValid() - @setDue(taskID, moment().startOf('hour').add(1, 'h'),'time') - - setDue: (taskID, date, type='day') -> - due = moment(@_$tasksmodel.getById(taskID).due, "YYYYMMDDTHHmmss") - if type=='day' - if moment(due).isValid() - due.year(date.year()).month(date.month()).date(date.date()) - else - due = date.add(12, 'h') - else if type == 'time' - if moment(due).isValid() - due.hour(date.hour()).minute(date.minute()) - else - due = date - else if type == 'all' - due = date - else - return - @_$tasksmodel.setDueDate(taskID,due.format('YYYYMMDDTHHmmss')) - @checkReminderDate(taskID) - @_persistence.setDueDate(taskID, - if due.isValid() then due.unix() else false) - - deleteDueDate: (taskID) -> - reminder = @_$tasksmodel.getById(taskID).reminder - if (reminder != null && reminder.type == 'DURATION' && - reminder.duration.params.related == 'END') - @deleteReminderDate(taskID) - @_$tasksmodel.setDueDate(taskID, null) - @_persistence.setDueDate(taskID, false) - - initStartDate: (taskID) -> - start = moment(@_$tasksmodel.getById(taskID).start, "YYYYMMDDTHHmmss") - if !start.isValid() - @setStart(taskID, moment().startOf('hour').add(1, 'h'),'time') - - setStart: (taskID, date, type='day') -> - start = moment(@_$tasksmodel.getById(taskID).start, "YYYYMMDDTHHmmss") - if type == 'day' - if moment(start).isValid() - start.year(date.year()).month(date.month()).date(date.date()) - else - start = date.add(12, 'h') - else if type == 'time' - if moment(start).isValid() - start.hour(date.hour()).minute(date.minute()) - else - start = date - else - return - @_$tasksmodel.setStartDate(taskID,start.format('YYYYMMDDTHHmmss')) - @checkReminderDate(taskID) - @_persistence.setStartDate(taskID, - if start.isValid() then start.unix() else false) - - deleteStartDate: (taskID) -> - reminder = @_$tasksmodel.getById(taskID).reminder - if (reminder != null && reminder.type == 'DURATION' && - reminder.duration.params.related == 'START') - @deleteReminderDate(taskID) - @_$tasksmodel.setStartDate(taskID, null) - @_persistence.setStartDate(taskID, false) - - initReminder: (taskID) -> - if !@checkReminderDate(taskID) - task = @_$tasksmodel.getById(taskID) - task.reminder = { - type: 'DURATION', - action: 'DISPLAY', - duration: { - token: 'week', - week: 0, - day: 0, - hour: 0, - minute: 0, - second: 0, - params: { - invert: true - } - } - } - if moment(task.start, "YYYYMMDDTHHmmss").isValid() - p = task.reminder.duration.params - p.related = 'START' - p.id = '10' - else if moment(task.due, "YYYYMMDDTHHmmss").isValid() - p = task.reminder.duration.params - p.related = 'END' - p.id = '11' - else - task.reminder.type = 'DATE-TIME' - task.reminder.date = moment().startOf('hour').add(1, 'h') - .format('YYYYMMDDTHHmmss') - @setReminder(taskID) - - setReminderDate: (taskID, date, type='day') -> - reminder = @_$tasksmodel.getById(taskID).reminder - newreminder = { - type: 'DATE-TIME', - action: 'DISPLAY', - duration: null - } - if type == 'day' - if (@checkReminderDate(taskID) || reminder == null) - reminderdate = moment(reminder.date, "YYYYMMDDTHHmmss") - newreminder.action = reminder.action - if (reminderdate.isValid() && reminder.type == 'DATE-TIME') - reminderdate.year(date.year()).month(date.month()).date(date.date()) - else - reminderdate = date.add(12, 'h') - else - reminderdate = date.add(12, 'h') - else if type == 'time' - if (@checkReminderDate(taskID) || reminder == null) - reminderdate = moment(reminder.date, "YYYYMMDDTHHmmss") - newreminder.action = reminder.action - if (reminderdate.isValid() && reminder.type == 'DATE-TIME') - reminderdate.hour(date.hour()).minute(date.minute()) - else - reminderdate = date - else - reminderdate = date - else - return - newreminder.date = reminderdate.format('YYYYMMDDTHHmmss') - @_$tasksmodel.setReminder(taskID,newreminder) - @_persistence.setReminder(taskID,newreminder) - - setReminder: (taskID) -> - if @checkReminderDate(taskID) - reminder = @_$tasksmodel.getById(taskID).reminder - @_persistence.setReminder(taskID,reminder) - - checkReminderDate: (taskID) -> - task = @_$tasksmodel.getById(taskID) - reminder = task.reminder - if(reminder != null && reminder.type == 'DURATION') - if !reminder.duration - return false - else if reminder.duration.params.related == 'START' - token = 'start' - else if reminder.duration.params.related == 'END' - token = 'due' - else - return false - date = moment(task[token], "YYYYMMDDTHHmmss") - duration = reminder.duration - d = { - w: duration.week, - d: duration.day, - h: duration.hour, - m: duration.minute, - s: duration.second - } - if duration.params.invert - date = date.subtract(d) - else - date = date.add(d) - task.reminder.date = date.format('YYYYMMDDTHHmmss') - else if(reminder != null && reminder.type == 'DATE-TIME') - duration = reminder.duration - date = moment(reminder.date, "YYYYMMDDTHHmmss") - if !date.isValid() - return false - if duration - if duration.params.related == 'START' - related = moment(task.start, "YYYYMMDDTHHmmss") - else - related = moment(task.due, "YYYYMMDDTHHmmss") - seg = @secondsToSegments(date.diff(related, 'seconds')) - duration.params.invert = seg.invert - duration.token = 'week' - duration.week = seg.week - duration.day = seg.day - duration.hour = seg.hour - duration.minute = seg.minute - duration.second = seg.second - else - if task.start - related = moment(task.start, "YYYYMMDDTHHmmss") - rel = 'START' - d = 0 - else if task.due - related = moment(task.due, "YYYYMMDDTHHmmss") - rel = 'END' - d = 1 - else - return true - seg = @secondsToSegments(date.diff(related, 'seconds')) - reminder.duration = { - token: 'week' - params: { - related: rel - invert: seg.invert - id: +seg.invert+''+d - } - week: seg.week - day: seg.day - hour: seg.hour - minute: seg.minute - second: seg.second - } - else - return false - return true - - secondsToSegments: (s) -> - if s<0 - s *= -1 - i = true - else - i = false - w = Math.floor(s/604800) - s -= w*604800 - d = Math.floor(s/86400) - s -= d*86400 - h = Math.floor(s/3600) - s -= h*3600 - m = Math.floor(s/60) - s -= m*60 - return {week:w, day:d, hour:h, minute:m, second:s, invert: i} - - deleteReminderDate: (taskID) -> - @_$tasksmodel.setReminder(taskID, null) - @_persistence.setReminder(taskID,false) - - changeCalendarId: (taskID, calendarID) -> - @_$tasksmodel.changeCalendarId(taskID, calendarID) - @_persistence.changeCalendarId(taskID, calendarID) - childrenID = @_$tasksmodel.getChildrenID(taskID) - task = @_$tasksmodel.getById(taskID) - for childID in childrenID - child = @_$tasksmodel.getById(childID) - if child.calendarid != task.calendarid - @changeCalendarId(childID,task.calendarid) - if !@_$tasksmodel.hasNoParent(task) - parentID = @_$tasksmodel.getIdByUid(task.related) - parent = @_$tasksmodel.getById(parentID) - if parent.calendarid != task.calendarid - @changeParent(taskID, '', '') - - - setTaskNote: (taskID, note) -> - @_persistence.setTaskNote(taskID, note) - - setTaskName: (taskID, name) -> - @_persistence.setTaskName(taskID, name) - - changeCollection: (taskID, collectionID) -> - - switch collectionID - when 'starred' - @starTask(taskID) - when 'completed' - @completeTask(taskID) - when 'uncompleted' - @uncompleteTask(taskID) - when 'today' - @setDue(taskID,moment().startOf('day').add(12, 'h'),'all') - when 'week', 'all' - return false - else - return false - - changeParent: (taskID, parentID, collectionID) -> - task = @_$tasksmodel.getById(taskID) - if parentID - parent = @_$tasksmodel.getById(parentID) - @unhideSubtasks(parentID) - related = parent.uid - - if parent.completed && !task.completed - @uncompleteTask(parentID) - if parent.calendarid != task.calendarid - @changeCalendarId(taskID,parent.calendarid) - else - related = "" - if collectionID != "completed" && task.completed - @uncompleteTask(taskID) - @_$tasksmodel.changeParent(taskID,related) - @_persistence.changeParent(taskID,related) - - updateModel: () -> - @_$tasksmodel.voidAll() - success = () => - @_$tasksmodel.removeVoid() - @_persistence.getTasks('init', 'all', success, true) - - setShowHidden: (showHidden) -> - @_persistence.setShowHidden(showHidden) - - addComment: (comment, onSuccess=null, onFailure=null) -> - onSuccess or= -> - onFailure or= -> - - @_$tasksmodel.addComment(comment) - - success = (response) => - if response.status == 'error' - onFailure() - else - onSuccess(response.data) - @_persistence.addComment(comment, success) - - deleteComment: (taskID, commentID) -> - @_$tasksmodel.deleteComment(taskID, commentID) - @_persistence.deleteComment(taskID, commentID) - - getCompletedTasks: (listID) -> - @_persistence.getTasks('completed', listID) - - addCategory: (taskID, category) -> - @_persistence.addCategory(taskID, category) - - removeCategory: (taskID, category) -> - @_persistence.removeCategory(taskID, category) - - return new TasksBusinessLayer(TasksModel, Persistence) - -] diff --git a/js/app/services/businesslayer/tasksbusinesslayer.js b/js/app/services/businesslayer/tasksbusinesslayer.js new file mode 100644 index 00000000..b40c4e02 --- /dev/null +++ b/js/app/services/businesslayer/tasksbusinesslayer.js @@ -0,0 +1,575 @@ +/** + * 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').factory('TasksBusinessLayer', [ + 'TasksModel', 'Persistence', function(TasksModel, Persistence) { + var TasksBusinessLayer; + TasksBusinessLayer = (function() { + function TasksBusinessLayer(_$tasksmodel, _persistence) { + this._$tasksmodel = _$tasksmodel; + this._persistence = _persistence; + } + + TasksBusinessLayer.prototype.addTask = function(task, onSuccess, onFailure) { + var parentID, success, + _this = this; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + this._$tasksmodel.add(task); + this.uncompleteParents(task.related); + parentID = this._$tasksmodel.getIdByUid(task.related); + if (parentID) { + this.unhideSubtasks(parentID); + } + success = function(response) { + if (response.status === 'error') { + return onFailure(); + } else { + return onSuccess(response.data); + } + }; + return this._persistence.addTask(task, success); + }; + + TasksBusinessLayer.prototype.getAll = function(calendar) {}; + + TasksBusinessLayer.prototype.getTask = function(taskID, onSuccess, onFailure) { + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + return this._persistence.getTask(taskID, onSuccess, true); + }; + + TasksBusinessLayer.prototype.setPriority = function(taskID, priority) { + this._$tasksmodel.setPriority(taskID, priority); + if (+priority === 6 || +priority === 7 || +priority === 8 || +priority === 9) { + this._$tasksmodel.star(taskID); + } else { + this._$tasksmodel.unstar(taskID); + } + return this._persistence.setPriority(taskID, priority); + }; + + TasksBusinessLayer.prototype.starTask = function(taskID) { + return this.setPriority(taskID, '9'); + }; + + TasksBusinessLayer.prototype.unstarTask = function(taskID) { + return this.setPriority(taskID, '0'); + }; + + TasksBusinessLayer.prototype.setPercentComplete = function(taskID, percentComplete) { + var task; + this._$tasksmodel.setPercentComplete(taskID, percentComplete); + if (percentComplete < 100) { + this._$tasksmodel.uncomplete(taskID); + task = this._$tasksmodel.getById(taskID); + this.uncompleteParents(task.related); + } else { + this._$tasksmodel.complete(taskID); + this.completeChildren(taskID); + } + return this._persistence.setPercentComplete(taskID, percentComplete); + }; + + TasksBusinessLayer.prototype.completeTask = function(taskID) { + this.setPercentComplete(taskID, 100); + return this.hideSubtasks(taskID); + }; + + TasksBusinessLayer.prototype.uncompleteTask = function(taskID) { + return this.setPercentComplete(taskID, 0); + }; + + TasksBusinessLayer.prototype.completeChildren = function(taskID) { + var childID, childrenID, _i, _len, _results; + childrenID = this._$tasksmodel.getChildrenID(taskID); + _results = []; + for (_i = 0, _len = childrenID.length; _i < _len; _i++) { + childID = childrenID[_i]; + _results.push(this.setPercentComplete(childID, 100)); + } + return _results; + }; + + TasksBusinessLayer.prototype.uncompleteParents = function(uid) { + var parentID; + if (uid) { + parentID = this._$tasksmodel.getIdByUid(uid); + if (this._$tasksmodel.completed(parentID)) { + return this.setPercentComplete(parentID, 0); + } + } + }; + + TasksBusinessLayer.prototype.unhideSubtasks = function(taskID) { + this._$tasksmodel.setHideSubtasks(taskID, false); + return this._persistence.setHideSubtasks(taskID, false); + }; + + TasksBusinessLayer.prototype.hideSubtasks = function(taskID) { + this._$tasksmodel.setHideSubtasks(taskID, true); + return this._persistence.setHideSubtasks(taskID, true); + }; + + TasksBusinessLayer.prototype.deleteTask = function(taskID) { + var childID, childrenID, _i, _len; + childrenID = this._$tasksmodel.getChildrenID(taskID); + for (_i = 0, _len = childrenID.length; _i < _len; _i++) { + childID = childrenID[_i]; + this.deleteTask(childID); + } + this._$tasksmodel.removeById(taskID); + return this._persistence.deleteTask(taskID); + }; + + TasksBusinessLayer.prototype.initDueDate = function(taskID) { + var due; + due = moment(this._$tasksmodel.getById(taskID).due, "YYYYMMDDTHHmmss"); + if (!due.isValid()) { + return this.setDue(taskID, moment().startOf('hour').add(1, 'h'), 'time'); + } + }; + + TasksBusinessLayer.prototype.setDue = function(taskID, date, type) { + var due; + if (type == null) { + type = 'day'; + } + due = moment(this._$tasksmodel.getById(taskID).due, "YYYYMMDDTHHmmss"); + if (type === 'day') { + if (moment(due).isValid()) { + due.year(date.year()).month(date.month()).date(date.date()); + } else { + due = date.add(12, 'h'); + } + } else if (type === 'time') { + if (moment(due).isValid()) { + due.hour(date.hour()).minute(date.minute()); + } else { + due = date; + } + } else if (type === 'all') { + due = date; + } else { + return; + } + this._$tasksmodel.setDueDate(taskID, due.format('YYYYMMDDTHHmmss')); + this.checkReminderDate(taskID); + return this._persistence.setDueDate(taskID, due.isValid() ? due.unix() : false); + }; + + TasksBusinessLayer.prototype.deleteDueDate = function(taskID) { + var reminder; + reminder = this._$tasksmodel.getById(taskID).reminder; + if (reminder !== null && reminder.type === 'DURATION' && reminder.duration.params.related === 'END') { + this.deleteReminderDate(taskID); + } + this._$tasksmodel.setDueDate(taskID, null); + return this._persistence.setDueDate(taskID, false); + }; + + TasksBusinessLayer.prototype.initStartDate = function(taskID) { + var start; + start = moment(this._$tasksmodel.getById(taskID).start, "YYYYMMDDTHHmmss"); + if (!start.isValid()) { + return this.setStart(taskID, moment().startOf('hour').add(1, 'h'), 'time'); + } + }; + + TasksBusinessLayer.prototype.setStart = function(taskID, date, type) { + var start; + if (type == null) { + type = 'day'; + } + start = moment(this._$tasksmodel.getById(taskID).start, "YYYYMMDDTHHmmss"); + if (type === 'day') { + if (moment(start).isValid()) { + start.year(date.year()).month(date.month()).date(date.date()); + } else { + start = date.add(12, 'h'); + } + } else if (type === 'time') { + if (moment(start).isValid()) { + start.hour(date.hour()).minute(date.minute()); + } else { + start = date; + } + } else { + return; + } + this._$tasksmodel.setStartDate(taskID, start.format('YYYYMMDDTHHmmss')); + this.checkReminderDate(taskID); + return this._persistence.setStartDate(taskID, start.isValid() ? start.unix() : false); + }; + + TasksBusinessLayer.prototype.deleteStartDate = function(taskID) { + var reminder; + reminder = this._$tasksmodel.getById(taskID).reminder; + if (reminder !== null && reminder.type === 'DURATION' && reminder.duration.params.related === 'START') { + this.deleteReminderDate(taskID); + } + this._$tasksmodel.setStartDate(taskID, null); + return this._persistence.setStartDate(taskID, false); + }; + + TasksBusinessLayer.prototype.initReminder = function(taskID) { + var p, task; + if (!this.checkReminderDate(taskID)) { + task = this._$tasksmodel.getById(taskID); + task.reminder = { + type: 'DURATION', + action: 'DISPLAY', + duration: { + token: 'week', + week: 0, + day: 0, + hour: 0, + minute: 0, + second: 0, + params: { + invert: true + } + } + }; + if (moment(task.start, "YYYYMMDDTHHmmss").isValid()) { + p = task.reminder.duration.params; + p.related = 'START'; + p.id = '10'; + } else if (moment(task.due, "YYYYMMDDTHHmmss").isValid()) { + p = task.reminder.duration.params; + p.related = 'END'; + p.id = '11'; + } else { + task.reminder.type = 'DATE-TIME'; + task.reminder.date = moment().startOf('hour').add(1, 'h').format('YYYYMMDDTHHmmss'); + } + return this.setReminder(taskID); + } + }; + + TasksBusinessLayer.prototype.setReminderDate = function(taskID, date, type) { + var newreminder, reminder, reminderdate; + if (type == null) { + type = 'day'; + } + reminder = this._$tasksmodel.getById(taskID).reminder; + newreminder = { + type: 'DATE-TIME', + action: 'DISPLAY', + duration: null + }; + if (type === 'day') { + if (this.checkReminderDate(taskID) || reminder === null) { + reminderdate = moment(reminder.date, "YYYYMMDDTHHmmss"); + newreminder.action = reminder.action; + if (reminderdate.isValid() && reminder.type === 'DATE-TIME') { + reminderdate.year(date.year()).month(date.month()).date(date.date()); + } else { + reminderdate = date.add(12, 'h'); + } + } else { + reminderdate = date.add(12, 'h'); + } + } else if (type === 'time') { + if (this.checkReminderDate(taskID) || reminder === null) { + reminderdate = moment(reminder.date, "YYYYMMDDTHHmmss"); + newreminder.action = reminder.action; + if (reminderdate.isValid() && reminder.type === 'DATE-TIME') { + reminderdate.hour(date.hour()).minute(date.minute()); + } else { + reminderdate = date; + } + } else { + reminderdate = date; + } + } else { + return; + } + newreminder.date = reminderdate.format('YYYYMMDDTHHmmss'); + this._$tasksmodel.setReminder(taskID, newreminder); + return this._persistence.setReminder(taskID, newreminder); + }; + + TasksBusinessLayer.prototype.setReminder = function(taskID) { + var reminder; + if (this.checkReminderDate(taskID)) { + reminder = this._$tasksmodel.getById(taskID).reminder; + return this._persistence.setReminder(taskID, reminder); + } + }; + + TasksBusinessLayer.prototype.checkReminderDate = function(taskID) { + var d, date, duration, rel, related, reminder, seg, task, token; + task = this._$tasksmodel.getById(taskID); + reminder = task.reminder; + if (reminder !== null && reminder.type === 'DURATION') { + if (!reminder.duration) { + return false; + } else if (reminder.duration.params.related === 'START') { + token = 'start'; + } else if (reminder.duration.params.related === 'END') { + token = 'due'; + } else { + return false; + } + date = moment(task[token], "YYYYMMDDTHHmmss"); + duration = reminder.duration; + d = { + w: duration.week, + d: duration.day, + h: duration.hour, + m: duration.minute, + s: duration.second + }; + if (duration.params.invert) { + date = date.subtract(d); + } else { + date = date.add(d); + } + task.reminder.date = date.format('YYYYMMDDTHHmmss'); + } else if (reminder !== null && reminder.type === 'DATE-TIME') { + duration = reminder.duration; + date = moment(reminder.date, "YYYYMMDDTHHmmss"); + if (!date.isValid()) { + return false; + } + if (duration) { + if (duration.params.related === 'START') { + related = moment(task.start, "YYYYMMDDTHHmmss"); + } else { + related = moment(task.due, "YYYYMMDDTHHmmss"); + } + seg = this.secondsToSegments(date.diff(related, 'seconds')); + duration.params.invert = seg.invert; + duration.token = 'week'; + duration.week = seg.week; + duration.day = seg.day; + duration.hour = seg.hour; + duration.minute = seg.minute; + duration.second = seg.second; + } else { + if (task.start) { + related = moment(task.start, "YYYYMMDDTHHmmss"); + rel = 'START'; + d = 0; + } else if (task.due) { + related = moment(task.due, "YYYYMMDDTHHmmss"); + rel = 'END'; + d = 1; + } else { + return true; + } + seg = this.secondsToSegments(date.diff(related, 'seconds')); + reminder.duration = { + token: 'week', + params: { + related: rel, + invert: seg.invert, + id: +seg.invert + '' + d + }, + week: seg.week, + day: seg.day, + hour: seg.hour, + minute: seg.minute, + second: seg.second + }; + } + } else { + return false; + } + return true; + }; + + TasksBusinessLayer.prototype.secondsToSegments = function(s) { + var d, h, i, m, w; + if (s < 0) { + s *= -1; + i = true; + } else { + i = false; + } + w = Math.floor(s / 604800); + s -= w * 604800; + d = Math.floor(s / 86400); + s -= d * 86400; + h = Math.floor(s / 3600); + s -= h * 3600; + m = Math.floor(s / 60); + s -= m * 60; + return { + week: w, + day: d, + hour: h, + minute: m, + second: s, + invert: i + }; + }; + + TasksBusinessLayer.prototype.deleteReminderDate = function(taskID) { + this._$tasksmodel.setReminder(taskID, null); + return this._persistence.setReminder(taskID, false); + }; + + TasksBusinessLayer.prototype.changeCalendarId = function(taskID, calendarID) { + var child, childID, childrenID, parent, parentID, task, _i, _len; + this._$tasksmodel.changeCalendarId(taskID, calendarID); + this._persistence.changeCalendarId(taskID, calendarID); + childrenID = this._$tasksmodel.getChildrenID(taskID); + task = this._$tasksmodel.getById(taskID); + for (_i = 0, _len = childrenID.length; _i < _len; _i++) { + childID = childrenID[_i]; + child = this._$tasksmodel.getById(childID); + if (child.calendarid !== task.calendarid) { + this.changeCalendarId(childID, task.calendarid); + } + } + if (!this._$tasksmodel.hasNoParent(task)) { + parentID = this._$tasksmodel.getIdByUid(task.related); + parent = this._$tasksmodel.getById(parentID); + if (parent.calendarid !== task.calendarid) { + return this.changeParent(taskID, '', ''); + } + } + }; + + TasksBusinessLayer.prototype.setTaskNote = function(taskID, note) { + return this._persistence.setTaskNote(taskID, note); + }; + + TasksBusinessLayer.prototype.setTaskName = function(taskID, name) { + return this._persistence.setTaskName(taskID, name); + }; + + TasksBusinessLayer.prototype.changeCollection = function(taskID, collectionID) { + switch (collectionID) { + case 'starred': + return this.starTask(taskID); + case 'completed': + return this.completeTask(taskID); + case 'uncompleted': + return this.uncompleteTask(taskID); + case 'today': + return this.setDue(taskID, moment().startOf('day').add(12, 'h'), 'all'); + case 'week': + case 'all': + return false; + default: + return false; + } + }; + + TasksBusinessLayer.prototype.changeParent = function(taskID, parentID, collectionID) { + var parent, related, task; + task = this._$tasksmodel.getById(taskID); + if (parentID) { + parent = this._$tasksmodel.getById(parentID); + this.unhideSubtasks(parentID); + related = parent.uid; + if (parent.completed && !task.completed) { + this.uncompleteTask(parentID); + } + if (parent.calendarid !== task.calendarid) { + this.changeCalendarId(taskID, parent.calendarid); + } + } else { + related = ""; + if (collectionID !== "completed" && task.completed) { + this.uncompleteTask(taskID); + } + } + this._$tasksmodel.changeParent(taskID, related); + return this._persistence.changeParent(taskID, related); + }; + + TasksBusinessLayer.prototype.updateModel = function() { + var success, + _this = this; + this._$tasksmodel.voidAll(); + success = function() { + return _this._$tasksmodel.removeVoid(); + }; + return this._persistence.getTasks('init', 'all', success, true); + }; + + TasksBusinessLayer.prototype.setShowHidden = function(showHidden) { + return this._persistence.setShowHidden(showHidden); + }; + + TasksBusinessLayer.prototype.addComment = function(comment, onSuccess, onFailure) { + var success, + _this = this; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + this._$tasksmodel.addComment(comment); + success = function(response) { + if (response.status === 'error') { + return onFailure(); + } else { + return onSuccess(response.data); + } + }; + return this._persistence.addComment(comment, success); + }; + + TasksBusinessLayer.prototype.deleteComment = function(taskID, commentID) { + this._$tasksmodel.deleteComment(taskID, commentID); + return this._persistence.deleteComment(taskID, commentID); + }; + + TasksBusinessLayer.prototype.getCompletedTasks = function(listID) { + return this._persistence.getTasks('completed', listID); + }; + + TasksBusinessLayer.prototype.addCategory = function(taskID, category) { + return this._persistence.addCategory(taskID, category); + }; + + TasksBusinessLayer.prototype.removeCategory = function(taskID, category) { + return this._persistence.removeCategory(taskID, category); + }; + + return TasksBusinessLayer; + + })(); + return new TasksBusinessLayer(TasksModel, Persistence); + } + ]); + +}).call(this); diff --git a/js/app/services/calendarservice.js b/js/app/services/calendarservice.js new file mode 100644 index 00000000..aadfa1d5 --- /dev/null +++ b/js/app/services/calendarservice.js @@ -0,0 +1,461 @@ +/** + * ownCloud - Tasks + * + * @author Raghu Nayyar + * @author Georg Ehrke + * @author Raimund Schlüßler + * @copyright 2016 Raghu Nayyar <beingminimal@gmail.com> + * @copyright 2016 Georg Ehrke <oc.list@georgehrke.com> + * @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/>. + * + */ + +angular.module('Tasks').service('CalendarService', ['DavClient', 'Calendar', function(DavClient, Calendar){ + 'use strict'; + + var _this = this; + + this._CALENDAR_HOME = null; + + this._currentUserPrincipal = null; + + this._takenUrls = []; + + this._PROPERTIES = [ + '{' + DavClient.NS_DAV + '}displayname', + '{' + DavClient.NS_IETF + '}calendar-description', + '{' + DavClient.NS_IETF + '}calendar-timezone', + '{' + DavClient.NS_APPLE + '}calendar-order', + '{' + DavClient.NS_APPLE + '}calendar-color', + '{' + DavClient.NS_IETF + '}supported-calendar-component-set', + '{' + DavClient.NS_OWNCLOUD + '}calendar-enabled', + '{' + DavClient.NS_DAV + '}acl', + '{' + DavClient.NS_DAV + '}owner', + '{' + DavClient.NS_OWNCLOUD + '}invite' + ]; + + function discoverHome(callback) { + return DavClient.propFind(DavClient.buildUrl(OC.linkToRemoteBase('dav')), ['{' + DavClient.NS_DAV + '}current-user-principal'], 0, {'requesttoken': OC.requestToken}).then(function(response) { + if (!DavClient.wasRequestSuccessful(response.status)) { + throw "CalDAV client could not be initialized - Querying current-user-principal failed"; + } + + if (response.body.propStat.length < 1) { + return; + } + var props = response.body.propStat[0].properties; + _this._currentUserPrincipal = props['{' + DavClient.NS_DAV + '}current-user-principal'][0].textContent; + + return DavClient.propFind(DavClient.buildUrl(_this._currentUserPrincipal), ['{' + DavClient.NS_IETF + '}calendar-home-set'], 0, {'requesttoken': OC.requestToken}).then(function (response) { + if (!DavClient.wasRequestSuccessful(response.status)) { + throw "CalDAV client could not be initialized - Querying calendar-home-set failed"; + } + + if (response.body.propStat.length < 1) { + return; + } + var props = response.body.propStat[0].properties; + _this._CALENDAR_HOME = props['{' + DavClient.NS_IETF + '}calendar-home-set'][0].textContent; + + return callback(); + }); + }); + } + + function getResponseCodeFromHTTPResponse(t) { + return parseInt(t.split(' ')[1]); + } + + this.getAll = function() { + if (this._CALENDAR_HOME === null) { + return discoverHome(function() { + return _this.getAll(); + }); + } + + var prom = DavClient.propFind(DavClient.buildUrl(this._CALENDAR_HOME), this._PROPERTIES, 1, {'requesttoken': OC.requestToken}).then(function(response) { + var calendars = []; + + if (!DavClient.wasRequestSuccessful(response.status)) { + throw "CalDAV client could not be initialized - Querying calendars failed"; + } + + for (var i = 0; i < response.body.length; i++) { + var body = response.body[i]; + if (body.propStat.length < 1) { + continue; + } + + _this._takenUrls.push(body.href); + + var responseCode = getResponseCodeFromHTTPResponse(body.propStat[0].status); + if (!DavClient.wasRequestSuccessful(responseCode)) { + continue; + } + + var doesSupportVTodo = false; + var components = body.propStat[0].properties['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']; + if (components) { + for (var j=0; j < components.length; j++) { + var name = components[j].attributes.getNamedItem('name').textContent.toLowerCase(); + if (name === 'vtodo') { + doesSupportVTodo = true; + } + } + } + + if (!doesSupportVTodo) { + continue; + } + + _this._getACLFromResponse(body); + + var uri = body.href.substr(_this._CALENDAR_HOME.length).replace(/[^\w\-]+/g, ''); + + var calendar = new Calendar(body.href, body.propStat[0].properties, uri); + calendars.push(calendar); + } + + return calendars; + }); + return prom; + }; + + this.get = function(url) { + if (this._CALENDAR_HOME === null) { + return discoverHome(function() { + return _this.get(url); + }); + } + + return DavClient.propFind(DavClient.buildUrl(url), this._PROPERTIES, 0, {'requesttoken': OC.requestToken}).then(function(response) { + var body = response.body; + if (body.propStat.length < 1) { + //TODO - something went wrong + return; + } + + var responseCode = getResponseCodeFromHTTPResponse(body.propStat[0].status); + if (!DavClient.wasRequestSuccessful(responseCode)) { + //TODO - something went wrong + return; + } + + _this._getACLFromResponse(body); + + var uri = body.href.substr(_this._CALENDAR_HOME.length).replace(/[^\w\-]+/g, ''); + + return new Calendar(body.href, body.propStat[0].properties, uri); + }); + }; + + this.create = function(name, color, components) { + if (this._CALENDAR_HOME === null) { + return discoverHome(function() { + return _this.create(name, color); + }); + } + + if (typeof components === 'undefined') { + components = ['vtodo']; + } + + var xmlDoc = document.implementation.createDocument('', '', null); + var cMkcalendar = xmlDoc.createElement('c:mkcalendar'); + cMkcalendar.setAttribute('xmlns:c', 'urn:ietf:params:xml:ns:caldav'); + cMkcalendar.setAttribute('xmlns:d', 'DAV:'); + cMkcalendar.setAttribute('xmlns:a', 'http://apple.com/ns/ical/'); + cMkcalendar.setAttribute('xmlns:o', 'http://owncloud.org/ns'); + xmlDoc.appendChild(cMkcalendar); + + var dSet = xmlDoc.createElement('d:set'); + cMkcalendar.appendChild(dSet); + + var dProp = xmlDoc.createElement('d:prop'); + dSet.appendChild(dProp); + + dProp.appendChild(this._createXMLForProperty(xmlDoc, 'displayname', name)); + dProp.appendChild(this._createXMLForProperty(xmlDoc, 'enabled', true)); + dProp.appendChild(this._createXMLForProperty(xmlDoc, 'color', color)); + dProp.appendChild(this._createXMLForProperty(xmlDoc, 'components', components)); + + var body = cMkcalendar.outerHTML; + + var uri = this._suggestUri(name); + var url = this._CALENDAR_HOME + uri + '/'; + var headers = { + 'Content-Type' : 'application/xml; charset=utf-8', + 'requesttoken' : OC.requestToken + }; + + return DavClient.request('MKCALENDAR', url, headers, body).then(function(response) { + if (response.status === 201) { + _this._takenUrls.push(url); + return _this.get(url).then(function(calendar) { + calendar.enabled = true; + return _this.update(calendar); + }); + } + }); + }; + + this.update = function(calendar) { + var xmlDoc = document.implementation.createDocument('', '', null); + var dPropUpdate = xmlDoc.createElement('d:propertyupdate'); + dPropUpdate.setAttribute('xmlns:c', 'urn:ietf:params:xml:ns:caldav'); + dPropUpdate.setAttribute('xmlns:d', 'DAV:'); + dPropUpdate.setAttribute('xmlns:a', 'http://apple.com/ns/ical/'); + dPropUpdate.setAttribute('xmlns:o', 'http://owncloud.org/ns'); + xmlDoc.appendChild(dPropUpdate); + + var dSet = xmlDoc.createElement('d:set'); + dPropUpdate.appendChild(dSet); + + var dProp = xmlDoc.createElement('d:prop'); + dSet.appendChild(dProp); + + var updatedProperties = calendar.updatedProperties; + calendar.resetUpdatedProperties(); + for (var i=0; i < updatedProperties.length; i++) { + dProp.appendChild(this._createXMLForProperty( + xmlDoc, + updatedProperties[i], + calendar[updatedProperties[i]] + )); + } + + var url = calendar.url; + var body = dPropUpdate.outerHTML; + var headers = { + 'Content-Type' : 'application/xml; charset=utf-8', + 'requesttoken' : OC.requestToken + }; + + return DavClient.request('PROPPATCH', url, headers, body).then(function(response) { + return calendar; + }); + }; + + this.delete = function(calendar) { + return DavClient.request('DELETE', calendar.url, {'requesttoken': OC.requestToken}, '').then(function(response) { + if (response.status === 204) { + return true; + } else { + // TODO - handle error case + return false; + } + }); + }; + + this.share = function(calendar, shareType, shareWith, writable, existingShare) { + var xmlDoc = document.implementation.createDocument('', '', null); + var oShare = xmlDoc.createElement('o:share'); + oShare.setAttribute('xmlns:d', 'DAV:'); + oShare.setAttribute('xmlns:o', 'http://owncloud.org/ns'); + xmlDoc.appendChild(oShare); + + var oSet = xmlDoc.createElement('o:set'); + oShare.appendChild(oSet); + + var dHref = xmlDoc.createElement('d:href'); + if (shareType === OC.Share.SHARE_TYPE_USER) { + dHref.textContent = 'principal:principals/users/'; + } else if (shareType === OC.Share.SHARE_TYPE_GROUP) { + dHref.textContent = 'principal:principals/groups/'; + } + dHref.textContent += shareWith; + oSet.appendChild(dHref); + + var oSummary = xmlDoc.createElement('o:summary'); + oSummary.textContent = t('calendar', '{calendar} shared by {owner}', { + calendar: calendar.displayname, + owner: calendar.owner + }); + oSet.appendChild(oSummary); + + if (writable) { + var oRW = xmlDoc.createElement('o:read-write'); + oSet.appendChild(oRW); + } + + var headers = { + 'Content-Type' : 'application/xml; charset=utf-8', + requesttoken : oc_requesttoken + }; + var body = oShare.outerHTML; + return DavClient.request('POST', calendar.url, headers, body).then(function(response) { + if (response.status === 200) { + if (!existingShare) { + if (shareType === OC.Share.SHARE_TYPE_USER) { + calendar.sharedWith.users.push({ + id: shareWith, + displayname: shareWith, + writable: writable + }); + } else if (shareType === OC.Share.SHARE_TYPE_GROUP) { + calendar.sharedWith.groups.push({ + id: shareWith, + displayname: shareWith, + writable: writable + }); + } + } + } + }); + }; + + this.unshare = function(calendar, shareType, shareWith) { + var xmlDoc = document.implementation.createDocument('', '', null); + var oShare = xmlDoc.createElement('o:share'); + oShare.setAttribute('xmlns:d', 'DAV:'); + oShare.setAttribute('xmlns:o', 'http://owncloud.org/ns'); + xmlDoc.appendChild(oShare); + + var oRemove = xmlDoc.createElement('o:remove'); + oShare.appendChild(oRemove); + + var dHref = xmlDoc.createElement('d:href'); + if (shareType === OC.Share.SHARE_TYPE_USER) { + dHref.textContent = 'principal:principals/users/'; + } else if (shareType === OC.Share.SHARE_TYPE_GROUP) { + dHref.textContent = 'principal:principals/groups/'; + } + dHref.textContent += shareWith; + oRemove.appendChild(dHref); + + var headers = { + 'Content-Type' : 'application/xml; charset=utf-8', + requesttoken: oc_requesttoken + }; + var body = oShare.outerHTML; + return DavClient.request('POST', calendar.url, headers, body).then(function(response) { + if (response.status === 200) { + if (shareType === OC.Share.SHARE_TYPE_USER) { + calendar.sharedWith.users = calendar.sharedWith.users.filter(function(user) { + return user.id !== shareWith; + }); + } else if (shareType === OC.Share.SHARE_TYPE_GROUP) { + calendar.sharedWith.groups = calendar.sharedWith.groups.filter(function(groups) { + return groups.id !== shareWith; + }); + } + //todo - remove entry from calendar object + return true; + } else { + return false; + } + }); + }; + + this._createXMLForProperty = function(xmlDoc, propName, value) { + switch(propName) { + case 'enabled': + var oEnabled = xmlDoc.createElement('o:calendar-enabled'); + oEnabled.textContent = value ? '1' : '0'; + return oEnabled; + + case 'displayname': + var dDisplayname = xmlDoc.createElement('d:displayname'); + dDisplayname.textContent = value; + return dDisplayname; + + case 'order': + var aOrder = xmlDoc.createElement('a:calendar-color'); + aOrder.textContent = value; + return aOrder; + + case 'color': + var aColor = xmlDoc.createElement('a:calendar-color'); + aColor.textContent = value; + return aColor; + + case 'components': + var cComponents = xmlDoc.createElement('c:supported-calendar-component-set'); + for (var i=0; i < value.length; i++) { + var cComp = xmlDoc.createElement('c:comp'); + cComp.setAttribute('name', value[i].toUpperCase()); + cComponents.appendChild(cComp); + } + return cComponents; + } + }; + + this._getACLFromResponse = function(body) { + var canWrite = false; + var acl = body.propStat[0].properties['{' + DavClient.NS_DAV + '}acl']; + if (acl) { + for (var k=0; k < acl.length; k++) { + var href = acl[k].getElementsByTagNameNS('DAV:', 'href'); + if (href.length === 0) { + continue; + } + href = href[0].textContent; + if (href !== _this._currentUserPrincipal) { + continue; + } + var writeNode = acl[k].getElementsByTagNameNS('DAV:', 'write'); + if (writeNode.length > 0) { + canWrite = true; + } + } + } + body.propStat[0].properties.canWrite = canWrite; + }; + + this._isUriAlreadyTaken = function(uri) { + return (this._takenUrls.indexOf(this._CALENDAR_HOME + uri + '/') !== -1); + }; + + this._suggestUri = function(displayname) { + var uri = displayname.toString().toLowerCase() + .replace(/\s+/g, '-') // Replace spaces with - + .replace(/[^\w\-]+/g, '') // Remove all non-word chars + .replace(/\-\-+/g, '-') // Replace multiple - with single - + .replace(/^-+/, '') // Trim - from start of text + .replace(/-+$/, ''); // Trim - from end of text + + if (!this._isUriAlreadyTaken(uri)) { + return uri; + } + + if (uri.indexOf('-') === -1) { + uri = uri + '-1'; + if (!this._isUriAlreadyTaken(uri)) { + return uri; + } + } + + while (this._isUriAlreadyTaken(uri)) { + var positionLastDash = uri.lastIndexOf('-'); + var firstPart = uri.substr(0, positionLastDash); + var lastPart = uri.substr(positionLastDash + 1); + + if (lastPart.match(/^\d+$/)) { + lastPart = parseInt(lastPart); + lastPart++; + + uri = firstPart + '-' + lastPart; + } else if (lastPart === '') { + uri = uri + '1'; + } else { + uri = uri = '-1'; + } + } + + return uri; + }; + +}]); diff --git a/js/app/services/davclient.coffee b/js/app/services/davclient.coffee deleted file mode 100644 index 72251bc4..00000000 --- a/js/app/services/davclient.coffee +++ /dev/null @@ -1,52 +0,0 @@ -### -ownCloud - Tasks - -@author Raghu Nayyar -@author Georg Ehrke -@author Raimund Schlüßler -@copyright 2016 Raghu Nayyar <beingminimal@gmail.com> -@copyright 2016 Georg Ehrke <oc.list@georgehrke.com> -@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/>. - -### - -angular.module('Tasks').service 'DavClient', [ () -> - - client = new dav.Client - baseUrl: OC.linkToRemote('dav/calendars'), - xmlNamespaces: - 'DAV:': 'd' - 'urn:ietf:params:xml:ns:caldav': 'c' - 'http://apple.com/ns/ical/': 'aapl' - 'http://owncloud.org/ns': 'oc' - 'http://calendarserver.org/ns/': 'cs' - - angular.extend(client, - NS_DAV: 'DAV:' - NS_IETF: 'urn:ietf:params:xml:ns:caldav' - NS_APPLE: 'http://apple.com/ns/ical/' - NS_OWNCLOUD: 'http://owncloud.org/ns' - NS_CALENDARSERVER: 'http://calendarserver.org/ns/' - - buildUrl: (path) -> - return window.location.protocol + '//' + window.location.host + path - - wasRequestSuccessful: (status) -> - return (status >= 200 && status <= 299) - ) - - return client -] diff --git a/js/app/services/davclient.js b/js/app/services/davclient.js new file mode 100644 index 00000000..070e5984 --- /dev/null +++ b/js/app/services/davclient.js @@ -0,0 +1,57 @@ +/** + * ownCloud - Tasks + * + * @author Raghu Nayyar + * @author Georg Ehrke + * @author Raimund Schlüßler + * @copyright 2016 Raghu Nayyar <beingminimal@gmail.com> + * @copyright 2016 Georg Ehrke <oc.list@georgehrke.com> + * @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').service('DavClient', [ + function() { + var client; + client = new dav.Client({ + baseUrl: OC.linkToRemote('dav/calendars'), + xmlNamespaces: { + 'DAV:': 'd', + 'urn:ietf:params:xml:ns:caldav': 'c', + 'http://apple.com/ns/ical/': 'aapl', + 'http://owncloud.org/ns': 'oc', + 'http://calendarserver.org/ns/': 'cs' + } + }); + angular.extend(client, { + NS_DAV: 'DAV:', + NS_IETF: 'urn:ietf:params:xml:ns:caldav', + NS_APPLE: 'http://apple.com/ns/ical/', + NS_OWNCLOUD: 'http://owncloud.org/ns', + NS_CALENDARSERVER: 'http://calendarserver.org/ns/', + buildUrl: function(path) { + return window.location.protocol + '//' + window.location.host + path; + }, + wasRequestSuccessful: function(status) { + return status >= 200 && status <= 299; + } + }); + return client; + } + ]); + +}).call(this); diff --git a/js/app/services/loading.coffee b/js/app/services/loading.coffee deleted file mode 100644 index e40a15ac..00000000 --- a/js/app/services/loading.coffee +++ /dev/null @@ -1,44 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').factory 'Loading', -[ () -> - - class Loading - - constructor: () -> - @count = 0 - - increase: () -> - @count += 1 - - decrease: () -> - @count -= 1 - - getCount: () -> - return @count - - isLoading: () -> - return @count > 0 - - return new Loading() - -] diff --git a/js/app/services/loading.js b/js/app/services/loading.js new file mode 100644 index 00000000..19c86203 --- /dev/null +++ b/js/app/services/loading.js @@ -0,0 +1,54 @@ +/** + * 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').factory('Loading', [ + function() { + var Loading; + Loading = (function() { + function Loading() { + this.count = 0; + } + + Loading.prototype.increase = function() { + return this.count += 1; + }; + + Loading.prototype.decrease = function() { + return this.count -= 1; + }; + + Loading.prototype.getCount = function() { + return this.count; + }; + + Loading.prototype.isLoading = function() { + return this.count > 0; + }; + + return Loading; + + })(); + return new Loading(); + } + ]); + +}).call(this); diff --git a/js/app/services/model.coffee b/js/app/services/model.coffee deleted file mode 100644 index 29250334..00000000 --- a/js/app/services/model.coffee +++ /dev/null @@ -1,97 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').factory '_Model', -[() -> - - class Model - - constructor: () -> - @_data = [] - @_dataMap = {} - @_filterCache = {} - - handle: (data) -> - _results = [] - for item in data - _results.push(@add(item)) - return _results - - add: (data, clearCache=true) -> - if (clearCache) - @_invalidateCache() - - if (angular.isDefined(@_dataMap[data.id])) - return @update(data, clearCache) - else - @_data.push(data) - return @_dataMap[data.id] = data - - update: (data, clearCache=true) -> - if clearCache - @_invalidateCache() - - entry = @getById(data.id) - _results = [] - for key of data - value = data[key] - if (key == 'id') - continue - else - _results.push(entry[key] = value) - return _results - - getById: (id) -> - return @_dataMap[id] - - getAll: () -> - return @_data - - removeById: (id, clearCache=true) -> - for entry, counter in @_data - if entry.id == id - @_data.splice(counter, 1) - data = @_dataMap[id] - delete @_dataMap[id] - if clearCache - @_invalidateCache() - return data - - clear: () -> - @_data.length = 0 - @_dataMap = {} - return @_invalidateCache() - - _invalidateCache: () -> - return @_filterCache = {} - - get: (query) -> - hash = query.hashCode() - if (!angular.isDefined(@_filterCache[hash])) - @_filterCache[hash] = query.exec(@_data) - return @_filterCache[hash] - - size: () -> - return @_data.length - - return Model - -] diff --git a/js/app/services/model.js b/js/app/services/model.js new file mode 100644 index 00000000..1bc2b1cf --- /dev/null +++ b/js/app/services/model.js @@ -0,0 +1,137 @@ +/** + * 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').factory('_Model', [ + function() { + var Model; + Model = (function() { + function Model() { + this._data = []; + this._dataMap = {}; + this._filterCache = {}; + } + + Model.prototype.handle = function(data) { + var item, _i, _len, _results; + _results = []; + for (_i = 0, _len = data.length; _i < _len; _i++) { + item = data[_i]; + _results.push(this.add(item)); + } + return _results; + }; + + Model.prototype.add = function(data, clearCache) { + if (clearCache == null) { + clearCache = true; + } + if (clearCache) { + this._invalidateCache(); + } + if (angular.isDefined(this._dataMap[data.id])) { + return this.update(data, clearCache); + } else { + this._data.push(data); + return this._dataMap[data.id] = data; + } + }; + + Model.prototype.update = function(data, clearCache) { + var entry, key, value, _results; + if (clearCache == null) { + clearCache = true; + } + if (clearCache) { + this._invalidateCache(); + } + entry = this.getById(data.id); + _results = []; + for (key in data) { + value = data[key]; + if (key === 'id') { + continue; + } else { + _results.push(entry[key] = value); + } + } + return _results; + }; + + Model.prototype.getById = function(id) { + return this._dataMap[id]; + }; + + Model.prototype.getAll = function() { + return this._data; + }; + + Model.prototype.removeById = function(id, 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.id === id) { + this._data.splice(counter, 1); + data = this._dataMap[id]; + delete this._dataMap[id]; + if (clearCache) { + this._invalidateCache(); + } + return data; + } + } + }; + + Model.prototype.clear = function() { + this._data.length = 0; + this._dataMap = {}; + return this._invalidateCache(); + }; + + Model.prototype._invalidateCache = function() { + return this._filterCache = {}; + }; + + Model.prototype.get = function(query) { + var hash; + hash = query.hashCode(); + if (!angular.isDefined(this._filterCache[hash])) { + this._filterCache[hash] = query.exec(this._data); + } + return this._filterCache[hash]; + }; + + Model.prototype.size = function() { + return this._data.length; + }; + + return Model; + + })(); + return Model; + } + ]); + +}).call(this); diff --git a/js/app/services/models/calendar.js b/js/app/services/models/calendar.js new file mode 100644 index 00000000..f7124093 --- /dev/null +++ b/js/app/services/models/calendar.js @@ -0,0 +1,262 @@ +/** + * ownCloud - Tasks + * + * @author Raghu Nayyar + * @author Georg Ehrke + * @author Raimund Schlüßler + * @copyright 2016 Raghu Nayyar <beingminimal@gmail.com> + * @copyright 2016 Georg Ehrke <oc.list@georgehrke.com> + * @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/>. + * + */ + +angular.module('Tasks').factory('Calendar', ['$rootScope', '$filter', function($rootScope, $filter) { + 'use strict'; + + function Calendar(url, props, uri) { + var _this = this; + + angular.extend(this, { + _propertiesBackup: {}, + _properties: { + url: url, + uri: uri, + enabled: props['{http://owncloud.org/ns}calendar-enabled'] === '1', + displayname: props['{DAV:}displayname'] || t('tasks','Unnamed'), + color: props['{http://apple.com/ns/ical/}calendar-color'] || '#1d2d44', + order: parseInt(props['{http://apple.com/ns/ical/}calendar-order']) || 0, + components: { + vevent: false, + vjournal: false, + vtodo: false + }, + writable: props.canWrite, + shareable: props.canWrite, + sharedWith: { + users: [], + groups: [] + }, + owner: '' + }, + _updatedProperties: [] + }); + + angular.extend(this, { + tmpId: null, + fcEventSource: { + events: function (start, end, timezone, callback) { + // console.log('querying events ...'); + // TimezoneService.get(timezone).then(function(tz) { + // _this.list.loading = true; + // $rootScope.$broadcast('reloadCalendarList'); + + // VEventService.getAll(_this, start, end).then(function(events) { + // var vevents = []; + // for (var i = 0; i < events.length; i++) { + // vevents = vevents.concat(events[i].getFcEvent(start, end, tz)); + // } + + // callback(vevents); + + // _this.list.loading = false; + // $rootScope.$broadcast('reloadCalendarList'); + // }); + // }); + }, + editable: this._properties.writable, + calendar: this + }, + list: { + edit: false, + loading: this.enabled, + locked: false, + editingShares: false + } + }); + + var components = props['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']; + for (var i=0; i < components.length; i++) { + var name = components[i].attributes.getNamedItem('name').textContent.toLowerCase(); + if (this._properties.components.hasOwnProperty(name)) { + this._properties.components[name] = true; + } + } + + var shares = props['{http://owncloud.org/ns}invite']; + if (typeof shares !== 'undefined') { + for (var j=0; j < shares.length; j++) { + var href = shares[j].getElementsByTagNameNS('DAV:', 'href'); + if (href.length === 0) { + continue; + } + href = href[0].textContent; + + var access = shares[j].getElementsByTagNameNS('http://owncloud.org/ns', 'access'); + if (access.length === 0) { + continue; + } + access = access[0]; + + var readWrite = access.getElementsByTagNameNS('http://owncloud.org/ns', 'read-write'); + readWrite = readWrite.length !== 0; + + if (href.startsWith('principal:principals/users/')) { + this._properties.sharedWith.users.push({ + id: href.substr(27), + displayname: href.substr(27), + writable: readWrite + }); + } else if (href.startsWith('principal:principals/groups/')) { + this._properties.sharedWith.groups.push({ + id: href.substr(28), + displayname: href.substr(28), + writable: readWrite + }); + } + } + } + + var owner = props['{DAV:}owner']; + if (typeof owner !== 'undefined' && owner.length !== 0) { + owner = owner[0].textContent.slice(0, -1); + if (owner.startsWith('/remote.php/dav/principals/users/')) { + this._properties.owner = owner.substr(33); + } + } + + // this.tmpId = RandomStringService.generate(); + } + + Calendar.prototype = { + get url() { + return this._properties.url; + }, + get enabled() { + return this._properties.enabled; + }, + get uri() { + return this._properties.uri; + }, + get components() { + return this._properties.components; + }, + set enabled(enabled) { + this._properties.enabled = enabled; + this._setUpdated('enabled'); + }, + get displayname() { + return this._properties.displayname; + }, + set displayname(displayname) { + this._properties.displayname = displayname; + this._setUpdated('displayname'); + }, + get color() { + return this._properties.color; + }, + set color(color) { + this._properties.color = color; + this._setUpdated('color'); + }, + get sharedWith() { + return this._properties.sharedWith; + }, + set sharedWith(sharedWith) { + this._properties.sharedWith = sharedWith; + }, + get textColor() { + var color = this.color; + var fallbackColor = '#fff'; + var c; + switch (color.length) { + case 4: + c = color.match(/^#([0-9a-f]{3})$/i)[1]; + if (c) { + return this._generateTextColor( + parseInt(c.charAt(0),16)*0x11, + parseInt(c.charAt(1),16)*0x11, + parseInt(c.charAt(2),16)*0x11 + ); + } + return fallbackColor; + + case 7: + case 9: + var regex = new RegExp('^#([0-9a-f]{' + (color.length - 1) + '})$', 'i'); + c = color.match(regex)[1]; + if (c) { + return this._generateTextColor( + parseInt(c.substr(0,2),16), + parseInt(c.substr(2,2),16), + parseInt(c.substr(4,2),16) + ); + } + return fallbackColor; + + default: + return fallbackColor; + } + }, + get order() { + return this._properties.order; + }, + set order(order) { + this._properties.order = order; + this._setUpdated('order'); + }, + get writable() { + return this._properties.writable; + }, + get shareable() { + return this._properties.shareable; + }, + get owner() { + return this._properties.owner; + }, + _setUpdated: function(propName) { + if (this._updatedProperties.indexOf(propName) === -1) { + this._updatedProperties.push(propName); + } + }, + get updatedProperties() { + return this._updatedProperties; + }, + resetUpdatedProperties: function() { + this._updatedProperties = []; + }, + prepareUpdate: function() { + this.list.edit = true; + this._propertiesBackup = angular.copy(this._properties); + }, + resetToPreviousState: function() { + this._properties = angular.copy(this._propertiesBackup); + this.list.edit = false; + this._propertiesBackup = {}; + }, + dropPreviousState: function() { + this._propertiesBackup = {}; + }, + toggleSharesEditor: function() { + this.list.editingShares = !this.list.editingShares; + }, + _generateTextColor: function(r,g,b) { + var brightness = (((r * 299) + (g * 587) + (b * 114)) / 1000); + return (brightness > 130) ? '#000000' : '#FAFAFA'; + } + }; + + return Calendar; +}]); diff --git a/js/app/services/models/collectionsmodel.coffee b/js/app/services/models/collectionsmodel.coffee deleted file mode 100644 index c871160b..00000000 --- a/js/app/services/models/collectionsmodel.coffee +++ /dev/null @@ -1,47 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').factory 'CollectionsModel', -['TasksModel', '_Model', -(TasksModel, _Model) -> - class CollectionsModel extends _Model - - constructor: (@_$tasksmodel) -> - @_nameCache = {} - super() - - add: (data, clearCache=true) -> - @_nameCache[data.displayname] = data - if angular.isDefined(data.id) - super(data, clearCache) - - getCount: (collectionID, filter='') -> - count = 0 - tasks = @_$tasksmodel.filteredTasks(filter) - - for task in tasks - count += (@_$tasksmodel.filterTasks(task, collectionID) && - !task.related) - return count - - return new CollectionsModel(TasksModel) -] diff --git a/js/app/services/models/collectionsmodel.js b/js/app/services/models/collectionsmodel.js new file mode 100644 index 00000000..82345265 --- /dev/null +++ b/js/app/services/models/collectionsmodel.js @@ -0,0 +1,69 @@ +/** + * 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() { + 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; }; + + angular.module('Tasks').factory('CollectionsModel', [ + 'TasksModel', '_Model', function(TasksModel, _Model) { + var CollectionsModel; + CollectionsModel = (function(_super) { + __extends(CollectionsModel, _super); + + function CollectionsModel(_$tasksmodel) { + this._$tasksmodel = _$tasksmodel; + this._nameCache = {}; + CollectionsModel.__super__.constructor.call(this); + } + + CollectionsModel.prototype.add = function(data, clearCache) { + if (clearCache == null) { + clearCache = true; + } + this._nameCache[data.displayname] = data; + if (angular.isDefined(data.id)) { + return CollectionsModel.__super__.add.call(this, data, clearCache); + } + }; + + CollectionsModel.prototype.getCount = function(collectionID, filter) { + var count, task, tasks, _i, _len; + if (filter == null) { + filter = ''; + } + count = 0; + tasks = this._$tasksmodel.filteredTasks(filter); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + count += this._$tasksmodel.filterTasks(task, collectionID) && !task.related; + } + return count; + }; + + return CollectionsModel; + + })(_Model); + return new CollectionsModel(TasksModel); + } + ]); + +}).call(this); diff --git a/js/app/services/models/listsmodel.coffee b/js/app/services/models/listsmodel.coffee deleted file mode 100644 index f126b034..00000000 --- a/js/app/services/models/listsmodel.coffee +++ /dev/null @@ -1,203 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2016 - -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').factory 'ListsModel', -['TasksModel', '_Model', -(TasksModel, _Model) -> - class ListsModel extends _Model - - constructor: (@_$tasksmodel) -> - @_tmpUriCache = {} - @_data = [] - @_dataMap = {} - @_filterCache = {} - - insert: (cal) -> - calendar = - id: @size() - url: cal.url - enabled: cal.props['{http://owncloud.org/ns}calendar-enabled']=='1' - displayname: cal.props['{DAV:}displayname'] || 'Unnamed' - color: cal.props['{http://apple.com/ns/ical/}calendar-color'] || '#1d2d44' - order: parseInt( - cal.props['{http://apple.com/ns/ical/}calendar-order']) || 0 - components: - vevent: false - vjournal: false - vtodo: false - writable: cal.props.canWrite - shareable: cal.props.canWrite - sharedWith: - users: [] - groups: [] - owner: '' - - components = cal.props['{urn:ietf:params:xml:ns:caldav}'+ - 'supported-calendar-component-set'] - for component in components - name = component.attributes.getNamedItem('name').textContent.toLowerCase() - if (calendar.components.hasOwnProperty(name)) - calendar.components[name] = true - - - shares = cal.props['{http://owncloud.org/ns}invite'] - if (typeof shares != 'undefined') - for share in shares - href = share.getElementsByTagNameNS('DAV:', 'href') - if (href.length == 0) - continue - href = href[0].textContent - - access = share.getElementsByTagNameNS('http://owncloud.org/ns', 'access') - if (access.length == 0) - continue - access = access[0] - - readWrite = access - .getElementsByTagNameNS('http://owncloud.org/ns', 'read-write') - readWrite = readWrite.length != 0 - - if (href.startsWith('principal:principals/users/')) - this.sharedWith.users.push( - id: href.substr(27) - displayname: href.substr(27) - writable: readWrite - ) - else if (href.startsWith('principal:principals/groups/')) - this.sharedWith.groups.push( - id: href.substr(28) - displayname: href.substr(28) - writable: readWrite - ) - - owner = cal.props['{DAV:}owner'] - if (typeof owner != 'undefined' && owner.length != 0) - owner = owner[0].textContent.slice(0, -1) - if (owner.startsWith('/remote.php/dav/principals/users/')) - this.owner = owner.substr(33) - - @add(calendar) - return calendar - - add: (calendar, clearCache=true) -> - updateByUri = angular.isDefined(calendar.uri) and - angular.isDefined(@getByUri(calendar.uri)) - - if updateByUri - @update(calendar, clearCache) - else - if angular.isDefined(calendar.uri) - if (clearCache) - @_invalidateCache() - if (angular.isDefined(@_dataMap[calendar.uri])) - # return @update(data, clearCache) - else - @_data.push(calendar) - return @_dataMap[calendar.uri] = calendar - - getByUri: (uri) -> - return @_dataMap[uri] - - update: (list, clearCache=true) -> - tmplist = @_tmpIdCache[list.tmpID] - - if angular.isDefined(list.id) and - angular.isDefined(tmplist) and - angular.isUndefined(tmplist.id) - tmplist.id = list.id - @_dataMap[list.id] = tmplist - - list.void = false - super(list, clearCache) - - delete: (calendar, clearCache=true) -> - for entry, counter in @_data - if entry == calendar - @_data.splice(counter, 1) - data = @_dataMap[calendar.uri] - delete @_dataMap[calendar.uri] - if clearCache - @_invalidateCache() - return data - - voidAll: () -> - lists = @getAll() - for list in lists - list.void = true - - removeVoid: () -> - lists = @getAll() - listIDs = [] - for list in lists - if list.void - listIDs.push list.id - for id in listIDs - @removeById(id) - - getStandardList: () -> - if @size() - calendars = @getAll() - return calendars[0] - - checkName: (listName, listID=undefined) -> - lists = @getAll() - ret = true - for list in lists - if list.displayname == listName && - listID != list.id - ret = false - return ret - - getCount: (listID,collectionID,filter='') -> - count = 0 - tasks = @_$tasksmodel.filteredTasks(filter) - for task in tasks - count += (@_$tasksmodel.filterTasks(task, collectionID) && - task.calendarid == listID && - !task.related) - if (collectionID == 'completed' && filter == '') - count += @notLoaded(listID) - return count - - notLoaded: (listID) -> - if angular.isUndefined(@getById(listID)) - return 0 - else - return @getById(listID).notLoaded - - loadedAll: (listID) -> - return !@notLoaded(listID) - - getColor: (listID) -> - if angular.isUndefined(@getById(listID)) - return '#CCCCCC' - else - return @getById(listID).calendarcolor - - getName: (listID) -> - if angular.isUndefined(@getById(listID)) - return '' - else - return @getById(listID).displayname - - return new ListsModel(TasksModel) -] diff --git a/js/app/services/models/listsmodel.js b/js/app/services/models/listsmodel.js new file mode 100644 index 00000000..9ab7d650 --- /dev/null +++ b/js/app/services/models/listsmodel.js @@ -0,0 +1,278 @@ +/** + * 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() { + 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; }; + + angular.module('Tasks').factory('ListsModel', [ + 'TasksModel', '_Model', function(TasksModel, _Model) { + var ListsModel; + ListsModel = (function(_super) { + __extends(ListsModel, _super); + + function ListsModel(_$tasksmodel) { + this._$tasksmodel = _$tasksmodel; + this._tmpUriCache = {}; + this._data = []; + this._dataMap = {}; + this._filterCache = {}; + } + + ListsModel.prototype.insert = function(cal) { + var access, calendar, component, components, href, name, owner, readWrite, share, shares, _i, _j, _len, _len1; + calendar = { + id: this.size(), + url: cal.url, + enabled: cal.props['{http://owncloud.org/ns}calendar-enabled'] === '1', + displayname: cal.props['{DAV:}displayname'] || 'Unnamed', + color: cal.props['{http://apple.com/ns/ical/}calendar-color'] || '#1d2d44', + order: parseInt(cal.props['{http://apple.com/ns/ical/}calendar-order']) || 0, + components: { + vevent: false, + vjournal: false, + vtodo: false + }, + writable: cal.props.canWrite, + shareable: cal.props.canWrite, + sharedWith: { + users: [], + groups: [] + }, + owner: '' + }; + components = cal.props['{urn:ietf:params:xml:ns:caldav}' + 'supported-calendar-component-set']; + for (_i = 0, _len = components.length; _i < _len; _i++) { + component = components[_i]; + name = component.attributes.getNamedItem('name').textContent.toLowerCase(); + if (calendar.components.hasOwnProperty(name)) { + calendar.components[name] = true; + } + } + shares = cal.props['{http://owncloud.org/ns}invite']; + if (typeof shares !== 'undefined') { + for (_j = 0, _len1 = shares.length; _j < _len1; _j++) { + share = shares[_j]; + href = share.getElementsByTagNameNS('DAV:', 'href'); + if (href.length === 0) { + continue; + } + href = href[0].textContent; + access = share.getElementsByTagNameNS('http://owncloud.org/ns', 'access'); + if (access.length === 0) { + continue; + } + access = access[0]; + readWrite = access.getElementsByTagNameNS('http://owncloud.org/ns', 'read-write'); + readWrite = readWrite.length !== 0; + if (href.startsWith('principal:principals/users/')) { + this.sharedWith.users.push({ + id: href.substr(27), + displayname: href.substr(27), + writable: readWrite + }); + } else if (href.startsWith('principal:principals/groups/')) { + this.sharedWith.groups.push({ + id: href.substr(28), + displayname: href.substr(28), + writable: readWrite + }); + } + } + } + owner = cal.props['{DAV:}owner']; + if (typeof owner !== 'undefined' && owner.length !== 0) { + owner = owner[0].textContent.slice(0, -1); + if (owner.startsWith('/remote.php/dav/principals/users/')) { + this.owner = owner.substr(33); + } + } + this.add(calendar); + return calendar; + }; + + ListsModel.prototype.add = function(calendar, clearCache) { + var updateByUri; + if (clearCache == null) { + clearCache = true; + } + updateByUri = angular.isDefined(calendar.uri) && angular.isDefined(this.getByUri(calendar.uri)); + if (updateByUri) { + return this.update(calendar, clearCache); + } else { + if (angular.isDefined(calendar.uri)) { + if (clearCache) { + this._invalidateCache(); + } + if (angular.isDefined(this._dataMap[calendar.uri])) { + + } else { + this._data.push(calendar); + return this._dataMap[calendar.uri] = calendar; + } + } + } + }; + + ListsModel.prototype.getByUri = function(uri) { + return this._dataMap[uri]; + }; + + ListsModel.prototype.update = function(list, clearCache) { + var tmplist; + if (clearCache == null) { + clearCache = true; + } + tmplist = this._tmpIdCache[list.tmpID]; + if (angular.isDefined(list.id) && angular.isDefined(tmplist) && angular.isUndefined(tmplist.id)) { + tmplist.id = list.id; + this._dataMap[list.id] = tmplist; + } + list["void"] = false; + return ListsModel.__super__.update.call(this, list, clearCache); + }; + + ListsModel.prototype["delete"] = function(calendar, 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 === calendar) { + this._data.splice(counter, 1); + data = this._dataMap[calendar.uri]; + delete this._dataMap[calendar.uri]; + if (clearCache) { + this._invalidateCache(); + } + return data; + } + } + }; + + ListsModel.prototype.voidAll = function() { + var list, lists, _i, _len, _results; + lists = this.getAll(); + _results = []; + for (_i = 0, _len = lists.length; _i < _len; _i++) { + list = lists[_i]; + _results.push(list["void"] = true); + } + return _results; + }; + + ListsModel.prototype.removeVoid = function() { + var id, list, listIDs, lists, _i, _j, _len, _len1, _results; + lists = this.getAll(); + listIDs = []; + for (_i = 0, _len = lists.length; _i < _len; _i++) { + list = lists[_i]; + if (list["void"]) { + listIDs.push(list.id); + } + } + _results = []; + for (_j = 0, _len1 = listIDs.length; _j < _len1; _j++) { + id = listIDs[_j]; + _results.push(this.removeById(id)); + } + return _results; + }; + + ListsModel.prototype.getStandardList = function() { + var calendars; + if (this.size()) { + calendars = this.getAll(); + return calendars[0]; + } + }; + + ListsModel.prototype.checkName = function(listName, listID) { + var list, lists, ret, _i, _len; + if (listID == null) { + listID = void 0; + } + lists = this.getAll(); + ret = true; + for (_i = 0, _len = lists.length; _i < _len; _i++) { + list = lists[_i]; + if (list.displayname === listName && listID !== list.id) { + ret = false; + } + } + return ret; + }; + + ListsModel.prototype.getCount = function(listID, collectionID, filter) { + var count, task, tasks, _i, _len; + if (filter == null) { + filter = ''; + } + count = 0; + tasks = this._$tasksmodel.filteredTasks(filter); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + count += this._$tasksmodel.filterTasks(task, collectionID) && task.calendarid === listID && !task.related; + } + if (collectionID === 'completed' && filter === '') { + count += this.notLoaded(listID); + } + return count; + }; + + ListsModel.prototype.notLoaded = function(listID) { + if (angular.isUndefined(this.getById(listID))) { + return 0; + } else { + return this.getById(listID).notLoaded; + } + }; + + ListsModel.prototype.loadedAll = function(listID) { + return !this.notLoaded(listID); + }; + + ListsModel.prototype.getColor = function(listID) { + if (angular.isUndefined(this.getById(listID))) { + return '#CCCCCC'; + } else { + return this.getById(listID).calendarcolor; + } + }; + + ListsModel.prototype.getName = function(listID) { + if (angular.isUndefined(this.getById(listID))) { + return ''; + } else { + return this.getById(listID).displayname; + } + }; + + return ListsModel; + + })(_Model); + return new ListsModel(TasksModel); + } + ]); + +}).call(this); diff --git a/js/app/services/models/settingsmodel.coffee b/js/app/services/models/settingsmodel.coffee deleted file mode 100644 index ad2ff9b9..00000000 --- a/js/app/services/models/settingsmodel.coffee +++ /dev/null @@ -1,44 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').factory 'SettingsModel', -['_Model', -(_Model) -> - class SettingsModel extends _Model - - constructor: () -> - @_nameCache = {} - super() - - add: (data, clearCache=true) -> - @_nameCache[data.displayname] = data - if angular.isDefined(data.id) - super(data, clearCache) - else - @_data.push(data) - - toggle: (type, setting) -> - set = @getById(type) - @getById(type)[setting] = !set[setting] - - return new SettingsModel() -]
\ No newline at end of file diff --git a/js/app/services/models/settingsmodel.js b/js/app/services/models/settingsmodel.js new file mode 100644 index 00000000..c9a426cd --- /dev/null +++ b/js/app/services/models/settingsmodel.js @@ -0,0 +1,62 @@ +/** + * 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() { + 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; }; + + angular.module('Tasks').factory('SettingsModel', [ + '_Model', function(_Model) { + var SettingsModel; + SettingsModel = (function(_super) { + __extends(SettingsModel, _super); + + function SettingsModel() { + this._nameCache = {}; + SettingsModel.__super__.constructor.call(this); + } + + SettingsModel.prototype.add = function(data, clearCache) { + if (clearCache == null) { + clearCache = true; + } + this._nameCache[data.displayname] = data; + if (angular.isDefined(data.id)) { + return SettingsModel.__super__.add.call(this, data, clearCache); + } else { + return this._data.push(data); + } + }; + + SettingsModel.prototype.toggle = function(type, setting) { + var set; + set = this.getById(type); + return this.getById(type)[setting] = !set[setting]; + }; + + return SettingsModel; + + })(_Model); + return new SettingsModel(); + } + ]); + +}).call(this); diff --git a/js/app/services/models/tasksmodel.coffee b/js/app/services/models/tasksmodel.coffee deleted file mode 100644 index 1d2b2e6e..00000000 --- a/js/app/services/models/tasksmodel.coffee +++ /dev/null @@ -1,336 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').factory 'TasksModel', -['_Model', -(_Model) -> - class TasksModel extends _Model - - constructor: () -> - @_tmpIdCache = {} - super() - - add: (task, clearCache=true) -> - - tmptask = @_tmpIdCache[task.tmpID] - - updateById = angular.isDefined(task.id) and - angular.isDefined(@getById(task.id)) - - updateByTmpId = angular.isDefined(tmptask) - - if updateById or updateByTmpId - @update(task, clearCache) - else - if angular.isDefined(task.id) and - angular.isUndefined(task.tmpID) - super(task, clearCache) - else - @_tmpIdCache[task.tmpID] = task - @_data.push(task) - if clearCache - @_invalidateCache() - - update: (task, clearCache=true) -> - tmptask = @_tmpIdCache[task.tmpID] - - if angular.isDefined(task.id) and - angular.isDefined(tmptask) - tmptask.id = task.id - @_dataMap[task.id] = tmptask - - task.void = false - super(task, clearCache) - - removeById: (taskID) -> - super(taskID) - - voidAll: () -> - tasks = @getAll() - for task in tasks - task.void = true - - removeVoid: () -> - tasks = @getAll() - taskIDs = [] - for task in tasks - if task.void - taskIDs.push task.id - for id in taskIDs - @removeById(id) - - removeByList: (listID) -> - tasks = @getAll() - taskIDs = [] - for task in tasks - if task.calendarid == listID - taskIDs.push task.id - for id in taskIDs - @removeById(id) - - taskAtDay: (task, date) -> - 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 - - isLoaded: (task) -> - return if @getById(task.id) then true else false - - hasSubtasks: (uid) -> - tasks = @getAll() - for task in tasks - if task.related == uid - return true - return false - - hasNoParent: (task) -> - if !task.related - return true - else - tasks = @getAll() - for t in tasks - if task.related == t.uid - return false - return true - - # TODO: store UID by ID in tasksmodel to speed things up - getIdByUid: (uid) -> - tasks = @getAll() - for task in tasks - if task.uid == uid - return task.id - return false - - getChildrenID: (taskID) -> - task = @getById(taskID) - tasks = @getAll() - childrenID = [] - for t in tasks - if t.related == task.uid - childrenID.push t.id - return childrenID - - getDescendantID: (taskID) -> - childrenID = @getChildrenID(taskID) - descendantID = [] - descendantID = descendantID.concat childrenID - for childID in childrenID - descendantID = descendantID.concat @getDescendantID(childID) - return descendantID - - filterTasks: (task, filter) -> - switch filter - when 'completed' - return task.completed == true - when 'all' - return task.completed == false - when 'current' - return (task.completed == false && @current(task.start, task.due)) - when 'starred' - return (task.completed == false && task.starred == true) - when 'today' - return (task.completed == false && (@today(task.start) || - @today(task.due))) - when 'week' - return (task.completed == false && (@week(task.start) || - @week(task.due))) - else - return ''+task.calendarid == ''+filter - - filteredTasks: (needle) -> - ret = [] - tasks = @getAll() - if !needle - ret = tasks - else - for task in tasks - if @filterTasksByString(task, needle) - if (@objectExists(task,ret)) - continue - ret.push(task) - parentID = @getIdByUid(task.related) - ancestors = @getAncestor(parentID, ret) - if ancestors - ret = ret.concat(ancestors) - return ret - - objectExists: (task, ret) -> - for re in ret - if re.id == task.id - return true - return false - - getAncestor: (taskID, ret) -> - tasks = [] - task = @getById(taskID) - if task - if (@objectExists(task,ret)) - return tasks - tasks.push(task) - if (@hasNoParent(task)) - return tasks - parentID = @getIdByUid(task.related) - ancestors = @getAncestor(parentID, ret) - if ancestors - tasks = tasks.concat(ancestors) - return tasks - - filterTasksByString: (task, filter) -> - keys = ['name', 'note', 'location', - 'categories', 'comments'] - filter = filter.toLowerCase() - for key,value of task - if key in keys - if key == 'comments' - for comment in task.comments - if comment.comment.toLowerCase().indexOf(filter) !=-1 - return true - else if key == 'categories' - for category in task.categories - if category.toLowerCase().indexOf(filter) !=-1 - return true - else if value.toLowerCase().indexOf(filter) !=-1 - return true - return false - - hideSubtasks: (taskID) -> - return @getById(taskID).hidesubtasks - - setHideSubtasks: (taskID,hide) -> - @update({id:taskID,hidesubtasks:hide}) - - starred: (taskID) -> - return @getById(taskID).starred - - star: (taskID) -> - @update({id:taskID,starred:true}) - - unstar: (taskID) -> - @update({id:taskID,starred:false}) - - setPriority: (taskID, priority) -> - @update({id:taskID,priority:priority}) - - completed: (taskID) -> - return @getById(taskID).completed - - complete: (taskID) -> - @update({id:taskID,completed:true, - completed_date:moment().format("YYYYMMDDTHHmmss")}) - - uncomplete: (taskID) -> - @update({id:taskID,completed:false, - completed_date:null}) - - setPercentComplete: (taskID, complete) -> - @update({id:taskID,complete:complete}) - - setDueDate: (taskID,date) -> - @update({id:taskID,due:date}) - - setReminder: (taskID,reminder) -> - @update({id:taskID,reminder:reminder}) - - setStartDate: (taskID,date) -> - @update({id:taskID,start:date}) - - overdue: (due) -> - return (moment(due, "YYYYMMDDTHHmmss").isValid() && - moment(due, "YYYYMMDDTHHmmss"). - diff(moment()) < 0) - - due: (due) -> - return moment(due, 'YYYYMMDDTHHmmss').isValid() - - today: (due) -> - return (moment(due, "YYYYMMDDTHHmmss").isValid() && - moment(due, "YYYYMMDDTHHmmss"). - diff(moment().startOf('day'), 'days', true) < 1) - - week: (due) -> - return (moment(due, "YYYYMMDDTHHmmss").isValid() && - moment(due, "YYYYMMDDTHHmmss"). - diff(moment().startOf('day'), 'days', true) < 7) - - current: (start, due) -> - return (!moment(start, "YYYYMMDDTHHmmss").isValid() || - moment(start, "YYYYMMDDTHHmmss"). - diff(moment(), 'days', true) < 0 || - moment(due, "YYYYMMDDTHHmmss"). - diff(moment(), 'days', true) < 0) - - changeCalendarId: (taskID, calendarID) -> - @update({id:taskID,calendarid:calendarID}) - - changeParent: (taskID, related) -> - @update({id:taskID,related:related}) - - setNote: (taskID, note) -> - @update({id:taskID,note:note}) - - addComment: (comment) -> - task = @getById(comment.taskID) - if task.comments - task.comments.push(comment) - else - task.comments = [comment] - - updateComment: (comment) -> - task = @getById(comment.taskID) - i = 0 - for com in task.comments - if com.tmpID == comment.tmpID - task.comments[i] = comment - break - i++ - - deleteComment: (taskID, commentID) -> - task = @getById(taskID) - i = 0 - for comment in task.comments - if comment.id == commentID - task.comments.splice(i,1) - break - i++ - - return new TasksModel() -] diff --git a/js/app/services/models/tasksmodel.js b/js/app/services/models/tasksmodel.js new file mode 100644 index 00000000..4d54001c --- /dev/null +++ b/js/app/services/models/tasksmodel.js @@ -0,0 +1,517 @@ +/** + * 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() { + 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; + TasksModel = (function(_super) { + __extends(TasksModel, _super); + + function TasksModel() { + this._tmpIdCache = {}; + TasksModel.__super__.constructor.call(this); + } + + TasksModel.prototype.add = function(task, clearCache) { + var tmptask, updateById, updateByTmpId; + if (clearCache == null) { + clearCache = true; + } + tmptask = this._tmpIdCache[task.tmpID]; + updateById = angular.isDefined(task.id) && angular.isDefined(this.getById(task.id)); + updateByTmpId = angular.isDefined(tmptask); + if (updateById || updateByTmpId) { + return this.update(task, clearCache); + } else { + if (angular.isDefined(task.id) && angular.isUndefined(task.tmpID)) { + return TasksModel.__super__.add.call(this, task, clearCache); + } else { + this._tmpIdCache[task.tmpID] = task; + this._data.push(task); + if (clearCache) { + return this._invalidateCache(); + } + } + } + }; + + TasksModel.prototype.update = function(task, clearCache) { + var tmptask; + if (clearCache == null) { + clearCache = true; + } + tmptask = this._tmpIdCache[task.tmpID]; + if (angular.isDefined(task.id) && angular.isDefined(tmptask)) { + tmptask.id = task.id; + this._dataMap[task.id] = tmptask; + } + task["void"] = false; + return TasksModel.__super__.update.call(this, task, clearCache); + }; + + TasksModel.prototype.removeById = function(taskID) { + return TasksModel.__super__.removeById.call(this, taskID); + }; + + TasksModel.prototype.voidAll = function() { + var task, tasks, _i, _len, _results; + tasks = this.getAll(); + _results = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + _results.push(task["void"] = true); + } + return _results; + }; + + TasksModel.prototype.removeVoid = function() { + var id, task, taskIDs, tasks, _i, _j, _len, _len1, _results; + tasks = this.getAll(); + taskIDs = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task["void"]) { + taskIDs.push(task.id); + } + } + _results = []; + for (_j = 0, _len1 = taskIDs.length; _j < _len1; _j++) { + id = taskIDs[_j]; + _results.push(this.removeById(id)); + } + return _results; + }; + + TasksModel.prototype.removeByList = function(listID) { + var id, task, taskIDs, tasks, _i, _j, _len, _len1, _results; + tasks = this.getAll(); + taskIDs = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.calendarid === listID) { + taskIDs.push(task.id); + } + } + _results = []; + for (_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.getById(task.id)) { + return true; + } else { + return false; + } + }; + + TasksModel.prototype.hasSubtasks = function(uid) { + var task, tasks, _i, _len; + tasks = this.getAll(); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.related === uid) { + return true; + } + } + return false; + }; + + TasksModel.prototype.hasNoParent = function(task) { + var t, tasks, _i, _len; + if (!task.related) { + return true; + } else { + tasks = this.getAll(); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + t = tasks[_i]; + if (task.related === t.uid) { + return false; + } + } + return true; + } + }; + + TasksModel.prototype.getIdByUid = function(uid) { + var task, tasks, _i, _len; + tasks = this.getAll(); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.uid === uid) { + return task.id; + } + } + return false; + }; + + TasksModel.prototype.getChildrenID = function(taskID) { + var childrenID, t, task, tasks, _i, _len; + task = this.getById(taskID); + tasks = this.getAll(); + childrenID = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + t = tasks[_i]; + if (t.related === task.uid) { + childrenID.push(t.id); + } + } + return childrenID; + }; + + TasksModel.prototype.getDescendantID = function(taskID) { + var childID, childrenID, descendantID, _i, _len; + childrenID = this.getChildrenID(taskID); + descendantID = []; + descendantID = descendantID.concat(childrenID); + for (_i = 0, _len = childrenID.length; _i < _len; _i++) { + childID = childrenID[_i]; + descendantID = descendantID.concat(this.getDescendantID(childID)); + } + return descendantID; + }; + + 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.starred === true; + 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.calendarid === '' + filter; + } + }; + + TasksModel.prototype.filteredTasks = function(needle) { + var ancestors, parentID, ret, task, tasks, _i, _len; + ret = []; + tasks = this.getAll(); + if (!needle) { + ret = tasks; + } else { + for (_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.getIdByUid(task.related); + ancestors = this.getAncestor(parentID, ret); + if (ancestors) { + ret = ret.concat(ancestors); + } + } + } + } + return ret; + }; + + TasksModel.prototype.objectExists = function(task, ret) { + var re, _i, _len; + for (_i = 0, _len = ret.length; _i < _len; _i++) { + re = ret[_i]; + if (re.id === task.id) { + return true; + } + } + return false; + }; + + TasksModel.prototype.getAncestor = function(taskID, ret) { + var ancestors, parentID, task, tasks; + tasks = []; + task = this.getById(taskID); + if (task) { + if (this.objectExists(task, ret)) { + return tasks; + } + tasks.push(task); + if (this.hasNoParent(task)) { + return tasks; + } + parentID = this.getIdByUid(task.related); + ancestors = this.getAncestor(parentID, ret); + if (ancestors) { + tasks = tasks.concat(ancestors); + } + } + return tasks; + }; + + TasksModel.prototype.filterTasksByString = function(task, filter) { + var category, comment, key, keys, value, _i, _j, _len, _len1, _ref, _ref1; + keys = ['name', 'note', 'location', 'categories', 'comments']; + filter = filter.toLowerCase(); + for (key in task) { + value = task[key]; + if (__indexOf.call(keys, key) >= 0) { + if (key === 'comments') { + _ref = task.comments; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + comment = _ref[_i]; + if (comment.comment.toLowerCase().indexOf(filter) !== -1) { + return true; + } + } + } else if (key === 'categories') { + _ref1 = task.categories; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + category = _ref1[_j]; + if (category.toLowerCase().indexOf(filter) !== -1) { + return true; + } + } + } else if (value.toLowerCase().indexOf(filter) !== -1) { + return true; + } + } + } + return false; + }; + + TasksModel.prototype.hideSubtasks = function(taskID) { + return this.getById(taskID).hidesubtasks; + }; + + TasksModel.prototype.setHideSubtasks = function(taskID, hide) { + return this.update({ + id: taskID, + hidesubtasks: hide + }); + }; + + TasksModel.prototype.starred = function(taskID) { + return this.getById(taskID).starred; + }; + + TasksModel.prototype.star = function(taskID) { + return this.update({ + id: taskID, + starred: true + }); + }; + + TasksModel.prototype.unstar = function(taskID) { + return this.update({ + id: taskID, + starred: false + }); + }; + + TasksModel.prototype.setPriority = function(taskID, priority) { + return this.update({ + id: taskID, + priority: priority + }); + }; + + TasksModel.prototype.completed = function(taskID) { + return this.getById(taskID).completed; + }; + + TasksModel.prototype.complete = function(taskID) { + return this.update({ + id: taskID, + completed: true, + completed_date: moment().format("YYYYMMDDTHHmmss") + }); + }; + + TasksModel.prototype.uncomplete = function(taskID) { + return this.update({ + id: taskID, + completed: false, + completed_date: null + }); + }; + + TasksModel.prototype.setPercentComplete = function(taskID, complete) { + return this.update({ + id: taskID, + complete: complete + }); + }; + + TasksModel.prototype.setDueDate = function(taskID, date) { + return this.update({ + id: taskID, + due: date + }); + }; + + TasksModel.prototype.setReminder = function(taskID, reminder) { + return this.update({ + id: taskID, + reminder: reminder + }); + }; + + TasksModel.prototype.setStartDate = function(taskID, date) { + return this.update({ + id: taskID, + start: date + }); + }; + + 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; + }; + + TasksModel.prototype.changeCalendarId = function(taskID, calendarID) { + return this.update({ + id: taskID, + calendarid: calendarID + }); + }; + + TasksModel.prototype.changeParent = function(taskID, related) { + return this.update({ + id: taskID, + related: related + }); + }; + + TasksModel.prototype.setNote = function(taskID, note) { + return this.update({ + id: taskID, + note: note + }); + }; + + TasksModel.prototype.addComment = function(comment) { + var task; + task = this.getById(comment.taskID); + if (task.comments) { + return task.comments.push(comment); + } else { + return task.comments = [comment]; + } + }; + + TasksModel.prototype.updateComment = function(comment) { + var com, i, task, _i, _len, _ref, _results; + task = this.getById(comment.taskID); + i = 0; + _ref = task.comments; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + com = _ref[_i]; + if (com.tmpID === comment.tmpID) { + task.comments[i] = comment; + break; + } + _results.push(i++); + } + return _results; + }; + + TasksModel.prototype.deleteComment = function(taskID, commentID) { + var comment, i, task, _i, _len, _ref, _results; + task = this.getById(taskID); + i = 0; + _ref = task.comments; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + comment = _ref[_i]; + if (comment.id === commentID) { + task.comments.splice(i, 1); + break; + } + _results.push(i++); + } + return _results; + }; + + return TasksModel; + + })(_Model); + return new TasksModel(); + } + ]); + +}).call(this); diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee deleted file mode 100644 index 7afab1e1..00000000 --- a/js/app/services/persistence.coffee +++ /dev/null @@ -1,393 +0,0 @@ -### - -ownCloud - News - -@author Bernhard Posselt -@copyright 2012 Bernhard Posselt nukeawhale@gmail.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/>. - -### - -angular.module('Tasks').factory 'Persistence', -['Request', 'Loading', '$rootScope', '$q', 'CalendarService' -(Request, Loading, $rootScope, $q, CalendarService) -> - - class Persistence - - constructor: (@_request, @_Loading, @_$rootScope, @_CalendarService) -> - - init: -> - @deferred = $q.defer() - - successCallback = => - @deferred.resolve() - - @getCollections() - @getSettings() - # @getLists() - # @_CalendarService.getAll() - # @getTasks('init', 'all', successCallback) - @deferred.promise - - getCollections: (onSuccess, showLoading=true) -> - onSuccess or= -> - - if showLoading - @_Loading.increase() - successCallbackWrapper = (data) => - onSuccess() - @_Loading.decrease() - failureCallbackWrapper = (data) => - @_Loading.decrease() - else - successCallbackWrapper = (data) => - onSuccess() - failureCallbackWrapper = (data) => - - params = - onSuccess: successCallbackWrapper - onFailure: failureCallbackWrapper - - @_request.get '/apps/tasks/collections', params - - getSettings: (onSuccess, showLoading=true) -> - onSuccess or= -> - - if showLoading - @_Loading.increase() - successCallbackWrapper = (data) => - onSuccess() - @_Loading.decrease() - failureCallbackWrapper = (data) => - @_Loading.decrease() - else - successCallbackWrapper = (data) => - onSuccess() - failureCallbackWrapper = (data) => - - params = - onSuccess: successCallbackWrapper - onFailure: failureCallbackWrapper - - @_request.get '/apps/tasks/settings', params - - setVisibility: (collectionID, visibility) -> - params = - routeParams: - collectionID: collectionID - visibility: visibility - - @_request.post '/apps/tasks/collection/ - {collectionID}/visibility/{visibility}', params - - setting: (type, setting, value) -> - params = - routeParams: - type: type - setting: setting - value: +value - - @_request.post '/apps/tasks/settings/ - {type}/{setting}/{value}', params - - - - getLists: (onSuccess, showLoading=true, which='all') -> - onSuccess or= -> - - if showLoading - @_Loading.increase() - successCallbackWrapper = (data) => - onSuccess() - @_Loading.decrease() - failureCallbackWrapper = (data) => - @_Loading.decrease() - else - successCallbackWrapper = (data) => - onSuccess() - failureCallbackWrapper = (data) => - - params = - onSuccess: successCallbackWrapper - onFailure: failureCallbackWrapper - routeParams: - request: which - - @_request.get '/apps/tasks/lists', params - - addList: (list, onSuccess=null, onFailure=null) -> - onSuccess or= -> - onFailure or= -> - params = - data: - name: list.displayname - tmpID: list.tmpID - onSuccess: onSuccess - onFailure: onFailure - - @_request.post '/apps/tasks/lists/add', params - - setListName: (list) -> - params = - routeParams: - listID: list.id - data: - name: list.displayname - - @_request.post '/apps/tasks/lists/{listID}/name', params - - deleteList: (listID) -> - params = - routeParams: - listID: listID - - @_request.post '/apps/tasks/lists/{listID}/delete', params - - getTasks: (type='init', listID='all', onSuccess, showLoading=true) -> - onSuccess or= -> - - if showLoading - @_Loading.increase() - successCallbackWrapper = (data) => - onSuccess() - @_Loading.decrease() - failureCallbackWrapper = (data) => - @_Loading.decrease() - else - successCallbackWrapper = (data) => - onSuccess() - failureCallbackWrapper = (data) => - - params = - onSuccess: successCallbackWrapper - onFailure: failureCallbackWrapper - routeParams: - listID: listID - type: type - - @_request.get '/apps/tasks/tasks/{type}/{listID}', params - - getTask: (taskID, onSuccess, showLoading=true) -> - onSuccess or= -> - - if showLoading - @_Loading.increase() - successCallbackWrapper = () => - onSuccess() - @_Loading.decrease() - failureCallbackWrapper = () => - @_Loading.decrease() - else - successCallbackWrapper = () => - onSuccess() - failureCallbackWrapper = () => - params = - onSuccess: successCallbackWrapper - onFailure: failureCallbackWrapper - routeParams: - taskID: taskID - - @_request.get '/apps/tasks/task/{taskID}', params - - setPercentComplete: (taskID, complete) -> - params = - routeParams: - taskID: taskID - data: - complete: complete - - @_request.post '/apps/tasks/tasks/{taskID}/percentcomplete', params - - setPriority: (taskID, priority) -> - params = - routeParams: - taskID: taskID - data: - priority: priority - - @_request.post '/apps/tasks/tasks/{taskID}/priority', params - - setHideSubtasks: (taskID, hide) -> - params = - routeParams: - taskID: taskID - data: - hide: hide - - @_request.post '/apps/tasks/tasks/{taskID}/hidesubtasks', params - - addTask: (task, onSuccess=null, onFailure=null) -> - onSuccess or= -> - onFailure or= -> - params = - data: - name: task.name - related: task.related - calendarID: task.calendarid - starred: task.starred - due: task.due - start: task.start - tmpID: task.tmpID - onSuccess: onSuccess - onFailure: onFailure - - @_request.post '/apps/tasks/tasks/add', params - - deleteTask: (taskID) -> - params = - routeParams: - taskID: taskID - - @_request.post '/apps/tasks/tasks/{taskID}/delete', params - - setDueDate: (taskID, due) -> - params = - routeParams: - taskID: taskID - data: - due: due - - @_request.post '/apps/tasks/tasks/{taskID}/due', params - - setStartDate: (taskID, start) -> - params = - routeParams: - taskID: taskID - data: - start: start - - @_request.post '/apps/tasks/tasks/{taskID}/start', params - - setReminder: (taskID, reminder) -> - if reminder == false - params = - routeParams: - taskID: taskID - data: - type: false - else if reminder.type == 'DATE-TIME' - params = - routeParams: - taskID: taskID - data: - type: reminder.type - action: reminder.action - date: moment(reminder.date, 'YYYYMMDDTHHmmss').unix() - else if reminder.type == 'DURATION' - params = - routeParams: - taskID: taskID - data: - type: reminder.type - action: reminder.action - week: reminder.duration.week - day: reminder.duration.day - hour: reminder.duration.hour - minute: reminder.duration.minute - second: reminder.duration.second - invert: reminder.duration.params.invert - related: reminder.duration.params.related - - else return - - @_request.post '/apps/tasks/tasks/{taskID}/reminder', params - - changeCalendarId: (taskID, calendarID) -> - params = - routeParams: - taskID: taskID - data: - calendarID: calendarID - - @_request.post '/apps/tasks/tasks/{taskID}/calendar', params - - changeParent: (taskID, related) -> - params = - routeParams: - taskID: taskID - data: - related: related - - @_request.post '/apps/tasks/tasks/{taskID}/parent', params - - setTaskName: (taskID, name) -> - params = - routeParams: - taskID: taskID - data: - name: name - - @_request.post '/apps/tasks/tasks/{taskID}/name', params - - setTaskNote: (taskID, note) -> - params = - routeParams: - taskID: taskID - data: - note: note - - @_request.post '/apps/tasks/tasks/{taskID}/note', params - - setShowHidden: (showHidden) -> - params = - routeParams: - showHidden: +showHidden - - @_request.post '/apps/tasks/settings/showhidden/{showHidden}', - params - - addComment: (comment, onSuccess=null, onFailure=null) -> - params = - routeParams: - taskID: comment.taskID - data: - comment: comment.comment - tmpID: comment.tmpID - onSuccess: onSuccess - onFailure: onFailure - - @_request.post '/apps/tasks/tasks/{taskID}/comment', - params - - deleteComment: (taskID, commentID) -> - params = - routeParams: - taskID: taskID - commentID: commentID - - @_request.post '/apps/tasks/tasks/{taskID}/comment/ - {commentID}/delete', params - - addCategory: (taskID, category) -> - params = - routeParams: - taskID: taskID - data: - category: category - - @_request.post '/apps/tasks/tasks/{taskID}/category/add', params - - removeCategory: (taskID, category) -> - params = - routeParams: - taskID: taskID - data: - category: category - - @_request.post '/apps/tasks/tasks/{taskID}/category/remove', params - - return new Persistence(Request, Loading, $rootScope, CalendarService) - -] diff --git a/js/app/services/persistence.js b/js/app/services/persistence.js new file mode 100644 index 00000000..d702ef73 --- /dev/null +++ b/js/app/services/persistence.js @@ -0,0 +1,554 @@ +/** + * 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').factory('Persistence', [ + 'Request', 'Loading', '$rootScope', '$q', 'CalendarService', function(Request, Loading, $rootScope, $q, CalendarService) { + var Persistence; + Persistence = (function() { + function Persistence(_request, _Loading, _$rootScope, _CalendarService) { + this._request = _request; + this._Loading = _Loading; + this._$rootScope = _$rootScope; + this._CalendarService = _CalendarService; + } + + Persistence.prototype.init = function() { + var successCallback, + _this = this; + this.deferred = $q.defer(); + successCallback = function() { + return _this.deferred.resolve(); + }; + this.getCollections(); + this.getSettings(); + return this.deferred.promise; + }; + + Persistence.prototype.getCollections = function(onSuccess, showLoading) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (showLoading == null) { + showLoading = true; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function(data) { + return onSuccess(); + }; + failureCallbackWrapper = function(data) {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('/apps/tasks/collections', params); + }; + + Persistence.prototype.getSettings = function(onSuccess, showLoading) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (showLoading == null) { + showLoading = true; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function(data) { + return onSuccess(); + }; + failureCallbackWrapper = function(data) {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('/apps/tasks/settings', params); + }; + + Persistence.prototype.setVisibility = function(collectionID, visibility) { + var params; + params = { + routeParams: { + collectionID: collectionID, + visibility: visibility + } + }; + return this._request.post('/apps/tasks/collection/\ + {collectionID}/visibility/{visibility}', params); + }; + + Persistence.prototype.setting = function(type, setting, value) { + var params; + params = { + routeParams: { + type: type, + setting: setting, + value: +value + } + }; + return this._request.post('/apps/tasks/settings/\ + {type}/{setting}/{value}', params); + }; + + Persistence.prototype.getLists = function(onSuccess, showLoading, which) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (showLoading == null) { + showLoading = true; + } + if (which == null) { + which = 'all'; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function(data) { + return onSuccess(); + }; + failureCallbackWrapper = function(data) {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper, + routeParams: { + request: which + } + }; + return this._request.get('/apps/tasks/lists', params); + }; + + Persistence.prototype.addList = function(list, onSuccess, onFailure) { + var params; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + params = { + data: { + name: list.displayname, + tmpID: list.tmpID + }, + onSuccess: onSuccess, + onFailure: onFailure + }; + return this._request.post('/apps/tasks/lists/add', params); + }; + + Persistence.prototype.setListName = function(list) { + var params; + params = { + routeParams: { + listID: list.id + }, + data: { + name: list.displayname + } + }; + return this._request.post('/apps/tasks/lists/{listID}/name', params); + }; + + Persistence.prototype.deleteList = function(listID) { + var params; + params = { + routeParams: { + listID: listID + } + }; + return this._request.post('/apps/tasks/lists/{listID}/delete', params); + }; + + Persistence.prototype.getTasks = function(type, listID, onSuccess, showLoading) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (type == null) { + type = 'init'; + } + if (listID == null) { + listID = 'all'; + } + if (showLoading == null) { + showLoading = true; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function(data) { + return onSuccess(); + }; + failureCallbackWrapper = function(data) {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper, + routeParams: { + listID: listID, + type: type + } + }; + return this._request.get('/apps/tasks/tasks/{type}/{listID}', params); + }; + + Persistence.prototype.getTask = function(taskID, onSuccess, showLoading) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (showLoading == null) { + showLoading = true; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function() { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function() { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function() { + return onSuccess(); + }; + failureCallbackWrapper = function() {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper, + routeParams: { + taskID: taskID + } + }; + return this._request.get('/apps/tasks/task/{taskID}', params); + }; + + Persistence.prototype.setPercentComplete = function(taskID, complete) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + complete: complete + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/percentcomplete', params); + }; + + Persistence.prototype.setPriority = function(taskID, priority) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + priority: priority + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/priority', params); + }; + + Persistence.prototype.setHideSubtasks = function(taskID, hide) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + hide: hide + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/hidesubtasks', params); + }; + + Persistence.prototype.addTask = function(task, onSuccess, onFailure) { + var params; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + params = { + data: { + name: task.name, + related: task.related, + calendarID: task.calendarid, + starred: task.starred, + due: task.due, + start: task.start, + tmpID: task.tmpID + }, + onSuccess: onSuccess, + onFailure: onFailure + }; + return this._request.post('/apps/tasks/tasks/add', params); + }; + + Persistence.prototype.deleteTask = function(taskID) { + var params; + params = { + routeParams: { + taskID: taskID + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/delete', params); + }; + + Persistence.prototype.setDueDate = function(taskID, due) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + due: due + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/due', params); + }; + + Persistence.prototype.setStartDate = function(taskID, start) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + start: start + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/start', params); + }; + + Persistence.prototype.setReminder = function(taskID, reminder) { + var params; + if (reminder === false) { + params = { + routeParams: { + taskID: taskID + }, + data: { + type: false + } + }; + } else if (reminder.type === 'DATE-TIME') { + params = { + routeParams: { + taskID: taskID + }, + data: { + type: reminder.type, + action: reminder.action, + date: moment(reminder.date, 'YYYYMMDDTHHmmss').unix() + } + }; + } else if (reminder.type === 'DURATION') { + params = { + routeParams: { + taskID: taskID + }, + data: { + type: reminder.type, + action: reminder.action, + week: reminder.duration.week, + day: reminder.duration.day, + hour: reminder.duration.hour, + minute: reminder.duration.minute, + second: reminder.duration.second, + invert: reminder.duration.params.invert, + related: reminder.duration.params.related + } + }; + } else { + return; + } + return this._request.post('/apps/tasks/tasks/{taskID}/reminder', params); + }; + + Persistence.prototype.changeCalendarId = function(taskID, calendarID) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + calendarID: calendarID + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/calendar', params); + }; + + Persistence.prototype.changeParent = function(taskID, related) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + related: related + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/parent', params); + }; + + Persistence.prototype.setTaskName = function(taskID, name) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + name: name + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/name', params); + }; + + Persistence.prototype.setTaskNote = function(taskID, note) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + note: note + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/note', params); + }; + + Persistence.prototype.setShowHidden = function(showHidden) { + var params; + params = { + routeParams: { + showHidden: +showHidden + } + }; + return this._request.post('/apps/tasks/settings/showhidden/{showHidden}', params); + }; + + Persistence.prototype.addComment = function(comment, onSuccess, onFailure) { + var params; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + params = { + routeParams: { + taskID: comment.taskID + }, + data: { + comment: comment.comment, + tmpID: comment.tmpID + }, + onSuccess: onSuccess, + onFailure: onFailure + }; + return this._request.post('/apps/tasks/tasks/{taskID}/comment', params); + }; + + Persistence.prototype.deleteComment = function(taskID, commentID) { + var params; + params = { + routeParams: { + taskID: taskID, + commentID: commentID + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/comment/\ + {commentID}/delete', params); + }; + + Persistence.prototype.addCategory = function(taskID, category) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + category: category + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/category/add', params); + }; + + Persistence.prototype.removeCategory = function(taskID, category) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + category: category + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/category/remove', params); + }; + + return Persistence; + + })(); + return new Persistence(Request, Loading, $rootScope, CalendarService); + } + ]); + +}).call(this); diff --git a/js/app/services/publisher.coffee b/js/app/services/publisher.coffee deleted file mode 100644 index 827e820e..00000000 --- a/js/app/services/publisher.coffee +++ /dev/null @@ -1,46 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').factory 'Publisher', -['CollectionsModel', 'SettingsModel', -(CollectionsModel, SettingsModel) -> - - class Publisher - - constructor: (@_$collectionsmodel, @_$settingsmodel) -> - @_subscriptions = {} - @subscribeObjectTo(@_$collectionsmodel, 'collections') - @subscribeObjectTo(@_$settingsmodel, 'settings') - - subscribeObjectTo: (object, name) -> - (base = @_subscriptions)[name] || (base[name] = []) - return @_subscriptions[name].push(object) - - publishDataTo: (data, name) -> - ref = @_subscriptions[name] || [] - results = [] - for subscriber in ref - results.push(subscriber.handle(data)) - return results - - return new Publisher(CollectionsModel, SettingsModel) - -] diff --git a/js/app/services/publisher.js b/js/app/services/publisher.js new file mode 100644 index 00000000..6ce858f7 --- /dev/null +++ b/js/app/services/publisher.js @@ -0,0 +1,59 @@ +/** + * 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').factory('Publisher', [ + 'CollectionsModel', 'SettingsModel', function(CollectionsModel, SettingsModel) { + var Publisher; + Publisher = (function() { + function Publisher(_$collectionsmodel, _$settingsmodel) { + this._$collectionsmodel = _$collectionsmodel; + this._$settingsmodel = _$settingsmodel; + this._subscriptions = {}; + this.subscribeObjectTo(this._$collectionsmodel, 'collections'); + this.subscribeObjectTo(this._$settingsmodel, 'settings'); + } + + Publisher.prototype.subscribeObjectTo = function(object, name) { + var base; + (base = this._subscriptions)[name] || (base[name] = []); + return this._subscriptions[name].push(object); + }; + + Publisher.prototype.publishDataTo = function(data, name) { + var ref, results, subscriber, _i, _len; + ref = this._subscriptions[name] || []; + results = []; + for (_i = 0, _len = ref.length; _i < _len; _i++) { + subscriber = ref[_i]; + results.push(subscriber.handle(data)); + } + return results; + }; + + return Publisher; + + })(); + return new Publisher(CollectionsModel, SettingsModel); + } + ]); + +}).call(this); diff --git a/js/app/services/request.coffee b/js/app/services/request.coffee deleted file mode 100644 index 5d1d1c59..00000000 --- a/js/app/services/request.coffee +++ /dev/null @@ -1,128 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2015 - -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').factory 'Request', -[ '$http', 'Publisher', ($http, Publisher) -> - - class Request - - constructor: (@$http, @publisher) -> - @count = 0 - @initialized = false - @shelvedRequests = [] - @initialized = true - @_executeShelvedRequests() - - request: (route, data) -> - if data == null - data = {} - - # Wrapper to do a normal request to the server. This needs to - # be done to hook the publisher into the requests and to handle - # requests, that come in before routes have been loaded - - # route: the routename data can contain the following - # data.routeParams: object with parameters for the route - # data.data: ajax data objec which is passed to PHP - # data.onSuccess: callback for successful requests - # data.onFailure: callback for failed requests - # data.config: a config which should be passed to $http - defaultData = { - routeParams: {}, - data: {}, - onSuccess: () -> {}, - onFailure: () -> {}, - config: {} - } - angular.extend(defaultData, data) - if !@initialized - @_shelveRequest(route, defaultData) - return - - url = OC.generateUrl(route, defaultData.routeParams) - defaultConfig = { - url: url, - data: defaultData.data - } - angular.extend(defaultConfig, defaultData.config) - if defaultConfig.method == 'GET' - defaultConfig.params = defaultConfig.data - - return @$http(defaultConfig) - .success( - do (_this = @) -> - return (data, status, headers, config) -> - ref = data.data - for name of ref - value = ref[name] - _this.publisher.publishDataTo(value, name) - return defaultData.onSuccess(data, status, headers, config) - ) - .error( - (data, status, headers, config) -> - return defaultData.onFailure(data, status, headers, config) - ) - - post: (route, data) -> - if data == null - data = {} - data.config || (data.config = {}) - data.config.method = 'POST' - return @request(route, data) - - get: (route, data) -> - if data == null - data = {} - data.config || (data.config = {}) - data.config.method = 'GET' - return @request(route, data) - - put: (route, data) -> - if data == null - data = {} - data.config || (data.config = {}) - data.config.method = 'PUT' - return @request(route, data) - - delete: (route, data) -> - if data == null - data = {} - data.config || (data.config = {}) - data.config.method = 'DELETE' - return @request(route, data) - - _shelveRequest: (route, data) -> - request = { - route: route, - data: data - } - return @shelvedRequests.push(request) - - _executeShelvedRequests: () -> - ref = @shelvedRequests - results = [] - for r in ref - results.push(@request(r.route, r.data)) - return results - - return new Request($http, Publisher) - -] diff --git a/js/app/services/request.js b/js/app/services/request.js new file mode 100644 index 00000000..b07bb68c --- /dev/null +++ b/js/app/services/request.js @@ -0,0 +1,145 @@ +/** + * 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').factory('Request', [ + '$http', 'Publisher', function($http, Publisher) { + var Request; + Request = (function() { + function Request($http, publisher) { + this.$http = $http; + this.publisher = publisher; + this.count = 0; + this.initialized = false; + this.shelvedRequests = []; + this.initialized = true; + this._executeShelvedRequests(); + } + + Request.prototype.request = function(route, data) { + var defaultConfig, defaultData, url; + if (data === null) { + data = {}; + } + defaultData = { + routeParams: {}, + data: {}, + onSuccess: function() { + return {}; + }, + onFailure: function() { + return {}; + }, + config: {} + }; + angular.extend(defaultData, data); + if (!this.initialized) { + this._shelveRequest(route, defaultData); + return; + } + url = OC.generateUrl(route, defaultData.routeParams); + defaultConfig = { + url: url, + data: defaultData.data + }; + angular.extend(defaultConfig, defaultData.config); + if (defaultConfig.method === 'GET') { + defaultConfig.params = defaultConfig.data; + } + return this.$http(defaultConfig).success((function(_this) { + return function(data, status, headers, config) { + var name, ref, value; + ref = data.data; + for (name in ref) { + value = ref[name]; + _this.publisher.publishDataTo(value, name); + } + return defaultData.onSuccess(data, status, headers, config); + }; + })(this)).error(function(data, status, headers, config) { + return defaultData.onFailure(data, status, headers, config); + }); + }; + + Request.prototype.post = function(route, data) { + if (data === null) { + data = {}; + } + data.config || (data.config = {}); + data.config.method = 'POST'; + return this.request(route, data); + }; + + Request.prototype.get = function(route, data) { + if (data === null) { + data = {}; + } + data.config || (data.config = {}); + data.config.method = 'GET'; + return this.request(route, data); + }; + + Request.prototype.put = function(route, data) { + if (data === null) { + data = {}; + } + data.config || (data.config = {}); + data.config.method = 'PUT'; + return this.request(route, data); + }; + + Request.prototype["delete"] = function(route, data) { + if (data === null) { + data = {}; + } + data.config || (data.config = {}); + data.config.method = 'DELETE'; + return this.request(route, data); + }; + + Request.prototype._shelveRequest = function(route, data) { + var request; + request = { + route: route, + data: data + }; + return this.shelvedRequests.push(request); + }; + + Request.prototype._executeShelvedRequests = function() { + var r, ref, results, _i, _len; + ref = this.shelvedRequests; + results = []; + for (_i = 0, _len = ref.length; _i < _len; _i++) { + r = ref[_i]; + results.push(this.request(r.route, r.data)); + } + return results; + }; + + return Request; + + })(); + return new Request($http, Publisher); + } + ]); + +}).call(this); diff --git a/js/app/services/status.coffee b/js/app/services/status.coffee deleted file mode 100644 index bc037873..00000000 --- a/js/app/services/status.coffee +++ /dev/null @@ -1,38 +0,0 @@ -### - -ownCloud - Tasks - -@author Raimund Schlüßler -@copyright 2013 - -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').factory 'Status', -[ () -> - - class Status - - constructor: () -> - @_$status = { - addingList: false - focusTaskInput: false - } - - getStatus: () -> - @_$status - - return new Status() - -]
\ No newline at end of file diff --git a/js/app/services/status.js b/js/app/services/status.js new file mode 100644 index 00000000..a585db1c --- /dev/null +++ b/js/app/services/status.js @@ -0,0 +1,45 @@ +/** + * 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').factory('Status', [ + function() { + var Status; + Status = (function() { + function Status() { + this._$status = { + addingList: false, + focusTaskInput: false + }; + } + + Status.prototype.getStatus = function() { + return this._$status; + }; + + return Status; + + })(); + return new Status(); + } + ]); + +}).call(this); diff --git a/js/package.json b/js/package.json index a958541a..b25ff26a 100644 --- a/js/package.json +++ b/js/package.json @@ -17,12 +17,11 @@ "dependencies": {}, "devDependencies": { "bower": "*", - "coffee-script": "~1.4.0", "grunt": "~0.4.1", "grunt-cli": "~0.1.6", - "grunt-coffeelint": "0.0.6", + "grunt-contrib-jshint": "*", + "jshint-stylish": "^2.1.0", "grunt-concurrent": "~1.0.0", - "grunt-contrib-coffee": "~0.7.0", "grunt-contrib-concat": "~0.1.2", "grunt-contrib-less": "~0.6.4", "grunt-contrib-watch": "~0.2.0", diff --git a/js/public/app.js b/js/public/app.js index 7322945c..bb498b83 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -1,11 +1,11 @@ -(function(angular, $, moment, undefined){ +(function(angular, $, oc_requesttoken, undefined){ /** * ownCloud Task App - v0.9.0 * * Copyright (c) 2016 - Raimund Schlüßler <raimund.schluessler@googlemail.com> * - * This file is licensed under the Affero General Public License version 3 or later. + * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING file * */ @@ -13,899 +13,749 @@ (function() { angular.module('Tasks', ['ngRoute', 'ngAnimate', 'ui.select', 'ngSanitize', 'dndLists']).config([ - '$provide', '$routeProvider', '$interpolateProvider', '$httpProvider', function($provide, $routeProvider, $interpolateProvider, $httpProvider) { - var config; - $provide.value('Config', config = { - markReadTimeout: 500, - taskUpdateInterval: 1000 * 600 - }); - $httpProvider.defaults.headers.common['requesttoken'] = oc_requesttoken; - $routeProvider.when('/calendars/:calendarID', {}).when('/calendars/:calendarID/edit/:listparameter', {}).when('/calendars/:calendarID/tasks/:taskID', {}).when('/calendars/:calendarID/tasks/:taskID/settings', {}).when('/calendars/:calendarID/tasks/:taskID/edit/:parameter', {}).when('/collections/:collectionID', {}).when('/search/:searchString', {}).when('/search/:searchString/tasks/:taskID', {}).when('/search/:searchString/tasks/:taskID/edit/:parameter', {}); - } + '$provide', '$routeProvider', '$interpolateProvider', '$httpProvider', function($provide, $routeProvider, $interpolateProvider, $httpProvider) { + var config; + $provide.value('Config', config = { + markReadTimeout: 500, + taskUpdateInterval: 1000 * 600 + }); + $httpProvider.defaults.headers.common['requesttoken'] = oc_requesttoken; + $routeProvider.when('/calendars/:calendarID', {}).when('/calendars/:calendarID/edit/:listparameter', {}).when('/calendars/:calendarID/tasks/:taskID', {}).when('/calendars/:calendarID/tasks/:taskID/settings', {}).when('/calendars/:calendarID/tasks/:taskID/edit/:parameter', {}).when('/collections/:collectionID', {}).when('/search/:searchString', {}).when('/search/:searchString/tasks/:taskID', {}).when('/search/:searchString/tasks/:taskID/edit/:parameter', {}); + } ]); angular.module('Tasks').run([ - '$document', '$rootScope', 'Config', '$timeout', 'ListsBusinessLayer', 'TasksBusinessLayer', 'SearchBusinessLayer', function($document, $rootScope, Config, $timeout, TasksBusinessLayer, ListsBusinessLayer, SearchBusinessLayer) { - var init, update; - init = false; - (update = function() { - var timeOutUpdate; - timeOutUpdate = function() { - return $timeout(update, Config.taskUpdateInterval); - }; - init = true; - return timeOutUpdate(); - })(); - OCA.Search.tasks = SearchBusinessLayer; - $('link[rel="shortcut icon"]').attr('href', OC.filePath('tasks', 'img', 'favicon.png')); - $document.click(function(event) { - $rootScope.$broadcast('documentClicked', event); - }); - moment.locale('details', { - calendar: { - lastDay: '[' + t('tasks', 'Due yesterday') + '], HH:mm', - sameDay: '[' + t('tasks', 'Due today') + '], HH:mm', - nextDay: '[' + t('tasks', 'Due tomorrow') + '], HH:mm', - lastWeek: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm', - nextWeek: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm', - sameElse: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm' - } - }); - moment.locale('start', { - calendar: { - lastDay: '[' + t('tasks', 'Started yesterday') + '], HH:mm', - sameDay: '[' + t('tasks', 'Starts today') + '], HH:mm', - nextDay: '[' + t('tasks', 'Starts tomorrow') + '], HH:mm', - lastWeek: '[' + t('tasks', 'Started on') + '] MMM DD, YYYY, HH:mm', - nextWeek: '[' + t('tasks', 'Starts on') + '] MMM DD, YYYY, HH:mm', - sameElse: function() { - if (this.diff(moment()) > 0) { - return '[' + t('tasks', 'Starts on') + '] MMM DD, YYYY, HH:mm'; - } else { - return '[' + t('tasks', 'Started on') + '] MMM DD, YYYY, HH:mm'; - } - } - } - }); - moment.locale('reminder', { - calendar: { - lastDay: t('tasks', '[Remind me yesterday at ]HH:mm'), - sameDay: t('tasks', '[Remind me today at ]HH:mm'), - nextDay: t('tasks', '[Remind me tomorrow at ]HH:mm'), - lastWeek: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm'), - nextWeek: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm'), - sameElse: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm') - } - }); - moment.locale('tasks', { - calendar: { - lastDay: '[' + t('tasks', 'Yesterday') + ']', - sameDay: '[' + t('tasks', 'Today') + ']', - nextDay: '[' + t('tasks', 'Tomorrow') + ']', - lastWeek: 'DD.MM.YYYY', - nextWeek: 'DD.MM.YYYY', - sameElse: 'DD.MM.YYYY' - } - }); - moment.locale('details_short', { - calendar: { - lastDay: '[' + t('tasks', 'Yesterday') + ']', - sameDay: '[' + t('tasks', 'Today') + ']', - nextDay: '[' + t('tasks', 'Tomorrow') + ']', - lastWeek: 'MMM DD, YYYY', - nextWeek: 'MMM DD, YYYY', - sameElse: 'MMM DD, YYYY' - } - }); - moment.locale('list_week', { - calendar: { - lastDay: '[' + t('tasks', 'Yesterday') + ']', - sameDay: '[' + t('tasks', 'Today') + '], MMM. DD', - nextDay: '[' + t('tasks', 'Tomorrow') + '], MMM. DD', - lastWeek: 'ddd, MMM. DD', - nextWeek: 'ddd, MMM. DD', - sameElse: 'ddd, MMM. DD' - } - }); - return moment.locale('en', { - relativeTime: { - future: t('tasks', "in %s"), - past: t('tasks', "%s ago"), - s: t('tasks', "seconds"), - m: t('tasks', "a minute"), - mm: t('tasks', "%d minutes"), - h: t('tasks', "an hour"), - hh: t('tasks', "%d hours"), - d: t('tasks', "a day"), - dd: t('tasks', "%d days"), - M: t('tasks', "a month"), - MM: t('tasks', "%d months"), - y: t('tasks', "a year"), - yy: t('tasks', "%d years") - } - }); - } - ]); - -}).call(this); - -(function() { - angular.module('Tasks').directive('appNavigationEntryUtils', function() { - 'use strict'; - return { - restrict: 'C', - link: function(scope, elm) { - var button, menu; - menu = elm.siblings('.app-navigation-entry-menu'); - button = $(elm).find('.app-navigation-entry-utils-menu-button button'); - button.click(function() { - menu.toggleClass('open'); - }); - scope.$on('documentClicked', function(scope, event) { - if (event.target !== button[0]) { - menu.removeClass('open'); - } - }); - } - }; - }); - -}).call(this); - -(function() { - angular.module('Tasks').directive('autofocusOnInsert', function() { - 'use strict'; - return function(scope, elm) { - return elm.focus(); - }; - }); - -}).call(this); - -(function() { - angular.module('Tasks').directive('avatar', function() { - return { - restrict: 'A', - scope: false, - link: function(scope, elm, attr) { - return attr.$observe('userid', function() { - if (attr.userid) { - return elm.avatar(attr.userid, attr.size); - } - }); - } - }; - }); - -}).call(this); - -(function() { - angular.module('Tasks').directive('datepicker', function() { - return { - restrict: 'A', - scope: false, - link: function(scope, elm, attr) { - return elm.datepicker({ - onSelect: function(date, inst) { - scope['set' + attr.datepicker + 'day'](date); - return scope.$apply(); - }, - beforeShow: function(input, inst) { - var dp, marginLeft; - dp = $(inst).datepicker('widget'); - marginLeft = -Math.abs($(input).outerWidth() - dp.outerWidth()) / 2 + 'px'; - dp.css({ - 'margin-left': marginLeft - }); - $("div.ui-datepicker:before").css({ - 'left': 100 + 'px' - }); - return $('.hasDatepicker').datepicker("option", "firstDay", scope.settingsmodel.getById('various').startOfWeek); - }, - beforeShowDay: function(date) { - if (moment(date).startOf('day').diff(moment(scope.task[attr.datepicker], "YYYYMMDDTHHmmss").startOf('day'), 'days') === 0) { - return [1, "selected"]; - } else { - return [1, ""]; - } - }, - minDate: null - }); - } - }; - }); - -}).call(this); - -(function() { - angular.module('Tasks').directive('ocClickFocus', [ - '$timeout', function($timeout) { - return function(scope, elm, attr) { - var options; - options = scope.$eval(attr.ocClickFocus); - if (angular.isDefined(options) && angular.isDefined(options.selector)) { - return elm.click(function() { - if (angular.isDefined(options.timeout)) { - return $timeout(function() { - return $(options.selector).focus(); - }, options.timeout); - } else { - return $(options.selector).focus(); - } - }); - } - }; - } + '$document', '$rootScope', 'Config', '$timeout', 'ListsBusinessLayer', 'TasksBusinessLayer', 'SearchBusinessLayer', function($document, $rootScope, Config, $timeout, TasksBusinessLayer, ListsBusinessLayer, SearchBusinessLayer) { + var init, update; + init = false; + (update = function() { + var timeOutUpdate; + timeOutUpdate = function() { + return $timeout(update, Config.taskUpdateInterval); + }; + init = true; + return timeOutUpdate(); + })(); + OCA.Search.tasks = SearchBusinessLayer; + $('link[rel="shortcut icon"]').attr('href', OC.filePath('tasks', 'img', 'favicon.png')); + $document.click(function(event) { + $rootScope.$broadcast('documentClicked', event); + }); + moment.locale('details', { + calendar: { + lastDay: '[' + t('tasks', 'Due yesterday') + '], HH:mm', + sameDay: '[' + t('tasks', 'Due today') + '], HH:mm', + nextDay: '[' + t('tasks', 'Due tomorrow') + '], HH:mm', + lastWeek: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm', + nextWeek: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm', + sameElse: '[' + t('tasks', 'Due on') + '] MMM DD, YYYY, HH:mm' + } + }); + moment.locale('start', { + calendar: { + lastDay: '[' + t('tasks', 'Started yesterday') + '], HH:mm', + sameDay: '[' + t('tasks', 'Starts today') + '], HH:mm', + nextDay: '[' + t('tasks', 'Starts tomorrow') + '], HH:mm', + lastWeek: '[' + t('tasks', 'Started on') + '] MMM DD, YYYY, HH:mm', + nextWeek: '[' + t('tasks', 'Starts on') + '] MMM DD, YYYY, HH:mm', + sameElse: function() { + if (this.diff(moment()) > 0) { + return '[' + t('tasks', 'Starts on') + '] MMM DD, YYYY, HH:mm'; + } else { + return '[' + t('tasks', 'Started on') + '] MMM DD, YYYY, HH:mm'; + } + } + } + }); + moment.locale('reminder', { + calendar: { + lastDay: t('tasks', '[Remind me yesterday at ]HH:mm'), + sameDay: t('tasks', '[Remind me today at ]HH:mm'), + nextDay: t('tasks', '[Remind me tomorrow at ]HH:mm'), + lastWeek: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm'), + nextWeek: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm'), + sameElse: t('tasks', '[Remind me on ]MMM DD, YYYY,[ at ]HH:mm') + } + }); + moment.locale('tasks', { + calendar: { + lastDay: '[' + t('tasks', 'Yesterday') + ']', + sameDay: '[' + t('tasks', 'Today') + ']', + nextDay: '[' + t('tasks', 'Tomorrow') + ']', + lastWeek: 'DD.MM.YYYY', + nextWeek: 'DD.MM.YYYY', + sameElse: 'DD.MM.YYYY' + } + }); + moment.locale('details_short', { + calendar: { + lastDay: '[' + t('tasks', 'Yesterday') + ']', + sameDay: '[' + t('tasks', 'Today') + ']', + nextDay: '[' + t('tasks', 'Tomorrow') + ']', + lastWeek: 'MMM DD, YYYY', + nextWeek: 'MMM DD, YYYY', + sameElse: 'MMM DD, YYYY' + } + }); + moment.locale('list_week', { + calendar: { + lastDay: '[' + t('tasks', 'Yesterday') + ']', + sameDay: '[' + t('tasks', 'Today') + '], MMM. DD', + nextDay: '[' + t('tasks', 'Tomorrow') + '], MMM. DD', + lastWeek: 'ddd, MMM. DD', + nextWeek: 'ddd, MMM. DD', + sameElse: 'ddd, MMM. DD' + } + }); + return moment.locale('en', { + relativeTime: { + future: t('tasks', "in %s"), + past: t('tasks', "%s ago"), + s: t('tasks', "seconds"), + m: t('tasks', "a minute"), + mm: t('tasks', "%d minutes"), + h: t('tasks', "an hour"), + hh: t('tasks', "%d hours"), + d: t('tasks', "a day"), + dd: t('tasks', "%d days"), + M: t('tasks', "a month"), + MM: t('tasks', "%d months"), + y: t('tasks', "a year"), + yy: t('tasks', "%d years") + } + }); + } ]); }).call(this); (function() { - angular.module('Tasks').directive('timepicker', function() { - return { - restrict: 'A', - link: function(scope, elm, attr) { - return elm.timepicker({ - onSelect: function(date, inst) { - scope['set' + attr.timepicker + 'time'](date); - return scope.$apply(); - }, - myPosition: 'center top', - atPosition: 'center bottom', - hourText: t('tasks', 'Hours'), - minuteText: t('tasks', 'Minutes') - }); - } - }; - }); - -}).call(this); - -(function() { - angular.module('Tasks').directive('watchTop', function() { - return { - restrict: 'A', - link: function(scope, element, attr) { - ({ - scope: { - "divTop": "=" - } - }); - return scope.$watch(function() { - return scope.divTop = element.prev().outerHeight(true); - }); - } - }; - }); - -}).call(this); - -(function() { angular.module('Tasks').controller('AppController', [ - '$scope', 'ListsBusinessLayer', '$route', 'Status', '$timeout', '$location', '$routeParams', 'Loading', 'SettingsModel', 'Persistence', function($scope, ListsBusinessLayer, $route, status, $timeout, $location, $routeParams, Loading, SettingsModel, Persistence) { - var AppController; - AppController = (function() { - function AppController(_$scope, _$listsbusinesslayer, _$route, _$status, _$timeout, _$location, _$routeparams, _Loading, _$settingsmodel, _persistence) { - this._$scope = _$scope; - this._$listsbusinesslayer = _$listsbusinesslayer; - this._$route = _$route; - this._$status = _$status; - this._$timeout = _$timeout; - this._$location = _$location; - this._$routeparams = _$routeparams; - this._Loading = _Loading; - this._$settingsmodel = _$settingsmodel; - this._persistence = _persistence; - this._$scope.initialized = false; - this._$scope.status = this._$status.getStatus(); - this._$scope.route = this._$routeparams; - this._$scope.status.newListName = ""; - this._$scope.settingsmodel = this._$settingsmodel; - this._$listsbusinesslayer.init().then(function() { - return $scope.$apply(); - }); - this._persistence.init(); - this._$scope.closeAll = function($event) { - if ($($event.target).closest('.close-all').length || $($event.currentTarget).is($($event.target).closest('.handler'))) { - if (!angular.isUndefined(_$scope.route.calendarID)) { - _$location.path('/calendars/' + _$scope.route.calendarID); - } else if (!angular.isUndefined(_$scope.route.collectionID)) { - _$location.path('/collections/' + _$scope.route.collectionID); - } else { - _$location.path('/collections/all'); - } - _$scope.status.addingList = false; - _$scope.status.focusTaskInput = false; - _$scope.status.newListName = ""; - } - if (!$($event.target).closest('.newList').length) { - _$scope.status.addingList = false; - _$scope.status.newListName = ""; - } - if (!$($event.target).closest('.add-subtask').length) { - _$scope.status.addSubtaskTo = ''; - return _$scope.status.focusSubtaskInput = false; - } else { + '$scope', 'ListsBusinessLayer', '$route', 'Status', '$timeout', '$location', '$routeParams', 'Loading', 'SettingsModel', 'Persistence', function($scope, ListsBusinessLayer, $route, status, $timeout, $location, $routeParams, Loading, SettingsModel, Persistence) { + var AppController; + AppController = (function() { + function AppController(_$scope, _$listsbusinesslayer, _$route, _$status, _$timeout, _$location, _$routeparams, _Loading, _$settingsmodel, _persistence) { + this._$scope = _$scope; + this._$listsbusinesslayer = _$listsbusinesslayer; + this._$route = _$route; + this._$status = _$status; + this._$timeout = _$timeout; + this._$location = _$location; + this._$routeparams = _$routeparams; + this._Loading = _Loading; + this._$settingsmodel = _$settingsmodel; + this._persistence = _persistence; + this._$scope.initialized = false; + this._$scope.status = this._$status.getStatus(); + this._$scope.route = this._$routeparams; + this._$scope.status.newListName = ""; + this._$scope.settingsmodel = this._$settingsmodel; + this._$listsbusinesslayer.init().then(function() { + return $scope.$apply(); + }); + + this._persistence.init(); + this._$scope.closeAll = function($event) { + if ($($event.target).closest('.close-all').length || $($event.currentTarget).is($($event.target).closest('.handler'))) { + if (!angular.isUndefined(_$scope.route.calendarID)) { + _$location.path('/calendars/' + _$scope.route.calendarID); + } else if (!angular.isUndefined(_$scope.route.collectionID)) { + _$location.path('/collections/' + _$scope.route.collectionID); + } else { + _$location.path('/collections/all'); + } + _$scope.status.addingList = false; + _$scope.status.focusTaskInput = false; + _$scope.status.newListName = ""; + } + if (!$($event.target).closest('.newList').length) { + _$scope.status.addingList = false; + _$scope.status.newListName = ""; + } + if (!$($event.target).closest('.add-subtask').length) { + _$scope.status.addSubtaskTo = ''; + return _$scope.status.focusSubtaskInput = false; + } else { - } - }; - this._$scope.isLoading = function() { - return _Loading.isLoading(); - }; - } + } + }; + this._$scope.isLoading = function() { + return _Loading.isLoading(); + }; + } - return AppController; + return AppController; - })(); - return new AppController($scope, ListsBusinessLayer, $route, status, $timeout, $location, $routeParams, Loading, SettingsModel, Persistence); - } + })(); + return new AppController($scope, ListsBusinessLayer, $route, status, $timeout, $location, $routeParams, Loading, SettingsModel, Persistence); + } ]); }).call(this); (function() { angular.module('Tasks').controller('DetailsController', [ - '$scope', '$window', 'TasksModel', 'TasksBusinessLayer', '$route', '$location', '$timeout', '$routeParams', 'SettingsModel', 'Loading', function($scope, $window, TasksModel, TasksBusinessLayer, $route, $location, $timeout, $routeParams, SettingsModel, Loading) { - var DetailsController; - DetailsController = (function() { - function DetailsController(_$scope, _$window, _$tasksmodel, _tasksbusinesslayer, _$route, _$location, _$timeout, _$routeparams, _$settingsmodel, _Loading) { - this._$scope = _$scope; - this._$window = _$window; - this._$tasksmodel = _$tasksmodel; - this._tasksbusinesslayer = _tasksbusinesslayer; - this._$route = _$route; - this._$location = _$location; - this._$timeout = _$timeout; - this._$routeparams = _$routeparams; - this._$settingsmodel = _$settingsmodel; - this._Loading = _Loading; - this._$scope.task = _$tasksmodel.getById(_$scope.route.taskID); - this._$scope.found = true; - this._$scope.$on('$routeChangeSuccess', function() { - var task, - _this = this; - task = _$tasksmodel.getById(_$scope.route.taskID); - if (!(angular.isUndefined(task) || task === null)) { - _$scope.task = task; - return _$scope.found = true; - } else if (_$scope.route.taskID !== void 0) { - _$scope.found = false; - return _tasksbusinesslayer.getTask(_$scope.route.taskID, function(data) { - return _$scope.loadTask(_$scope.route.taskID); - }); - } - }); - this._$scope.settingsmodel = this._$settingsmodel; - this._$scope.settingsmodel.add({ - 'id': 'various', - 'categories': [] - }); - this._$scope.isAddingComment = false; - this._$scope.timers = []; - this._$scope.durations = [ - { - name: t('tasks', 'week'), - names: t('tasks', 'weeks'), - id: 'week' - }, { - name: t('tasks', 'day'), - names: t('tasks', 'days'), - id: 'day' - }, { - name: t('tasks', 'hour'), - names: t('tasks', 'hours'), - id: 'hour' - }, { - name: t('tasks', 'minute'), - names: t('tasks', 'minutes'), - id: 'minute' - }, { - name: t('tasks', 'second'), - names: t('tasks', 'seconds'), - id: 'second' - } - ]; - this._$scope.loadTask = function(taskID) { - var task; - task = _$tasksmodel.getById(_$scope.route.taskID); - if (!(angular.isUndefined(task) || task === null)) { - _$scope.task = task; - return _$scope.found = true; - } - }; - this._$scope.TaskState = function() { - if (_$scope.found) { - return 'found'; - } else { - if (_Loading.isLoading()) { - return 'loading'; - } else { - return null; - } - } - }; - this._$scope.params = [ - { - name: t('tasks', 'before beginning'), - invert: true, - related: 'START', - id: "10" - }, { - name: t('tasks', 'after beginning'), - invert: false, - related: 'START', - id: "00" - }, { - name: t('tasks', 'before end'), - invert: true, - related: 'END', - id: "11" - }, { - name: t('tasks', 'after end'), - invert: false, - related: 'END', - id: "01" - } - ]; - this._$scope.filterParams = function(params) { - var task; - task = _$tasksmodel.getById(_$scope.route.taskID); - if (!(angular.isUndefined(task) || task === null)) { - if (task.due && task.start) { - return params; - } else if (task.start) { - return params.slice(0, 2); - } else { - return params.slice(2); - } - } - }; - this._$scope.deleteTask = function(taskID) { - return _$timeout(function() { - return _tasksbusinesslayer.deleteTask(taskID); - }, 500); - }; - this._$scope.editName = function($event) { - if ($($event.target).is('a')) { + '$scope', '$window', 'TasksModel', 'TasksBusinessLayer', '$route', '$location', '$timeout', '$routeParams', 'SettingsModel', 'Loading', function($scope, $window, TasksModel, TasksBusinessLayer, $route, $location, $timeout, $routeParams, SettingsModel, Loading) { + var DetailsController; + DetailsController = (function() { + function DetailsController(_$scope, _$window, _$tasksmodel, _tasksbusinesslayer, _$route, _$location, _$timeout, _$routeparams, _$settingsmodel, _Loading) { + this._$scope = _$scope; + this._$window = _$window; + this._$tasksmodel = _$tasksmodel; + this._tasksbusinesslayer = _tasksbusinesslayer; + this._$route = _$route; + this._$location = _$location; + this._$timeout = _$timeout; + this._$routeparams = _$routeparams; + this._$settingsmodel = _$settingsmodel; + this._Loading = _Loading; + this._$scope.task = _$tasksmodel.getById(_$scope.route.taskID); + this._$scope.found = true; + this._$scope.$on('$routeChangeSuccess', function() { + var task, + _this = this; + task = _$tasksmodel.getById(_$scope.route.taskID); + if (!(angular.isUndefined(task) || task === null)) { + _$scope.task = task; + return _$scope.found = true; + } else if (_$scope.route.taskID !== void 0) { + _$scope.found = false; + return _tasksbusinesslayer.getTask(_$scope.route.taskID, function(data) { + return _$scope.loadTask(_$scope.route.taskID); + }); + } + }); + this._$scope.settingsmodel = this._$settingsmodel; + this._$scope.settingsmodel.add({ + 'id': 'various', + 'categories': [] + }); + this._$scope.isAddingComment = false; + this._$scope.timers = []; + this._$scope.durations = [ + { + name: t('tasks', 'week'), + names: t('tasks', 'weeks'), + id: 'week' + }, { + name: t('tasks', 'day'), + names: t('tasks', 'days'), + id: 'day' + }, { + name: t('tasks', 'hour'), + names: t('tasks', 'hours'), + id: 'hour' + }, { + name: t('tasks', 'minute'), + names: t('tasks', 'minutes'), + id: 'minute' + }, { + name: t('tasks', 'second'), + names: t('tasks', 'seconds'), + id: 'second' + } + ]; + this._$scope.loadTask = function(taskID) { + var task; + task = _$tasksmodel.getById(_$scope.route.taskID); + if (!(angular.isUndefined(task) || task === null)) { + _$scope.task = task; + return _$scope.found = true; + } + }; + this._$scope.TaskState = function() { + if (_$scope.found) { + return 'found'; + } else { + if (_Loading.isLoading()) { + return 'loading'; + } else { + return null; + } + } + }; + this._$scope.params = [ + { + name: t('tasks', 'before beginning'), + invert: true, + related: 'START', + id: "10" + }, { + name: t('tasks', 'after beginning'), + invert: false, + related: 'START', + id: "00" + }, { + name: t('tasks', 'before end'), + invert: true, + related: 'END', + id: "11" + }, { + name: t('tasks', 'after end'), + invert: false, + related: 'END', + id: "01" + } + ]; + this._$scope.filterParams = function(params) { + var task; + task = _$tasksmodel.getById(_$scope.route.taskID); + if (!(angular.isUndefined(task) || task === null)) { + if (task.due && task.start) { + return params; + } else if (task.start) { + return params.slice(0, 2); + } else { + return params.slice(2); + } + } + }; + this._$scope.deleteTask = function(taskID) { + return _$timeout(function() { + return _tasksbusinesslayer.deleteTask(taskID); + }, 500); + }; + this._$scope.editName = function($event) { + if ($($event.target).is('a')) { - } else { - console.log('open edit page'); - return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/name'); - } - }; - this._$scope.editDueDate = function($event) { - if ($($event.currentTarget).is($($event.target).closest('.handler'))) { - _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/duedate'); - return _tasksbusinesslayer.initDueDate(_$scope.route.taskID); - } else { + } else { + console.log('open edit page'); + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/name'); + } + }; + this._$scope.editDueDate = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/duedate'); + return _tasksbusinesslayer.initDueDate(_$scope.route.taskID); + } else { - } - }; - this._$scope.editStart = function($event) { - if ($($event.currentTarget).is($($event.target).closest('.handler'))) { - _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/startdate'); - return _tasksbusinesslayer.initStartDate(_$scope.route.taskID); - } else { + } + }; + this._$scope.editStart = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/startdate'); + return _tasksbusinesslayer.initStartDate(_$scope.route.taskID); + } else { - } - }; - this._$scope.editReminder = function($event) { - if ($($event.currentTarget).is($($event.target).closest('.handler'))) { - _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/reminder'); - return _tasksbusinesslayer.initReminder(_$scope.route.taskID); - } else { + } + }; + this._$scope.editReminder = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/reminder'); + return _tasksbusinesslayer.initReminder(_$scope.route.taskID); + } else { - } - }; - this._$scope.editNote = function($event) { - if ($($event.currentTarget).is($($event.target).closest('.handler'))) { - if ($($event.target).is('a')) { + } + }; + this._$scope.editNote = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + if ($($event.target).is('a')) { + + } else { + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/note'); + } + } else { - } else { - return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/note'); - } - } else { + } + }; + this._$scope.editPriority = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/priority'); + } else { - } - }; - this._$scope.editPriority = function($event) { - if ($($event.currentTarget).is($($event.target).closest('.handler'))) { - return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/priority'); - } else { + } + }; + this._$scope.editPercent = function($event) { + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/percent'); + } else { - } - }; - this._$scope.editPercent = function($event) { - if ($($event.currentTarget).is($($event.target).closest('.handler'))) { - return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID + '/edit/percent'); - } else { + } + }; + this._$scope.endEdit = function($event) { + if ($($event.target).closest('.end-edit').length || $($event.currentTarget).is($($event.target).closest('.handler'))) { + return _$scope.resetRoute(); + } else { - } - }; - this._$scope.endEdit = function($event) { - if ($($event.target).closest('.end-edit').length || $($event.currentTarget).is($($event.target).closest('.handler'))) { - return _$scope.resetRoute(); - } else { + } + }; + this._$scope.endName = function($event) { + if ($event.keyCode === 13) { + $event.preventDefault(); + _$scope.resetRoute(); + } + if ($event.keyCode === 27) { + return _$scope.resetRoute(); + } + }; + this._$scope.resetRoute = function() { + return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID); + }; + this._$scope.deleteDueDate = function() { + return _tasksbusinesslayer.deleteDueDate(_$scope.route.taskID); + }; + this._$scope.deletePercent = function() { + return _tasksbusinesslayer.setPercentComplete(_$scope.route.taskID, 0); + }; + this._$scope.deleteStartDate = function() { + return _tasksbusinesslayer.deleteStartDate(_$scope.route.taskID); + }; + this._$scope.deleteReminder = function() { + return _tasksbusinesslayer.deleteReminderDate(_$scope.route.taskID); + }; + this._$scope.toggleCompleted = function(taskID) { + if (_$tasksmodel.completed(taskID)) { + return _tasksbusinesslayer.uncompleteTask(taskID); + } else { + return _tasksbusinesslayer.completeTask(taskID); + } + }; + this._$scope.toggleStarred = function(taskID) { + if (_$tasksmodel.starred(taskID)) { + return _tasksbusinesslayer.unstarTask(taskID); + } else { + return _tasksbusinesslayer.starTask(taskID); + } + }; + this._$scope.deletePriority = function() { + return _tasksbusinesslayer.unstarTask(_$scope.route.taskID); + }; + this._$scope.isDue = function(date) { + return _$tasksmodel.due(date); + }; + this._$scope.isOverDue = function(date) { + return _$tasksmodel.overdue(date); + }; + this._$scope.$watch('task', function(newVal, oldVal) { + if (newVal === oldVal || (void 0 === newVal || void 0 === oldVal) || newVal.id !== oldVal.id) { - } - }; - this._$scope.endName = function($event) { - if ($event.keyCode === 13) { - $event.preventDefault(); - _$scope.resetRoute(); - } - if ($event.keyCode === 27) { - return _$scope.resetRoute(); - } - }; - this._$scope.resetRoute = function() { - return _$location.path('/lists/' + _$scope.route.listID + '/tasks/' + _$scope.route.taskID); - }; - this._$scope.deleteDueDate = function() { - return _tasksbusinesslayer.deleteDueDate(_$scope.route.taskID); - }; - this._$scope.deletePercent = function() { - return _tasksbusinesslayer.setPercentComplete(_$scope.route.taskID, 0); - }; - this._$scope.deleteStartDate = function() { - return _tasksbusinesslayer.deleteStartDate(_$scope.route.taskID); - }; - this._$scope.deleteReminder = function() { - return _tasksbusinesslayer.deleteReminderDate(_$scope.route.taskID); - }; - this._$scope.toggleCompleted = function(taskID) { - if (_$tasksmodel.completed(taskID)) { - return _tasksbusinesslayer.uncompleteTask(taskID); - } else { - return _tasksbusinesslayer.completeTask(taskID); - } - }; - this._$scope.toggleStarred = function(taskID) { - if (_$tasksmodel.starred(taskID)) { - return _tasksbusinesslayer.unstarTask(taskID); - } else { - return _tasksbusinesslayer.starTask(taskID); - } - }; - this._$scope.deletePriority = function() { - return _tasksbusinesslayer.unstarTask(_$scope.route.taskID); - }; - this._$scope.isDue = function(date) { - return _$tasksmodel.due(date); - }; - this._$scope.isOverDue = function(date) { - return _$tasksmodel.overdue(date); - }; - this._$scope.$watch('task', function(newVal, oldVal) { - if (newVal === oldVal || (void 0 === newVal || void 0 === oldVal) || newVal.id !== oldVal.id) { - - } else { - if (newVal.name !== oldVal.name) { - if (_$scope.timers['task' + newVal.id + 'name']) { - $timeout.cancel(_$scope.timers['task' + newVal.id + 'name']); - } - _$scope.timers['task' + newVal.id + 'name'] = $timeout(function() { - return _tasksbusinesslayer.setTaskName(newVal.id, newVal.name); - }, 3000); - } - if (newVal.note !== oldVal.note) { - if (_$scope.timers['task' + newVal.id + 'note']) { - $timeout.cancel(_$scope.timers['task' + newVal.id + 'note']); - } - _$scope.timers['task' + newVal.id + 'note'] = $timeout(function() { - return _tasksbusinesslayer.setTaskNote(newVal.id, newVal.note); - }, 5000); - } - if (newVal.complete !== oldVal.complete) { - if (_$scope.timers['task' + newVal.id + 'complete']) { - $timeout.cancel(_$scope.timers['task' + newVal.id + 'complete']); - } - _$scope.timers['task' + newVal.id + 'complete'] = $timeout(function() { - return _tasksbusinesslayer.setPercentComplete(newVal.id, newVal.complete); - }, 1000); - } - if (newVal.priority !== oldVal.priority) { - if (_$scope.timers['task' + newVal.id + 'priority']) { - $timeout.cancel(_$scope.timers['task' + newVal.id + 'priority']); - } - return _$scope.timers['task' + newVal.id + 'priority'] = $timeout(function() { - return _tasksbusinesslayer.setPriority(newVal.id, newVal.priority); - }, 1000); - } - } - }, true); - this._$scope.setstartday = function(date) { - return _tasksbusinesslayer.setStart(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); - }; - this._$scope.setstarttime = function(date) { - return _tasksbusinesslayer.setStart(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); - }; - this._$scope.setdueday = function(date) { - return _tasksbusinesslayer.setDue(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); - }; - this._$scope.setduetime = function(date) { - return _tasksbusinesslayer.setDue(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); - }; - this._$scope.setreminderday = function(date) { - return _tasksbusinesslayer.setReminderDate(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); - }; - this._$scope.setremindertime = function(date) { - return _tasksbusinesslayer.setReminderDate(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); - }; - this._$scope.reminderType = function(task) { - if (!angular.isUndefined(task)) { - if (task.reminder === null) { - if (moment(task.start, "YYYYMMDDTHHmmss").isValid() || moment(task.due, "YYYYMMDDTHHmmss").isValid()) { - return 'DURATION'; - } else { - return 'DATE-TIME'; - } - } else { - return task.reminder.type; - } - } - }; - this._$scope.changeReminderType = function(task) { - _tasksbusinesslayer.checkReminderDate(task.id); - if (this.reminderType(task) === 'DURATION') { - if (task.reminder) { - task.reminder.type = 'DATE-TIME'; - } else { - task.reminder = { - type: 'DATE-TIME' - }; - } - } else { - if (task.reminder) { - task.reminder.type = 'DURATION'; - } else { - task.reminder = { - type: 'DURATION' - }; - } - } - return _tasksbusinesslayer.setReminder(task.id); - }; - this._$scope.setReminderDuration = function(taskID) { - return _tasksbusinesslayer.setReminder(_$scope.route.taskID); - }; - this._$scope.addComment = function() { - var comment, - _this = this; - if (_$scope.CommentContent) { - _$scope.isAddingComment = true; - comment = { - tmpID: 'newComment' + Date.now(), - comment: _$scope.CommentContent, - taskID: _$scope.route.taskID, - time: moment().format('YYYYMMDDTHHmmss'), - name: $('#expandDisplayName').text() - }; - _tasksbusinesslayer.addComment(comment, function(data) { - _$tasksmodel.updateComment(data); - return _$scope.isAddingComment = false; - }, function() { - return _$scope.isAddingComment = false; - }); - return _$scope.CommentContent = ''; - } - }; - this._$scope.sendComment = function(event) { - if (event.keyCode === 13) { - return _$scope.addComment(); - } - }; - this._$scope.deleteComment = function(commentID) { - return _tasksbusinesslayer.deleteComment(_$scope.route.taskID, commentID); - }; - this._$scope.commentStrings = function() { - return { - button: t('tasks', 'Comment'), - input: t('tasks', 'Add a comment') - }; - }; - this._$scope.addCategory = function(category, model) { - var categories; - _tasksbusinesslayer.addCategory(_$scope.route.taskID, category); - categories = _$scope.settingsmodel.getById('various').categories; - if (!(categories.indexOf(category) > -1)) { - return categories.push(category); - } - }; - this._$scope.removeCategory = function(category, model) { - _tasksbusinesslayer.removeCategory(_$scope.route.taskID, category); - return _$scope.resetRoute(); - }; - } + } else { + if (newVal.name !== oldVal.name) { + if (_$scope.timers['task' + newVal.id + 'name']) { + $timeout.cancel(_$scope.timers['task' + newVal.id + 'name']); + } + _$scope.timers['task' + newVal.id + 'name'] = $timeout(function() { + return _tasksbusinesslayer.setTaskName(newVal.id, newVal.name); + }, 3000); + } + if (newVal.note !== oldVal.note) { + if (_$scope.timers['task' + newVal.id + 'note']) { + $timeout.cancel(_$scope.timers['task' + newVal.id + 'note']); + } + _$scope.timers['task' + newVal.id + 'note'] = $timeout(function() { + return _tasksbusinesslayer.setTaskNote(newVal.id, newVal.note); + }, 5000); + } + if (newVal.complete !== oldVal.complete) { + if (_$scope.timers['task' + newVal.id + 'complete']) { + $timeout.cancel(_$scope.timers['task' + newVal.id + 'complete']); + } + _$scope.timers['task' + newVal.id + 'complete'] = $timeout(function() { + return _tasksbusinesslayer.setPercentComplete(newVal.id, newVal.complete); + }, 1000); + } + if (newVal.priority !== oldVal.priority) { + if (_$scope.timers['task' + newVal.id + 'priority']) { + $timeout.cancel(_$scope.timers['task' + newVal.id + 'priority']); + } + return _$scope.timers['task' + newVal.id + 'priority'] = $timeout(function() { + return _tasksbusinesslayer.setPriority(newVal.id, newVal.priority); + }, 1000); + } + } + }, true); + this._$scope.setstartday = function(date) { + return _tasksbusinesslayer.setStart(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); + }; + this._$scope.setstarttime = function(date) { + return _tasksbusinesslayer.setStart(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); + }; + this._$scope.setdueday = function(date) { + return _tasksbusinesslayer.setDue(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); + }; + this._$scope.setduetime = function(date) { + return _tasksbusinesslayer.setDue(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); + }; + this._$scope.setreminderday = function(date) { + return _tasksbusinesslayer.setReminderDate(_$scope.route.taskID, moment(date, 'MM/DD/YYYY'), 'day'); + }; + this._$scope.setremindertime = function(date) { + return _tasksbusinesslayer.setReminderDate(_$scope.route.taskID, moment(date, 'HH:mm'), 'time'); + }; + this._$scope.reminderType = function(task) { + if (!angular.isUndefined(task)) { + if (task.reminder === null) { + if (moment(task.start, "YYYYMMDDTHHmmss").isValid() || moment(task.due, "YYYYMMDDTHHmmss").isValid()) { + return 'DURATION'; + } else { + return 'DATE-TIME'; + } + } else { + return task.reminder.type; + } + } + }; + this._$scope.changeReminderType = function(task) { + _tasksbusinesslayer.checkReminderDate(task.id); + if (this.reminderType(task) === 'DURATION') { + if (task.reminder) { + task.reminder.type = 'DATE-TIME'; + } else { + task.reminder = { + type: 'DATE-TIME' + }; + } + } else { + if (task.reminder) { + task.reminder.type = 'DURATION'; + } else { + task.reminder = { + type: 'DURATION' + }; + } + } + return _tasksbusinesslayer.setReminder(task.id); + }; + this._$scope.setReminderDuration = function(taskID) { + return _tasksbusinesslayer.setReminder(_$scope.route.taskID); + }; + this._$scope.addComment = function() { + var comment, + _this = this; + if (_$scope.CommentContent) { + _$scope.isAddingComment = true; + comment = { + tmpID: 'newComment' + Date.now(), + comment: _$scope.CommentContent, + taskID: _$scope.route.taskID, + time: moment().format('YYYYMMDDTHHmmss'), + name: $('#expandDisplayName').text() + }; + _tasksbusinesslayer.addComment(comment, function(data) { + _$tasksmodel.updateComment(data); + return _$scope.isAddingComment = false; + }, function() { + return _$scope.isAddingComment = false; + }); + return _$scope.CommentContent = ''; + } + }; + this._$scope.sendComment = function(event) { + if (event.keyCode === 13) { + return _$scope.addComment(); + } + }; + this._$scope.deleteComment = function(commentID) { + return _tasksbusinesslayer.deleteComment(_$scope.route.taskID, commentID); + }; + this._$scope.commentStrings = function() { + return { + button: t('tasks', 'Comment'), + input: t('tasks', 'Add a comment') + }; + }; + this._$scope.addCategory = function(category, model) { + var categories; + _tasksbusinesslayer.addCategory(_$scope.route.taskID, category); + categories = _$scope.settingsmodel.getById('various').categories; + if (!(categories.indexOf(category) > -1)) { + return categories.push(category); + } + }; + this._$scope.removeCategory = function(category, model) { + _tasksbusinesslayer.removeCategory(_$scope.route.taskID, category); + return _$scope.resetRoute(); + }; + } - return DetailsController; + return DetailsController; - })(); - return new DetailsController($scope, $window, TasksModel, TasksBusinessLayer, $route, $location, $timeout, $routeParams, SettingsModel, Loading); - } + })(); + return new DetailsController($scope, $window, TasksModel, TasksBusinessLayer, $route, $location, $timeout, $routeParams, SettingsModel, Loading); + } ]); }).call(this); (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; - }; - } + '$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 ListController; - })(); - return new ListController($scope, $window, $routeParams, ListsModel, TasksBusinessLayer, CollectionsModel, ListsBusinessLayer, $location, SearchBusinessLayer, CalendarService); - } + })(); + return new ListController($scope, $window, $routeParams, ListsModel, TasksBusinessLayer, CollectionsModel, ListsBusinessLayer, $location, SearchBusinessLayer, CalendarService); + } ]); }).call(this); @@ -986,361 +836,666 @@ var __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').controller('TasksController', [ - '$scope', '$window', '$routeParams', 'TasksModel', 'ListsModel', 'CollectionsModel', 'TasksBusinessLayer', '$location', 'SettingsBusinessLayer', 'SearchBusinessLayer', function($scope, $window, $routeParams, TasksModel, ListsModel, CollectionsModel, TasksBusinessLayer, $location, SettingsBusinessLayer, SearchBusinessLayer) { - var TasksController; - TasksController = (function() { - function TasksController(_$scope, _$window, _$routeParams, _$tasksmodel, _$listsmodel, _$collectionsmodel, _tasksbusinesslayer, $location, _settingsbusinesslayer, _searchbusinesslayer) { - var _this = this; - this._$scope = _$scope; - this._$window = _$window; - this._$routeParams = _$routeParams; - this._$tasksmodel = _$tasksmodel; - this._$listsmodel = _$listsmodel; - this._$collectionsmodel = _$collectionsmodel; - this._tasksbusinesslayer = _tasksbusinesslayer; - this.$location = $location; - this._settingsbusinesslayer = _settingsbusinesslayer; - this._searchbusinesslayer = _searchbusinesslayer; - this._$scope.tasks = this._$tasksmodel.getAll(); - this._$scope.draggedTasks = []; - this._$scope.lists = this._$listsmodel.getAll(); - this._$scope.days = [0, 1, 2, 3, 4, 5, 6]; - this._$scope.isAddingTask = false; - this._$scope.focusInputField = false; - this._$scope.TasksModel = this._$tasksmodel; - this._$scope.TasksBusinessLayer = this._tasksbusinesslayer; - this._$scope.getAddString = function() { - var calendar; - if (angular.isDefined(calendar = _$listsmodel.getStandardList())) { - if (angular.isDefined(_$scope.route.collectionID)) { - switch (_$scope.route.collectionID) { - case 'starred': - return t('tasks', 'Add an important item in "%s"...').replace('%s', calendar.displayname); - case 'today': - return t('tasks', 'Add an item due today in "%s"...').replace('%s', calendar.displayname); - case 'all': - return t('tasks', 'Add an item in "%s"...').replace('%s', calendar.displayname); - case 'current': - return t('tasks', 'Add a current item in "%s"...').replace('%s', calendar.displayname); - case 'completed': - case 'week': - return null; - } - } else { - if (angular.isDefined(_$listsmodel.getByUri(_$scope.route.calendarID))) { - return t('tasks', 'Add an item in "%s"...').replace('%s', _$listsmodel.getByUri(_$scope.route.calendarID).displayname); - } - } - } - }; - this._$scope.getSubAddString = function(taskname) { - return t('tasks', 'Add a subtask to "%s"...').replace('%s', taskname); - }; - this._$scope.showSubtaskInput = function(uid) { - return _$scope.status.addSubtaskTo = uid; - }; - this._$scope.hideSubtasks = function(task) { - var descendants, _ref; - descendants = _$tasksmodel.getDescendantID(task.id); - if (task.id === _$scope.route.taskID) { - return false; - } else if (_ref = _$scope.route.taskID, __indexOf.call(descendants, _ref) >= 0) { - return false; - } else { - return task.hidesubtasks; - } - }; - this._$scope.showInput = function() { - var _ref; - if ((_ref = _$scope.route.listID) === 'completed' || _ref === 'week') { - return false; - } else { - return true; - } - }; - this._$scope.focusTaskInput = function() { - return _$scope.status.focusTaskInput = true; - }; - this._$scope.focusSubtaskInput = function() { - return _$scope.status.focusSubtaskInput = true; - }; - this._$scope.openDetails = function(id, $event) { - var listID; - if ($($event.currentTarget).is($($event.target).closest('.handler'))) { - listID = _$scope.route.listID; - return $location.path('/lists/' + listID + '/tasks/' + id); - } - }; - this._$scope.toggleCompleted = function(taskID) { - if (_$tasksmodel.completed(taskID)) { - return _tasksbusinesslayer.uncompleteTask(taskID); - } else { - return _tasksbusinesslayer.completeTask(taskID); - } - }; - this._$scope.toggleStarred = function(taskID) { - if (_$tasksmodel.starred(taskID)) { - return _tasksbusinesslayer.unstarTask(taskID); - } else { - _$tasksmodel.star(taskID); - return _tasksbusinesslayer.starTask(taskID); - } - }; - this._$scope.toggleHidden = function() { - return _settingsbusinesslayer.toggle('various', 'showHidden'); - }; - this._$scope.filterTasks = function(task, filter) { - return function(task) { - return _$tasksmodel.filterTasks(task, filter); - }; - }; - this._$scope.getSubTasks = function(tasks, parent) { - var ret, task, _i, _len; - ret = []; - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - if (task.related === parent.uid) { - ret.push(task); - } - } - return ret; - }; - this._$scope.hasNoParent = function(task) { - return function(task) { - return _$tasksmodel.hasNoParent(task); - }; - }; - this._$scope.hasSubtasks = function(task) { - return _$tasksmodel.hasSubtasks(task.uid); - }; - this._$scope.toggleSubtasks = function(taskID) { - if (_$tasksmodel.hideSubtasks(taskID)) { - return _tasksbusinesslayer.unhideSubtasks(taskID); - } else { - return _tasksbusinesslayer.hideSubtasks(taskID); - } - }; - this._$scope.filterTasksByString = function(task) { - return function(task) { - var filter; - filter = _searchbusinesslayer.getFilter(); - return _$tasksmodel.filterTasksByString(task, filter); - }; - }; - this._$scope.filteredTasks = function() { - var filter; - filter = _searchbusinesslayer.getFilter(); - return _$tasksmodel.filteredTasks(filter); - }; - this._$scope.dayHasEntry = function() { - return function(date) { - var filter, task, tasks, _i, _len; - filter = _searchbusinesslayer.getFilter(); - tasks = _$tasksmodel.filteredTasks(filter); - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - if (task.completed || !_$tasksmodel.hasNoParent(task)) { - continue; - } - if (_$tasksmodel.taskAtDay(task, date)) { - return true; - } - } - return false; - }; - }; - this._$scope.taskAtDay = function(task, day) { - return function(task) { - return _$tasksmodel.taskAtDay(task, day); - }; - }; - this._$scope.filterLists = function() { - return function(list) { - return _$scope.getCount(list.id, _$scope.route.listID); - }; - }; - this._$scope.getCount = function(listID, type) { - var filter; - filter = _searchbusinesslayer.getFilter(); - return _$listsmodel.getCount(listID, type, filter); - }; - this._$scope.getCountString = function(listID, type) { - var filter; - filter = _searchbusinesslayer.getFilter(); - return n('tasks', '%n Completed Task', '%n Completed Tasks', _$listsmodel.getCount(listID, type, filter)); - }; - this._$scope.addTask = function(taskName, related, calendarid) { - var task, _ref, - _this = this; - if (related == null) { - related = ''; - } - if (calendarid == null) { - calendarid = ''; - } - _$scope.isAddingTask = true; - task = { - tmpID: 'newTask' + Date.now(), - id: 'newTask' + Date.now(), - calendarid: null, - related: related, - name: taskName, - starred: false, - priority: '0', - due: false, - start: false, - reminder: null, - completed: false, - complete: '0', - note: false - }; - if (((_ref = _$scope.route.listID) === 'starred' || _ref === 'today' || _ref === 'week' || _ref === 'all' || _ref === 'completed' || _ref === 'current')) { - if (related) { - task.calendarid = calendarid; - } else { - task.calendarid = _$listsmodel.getStandardList(); - } - if (_$scope.route.listID === 'starred') { - task.starred = true; - } - if (_$scope.route.listID === 'today') { - task.due = moment().startOf('day').format("YYYYMMDDTHHmmss"); - } - if (_$scope.route.listID === 'current') { - task.start = moment().format("YYYYMMDDTHHmmss"); - } - } else { - task.calendarid = _$scope.route.listID; - } - _tasksbusinesslayer.addTask(task, function(data) { - _$tasksmodel.add(data); - return _$scope.isAddingTask = false; - }, function() { - return _$scope.isAddingTask = false; - }); - _$scope.status.focusTaskInput = false; - _$scope.status.focusSubtaskInput = false; - _$scope.status.addSubtaskTo = ''; - _$scope.status.taskName = ''; - return _$scope.status.subtaskName = ''; - }; - this._$scope.checkTaskInput = function($event) { - if ($event.keyCode === 27) { - $($event.currentTarget).blur(); - _$scope.status.taskName = ''; - _$scope.status.subtaskName = ''; - _$scope.status.addSubtaskTo = ''; - _$scope.status.focusTaskInput = false; - return _$scope.status.focusSubtaskInput = false; - } - }; - this._$scope.getCompletedTasks = function(listID) { - return _tasksbusinesslayer.getCompletedTasks(listID); - }; - this._$scope.loadedAll = function(listID) { - return _$listsmodel.loadedAll(listID); - }; - this._$scope.sortDue = function(task) { - if (task.due === null) { - return 'last'; - } else { - return task.due; - } - }; - this._$scope.getTaskColor = function(listID) { - return _$listsmodel.getColor(listID); - }; - this._$scope.getTaskList = function(listID) { - return _$listsmodel.getName(listID); - }; - this._$scope.dropCallback = function($event, item, index) { - var collectionID, listID, parentID, taskID; - taskID = item.id; - $('.subtasks-container').removeClass('dropzone-visible'); - parentID = $('li.dndPlaceholder').closest('.task-item').attr('taskID'); - parentID = parentID || ""; - if (parentID === taskID) { - parentID = ""; - } - collectionID = $('li.dndPlaceholder').closest('ol[dnd-list]').attr('collectionID'); - if (collectionID) { - _tasksbusinesslayer.changeCollection(taskID, collectionID); - } - listID = $('li.dndPlaceholder').closest('ol[dnd-list]').attr('listID'); - if (listID) { - _tasksbusinesslayer.changeCalendarId(taskID, listID); - } - _tasksbusinesslayer.changeParent(taskID, parentID, collectionID); - return true; - }; - this._$scope.dragover = function($event, item, index) { - $('.subtasks-container').removeClass('dropzone-visible'); - $($event.target).closest('.task-item').children('.subtasks-container').addClass('dropzone-visible'); - return true; - }; - } + '$scope', '$window', '$routeParams', 'TasksModel', 'ListsModel', 'CollectionsModel', 'TasksBusinessLayer', '$location', 'SettingsBusinessLayer', 'SearchBusinessLayer', function($scope, $window, $routeParams, TasksModel, ListsModel, CollectionsModel, TasksBusinessLayer, $location, SettingsBusinessLayer, SearchBusinessLayer) { + var TasksController; + TasksController = (function() { + function TasksController(_$scope, _$window, _$routeParams, _$tasksmodel, _$listsmodel, _$collectionsmodel, _tasksbusinesslayer, $location, _settingsbusinesslayer, _searchbusinesslayer) { + var _this = this; + this._$scope = _$scope; + this._$window = _$window; + this._$routeParams = _$routeParams; + this._$tasksmodel = _$tasksmodel; + this._$listsmodel = _$listsmodel; + this._$collectionsmodel = _$collectionsmodel; + this._tasksbusinesslayer = _tasksbusinesslayer; + this.$location = $location; + this._settingsbusinesslayer = _settingsbusinesslayer; + this._searchbusinesslayer = _searchbusinesslayer; + this._$scope.tasks = this._$tasksmodel.getAll(); + this._$scope.draggedTasks = []; + this._$scope.lists = this._$listsmodel.getAll(); + this._$scope.days = [0, 1, 2, 3, 4, 5, 6]; + this._$scope.isAddingTask = false; + this._$scope.focusInputField = false; + this._$scope.TasksModel = this._$tasksmodel; + this._$scope.TasksBusinessLayer = this._tasksbusinesslayer; + this._$scope.getAddString = function() { + var calendar; + if (angular.isDefined(calendar = _$listsmodel.getStandardList())) { + if (angular.isDefined(_$scope.route.collectionID)) { + switch (_$scope.route.collectionID) { + case 'starred': + return t('tasks', 'Add an important item in "%s"...').replace('%s', calendar.displayname); + case 'today': + return t('tasks', 'Add an item due today in "%s"...').replace('%s', calendar.displayname); + case 'all': + return t('tasks', 'Add an item in "%s"...').replace('%s', calendar.displayname); + case 'current': + return t('tasks', 'Add a current item in "%s"...').replace('%s', calendar.displayname); + case 'completed': + case 'week': + return null; + } + } else { + if (angular.isDefined(_$listsmodel.getByUri(_$scope.route.calendarID))) { + return t('tasks', 'Add an item in "%s"...').replace('%s', _$listsmodel.getByUri(_$scope.route.calendarID).displayname); + } + } + } + }; + this._$scope.getSubAddString = function(taskname) { + return t('tasks', 'Add a subtask to "%s"...').replace('%s', taskname); + }; + this._$scope.showSubtaskInput = function(uid) { + return _$scope.status.addSubtaskTo = uid; + }; + this._$scope.hideSubtasks = function(task) { + var descendants, _ref; + descendants = _$tasksmodel.getDescendantID(task.id); + if (task.id === _$scope.route.taskID) { + return false; + } else if (_ref = _$scope.route.taskID, __indexOf.call(descendants, _ref) >= 0) { + return false; + } else { + return task.hidesubtasks; + } + }; + this._$scope.showInput = function() { + var _ref; + if ((_ref = _$scope.route.listID) === 'completed' || _ref === 'week') { + return false; + } else { + return true; + } + }; + this._$scope.focusTaskInput = function() { + return _$scope.status.focusTaskInput = true; + }; + this._$scope.focusSubtaskInput = function() { + return _$scope.status.focusSubtaskInput = true; + }; + this._$scope.openDetails = function(id, $event) { + var listID; + if ($($event.currentTarget).is($($event.target).closest('.handler'))) { + listID = _$scope.route.listID; + return $location.path('/lists/' + listID + '/tasks/' + id); + } + }; + this._$scope.toggleCompleted = function(taskID) { + if (_$tasksmodel.completed(taskID)) { + return _tasksbusinesslayer.uncompleteTask(taskID); + } else { + return _tasksbusinesslayer.completeTask(taskID); + } + }; + this._$scope.toggleStarred = function(taskID) { + if (_$tasksmodel.starred(taskID)) { + return _tasksbusinesslayer.unstarTask(taskID); + } else { + _$tasksmodel.star(taskID); + return _tasksbusinesslayer.starTask(taskID); + } + }; + this._$scope.toggleHidden = function() { + return _settingsbusinesslayer.toggle('various', 'showHidden'); + }; + this._$scope.filterTasks = function(task, filter) { + return function(task) { + return _$tasksmodel.filterTasks(task, filter); + }; + }; + this._$scope.getSubTasks = function(tasks, parent) { + var ret, task, _i, _len; + ret = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.related === parent.uid) { + ret.push(task); + } + } + return ret; + }; + this._$scope.hasNoParent = function(task) { + return function(task) { + return _$tasksmodel.hasNoParent(task); + }; + }; + this._$scope.hasSubtasks = function(task) { + return _$tasksmodel.hasSubtasks(task.uid); + }; + this._$scope.toggleSubtasks = function(taskID) { + if (_$tasksmodel.hideSubtasks(taskID)) { + return _tasksbusinesslayer.unhideSubtasks(taskID); + } else { + return _tasksbusinesslayer.hideSubtasks(taskID); + } + }; + this._$scope.filterTasksByString = function(task) { + return function(task) { + var filter; + filter = _searchbusinesslayer.getFilter(); + return _$tasksmodel.filterTasksByString(task, filter); + }; + }; + this._$scope.filteredTasks = function() { + var filter; + filter = _searchbusinesslayer.getFilter(); + return _$tasksmodel.filteredTasks(filter); + }; + this._$scope.dayHasEntry = function() { + return function(date) { + var filter, task, tasks, _i, _len; + filter = _searchbusinesslayer.getFilter(); + tasks = _$tasksmodel.filteredTasks(filter); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.completed || !_$tasksmodel.hasNoParent(task)) { + continue; + } + if (_$tasksmodel.taskAtDay(task, date)) { + return true; + } + } + return false; + }; + }; + this._$scope.taskAtDay = function(task, day) { + return function(task) { + return _$tasksmodel.taskAtDay(task, day); + }; + }; + this._$scope.filterLists = function() { + return function(list) { + return _$scope.getCount(list.id, _$scope.route.listID); + }; + }; + this._$scope.getCount = function(listID, type) { + var filter; + filter = _searchbusinesslayer.getFilter(); + return _$listsmodel.getCount(listID, type, filter); + }; + this._$scope.getCountString = function(listID, type) { + var filter; + filter = _searchbusinesslayer.getFilter(); + return n('tasks', '%n Completed Task', '%n Completed Tasks', _$listsmodel.getCount(listID, type, filter)); + }; + this._$scope.addTask = function(taskName, related, calendarid) { + var task, _ref, + _this = this; + if (related == null) { + related = ''; + } + if (calendarid == null) { + calendarid = ''; + } + _$scope.isAddingTask = true; + task = { + tmpID: 'newTask' + Date.now(), + id: 'newTask' + Date.now(), + calendarid: null, + related: related, + name: taskName, + starred: false, + priority: '0', + due: false, + start: false, + reminder: null, + completed: false, + complete: '0', + note: false + }; + if (((_ref = _$scope.route.listID) === 'starred' || _ref === 'today' || _ref === 'week' || _ref === 'all' || _ref === 'completed' || _ref === 'current')) { + if (related) { + task.calendarid = calendarid; + } else { + task.calendarid = _$listsmodel.getStandardList(); + } + if (_$scope.route.listID === 'starred') { + task.starred = true; + } + if (_$scope.route.listID === 'today') { + task.due = moment().startOf('day').format("YYYYMMDDTHHmmss"); + } + if (_$scope.route.listID === 'current') { + task.start = moment().format("YYYYMMDDTHHmmss"); + } + } else { + task.calendarid = _$scope.route.listID; + } + _tasksbusinesslayer.addTask(task, function(data) { + _$tasksmodel.add(data); + return _$scope.isAddingTask = false; + }, function() { + return _$scope.isAddingTask = false; + }); + _$scope.status.focusTaskInput = false; + _$scope.status.focusSubtaskInput = false; + _$scope.status.addSubtaskTo = ''; + _$scope.status.taskName = ''; + return _$scope.status.subtaskName = ''; + }; + this._$scope.checkTaskInput = function($event) { + if ($event.keyCode === 27) { + $($event.currentTarget).blur(); + _$scope.status.taskName = ''; + _$scope.status.subtaskName = ''; + _$scope.status.addSubtaskTo = ''; + _$scope.status.focusTaskInput = false; + return _$scope.status.focusSubtaskInput = false; + } + }; + this._$scope.getCompletedTasks = function(listID) { + return _tasksbusinesslayer.getCompletedTasks(listID); + }; + this._$scope.loadedAll = function(listID) { + return _$listsmodel.loadedAll(listID); + }; + this._$scope.sortDue = function(task) { + if (task.due === null) { + return 'last'; + } else { + return task.due; + } + }; + this._$scope.getTaskColor = function(listID) { + return _$listsmodel.getColor(listID); + }; + this._$scope.getTaskList = function(listID) { + return _$listsmodel.getName(listID); + }; + this._$scope.dropCallback = function($event, item, index) { + var collectionID, listID, parentID, taskID; + taskID = item.id; + $('.subtasks-container').removeClass('dropzone-visible'); + parentID = $('li.dndPlaceholder').closest('.task-item').attr('taskID'); + parentID = parentID || ""; + if (parentID === taskID) { + parentID = ""; + } + collectionID = $('li.dndPlaceholder').closest('ol[dnd-list]').attr('collectionID'); + if (collectionID) { + _tasksbusinesslayer.changeCollection(taskID, collectionID); + } + listID = $('li.dndPlaceholder').closest('ol[dnd-list]').attr('listID'); + if (listID) { + _tasksbusinesslayer.changeCalendarId(taskID, listID); + } + _tasksbusinesslayer.changeParent(taskID, parentID, collectionID); + return true; + }; + this._$scope.dragover = function($event, item, index) { + $('.subtasks-container').removeClass('dropzone-visible'); + $($event.target).closest('.task-item').children('.subtasks-container').addClass('dropzone-visible'); + return true; + }; + } - return TasksController; + return TasksController; - })(); - return new TasksController($scope, $window, $routeParams, TasksModel, ListsModel, CollectionsModel, TasksBusinessLayer, $location, SettingsBusinessLayer, SearchBusinessLayer); - } + })(); + return new TasksController($scope, $window, $routeParams, TasksModel, ListsModel, CollectionsModel, TasksBusinessLayer, $location, SettingsBusinessLayer, SearchBusinessLayer); + } + ]); + +}).call(this); + +angular.module('Tasks').directive('appNavigationEntryUtils', function() { + 'use strict'; + return { + restrict: 'C', + link: function(scope, elm) { + var button, menu; + menu = elm.siblings('.app-navigation-entry-menu'); + button = $(elm).find('.app-navigation-entry-utils-menu-button button'); + button.click(function() { + menu.toggleClass('open'); + }); + scope.$on('documentClicked', function(scope, event) { + if (event.target !== button[0]) { + menu.removeClass('open'); + } + }); + } + }; +}); + +angular.module('Tasks').directive('autofocusOnInsert', function() { + 'use strict'; + return function(scope, elm) { + return elm.focus(); + }; +}); + +angular.module('Tasks').directive('avatar', function() { + return { + restrict: 'A', + scope: false, + link: function(scope, elm, attr) { + return attr.$observe('userid', function() { + if (attr.userid) { + return elm.avatar(attr.userid, attr.size); + } + }); + } + }; +}); + +(function() { + angular.module('Tasks').directive('datepicker', function() { + return { + restrict: 'A', + scope: false, + link: function(scope, elm, attr) { + return elm.datepicker({ + onSelect: function(date, inst) { + scope['set' + attr.datepicker + 'day'](date); + return scope.$apply(); + }, + beforeShow: function(input, inst) { + var dp, marginLeft; + dp = $(inst).datepicker('widget'); + marginLeft = -Math.abs($(input).outerWidth() - dp.outerWidth()) / 2 + 'px'; + dp.css({ + 'margin-left': marginLeft + }); + $("div.ui-datepicker:before").css({ + 'left': 100 + 'px' + }); + return $('.hasDatepicker').datepicker("option", "firstDay", scope.settingsmodel.getById('various').startOfWeek); + }, + beforeShowDay: function(date) { + if (moment(date).startOf('day').diff(moment(scope.task[attr.datepicker], "YYYYMMDDTHHmmss").startOf('day'), 'days') === 0) { + return [1, "selected"]; + } else { + return [1, ""]; + } + }, + minDate: null + }); + } + }; + }); + +}).call(this); + +(function() { + angular.module('Tasks').directive('ocClickFocus', [ + '$timeout', function($timeout) { + return function(scope, elm, attr) { + var options; + options = scope.$eval(attr.ocClickFocus); + if (angular.isDefined(options) && angular.isDefined(options.selector)) { + return elm.click(function() { + if (angular.isDefined(options.timeout)) { + return $timeout(function() { + return $(options.selector).focus(); + }, options.timeout); + } else { + return $(options.selector).focus(); + } + }); + } + }; + } ]); }).call(this); (function() { + angular.module('Tasks').directive('timepicker', function() { + return { + restrict: 'A', + link: function(scope, elm, attr) { + return elm.timepicker({ + onSelect: function(date, inst) { + scope['set' + attr.timepicker + 'time'](date); + return scope.$apply(); + }, + myPosition: 'center top', + atPosition: 'center bottom', + hourText: t('tasks', 'Hours'), + minuteText: t('tasks', 'Minutes') + }); + } + }; + }); + +}).call(this); + +angular.module('Tasks').directive('watchTop', function() { + return { + restrict: 'A', + link: function(scope, element, attr) { + ({ + scope: { + "divTop": "=" + } + }); + return scope.$watch(function() { + return scope.divTop = element.prev().outerHeight(true); + }); + } + }; +}); + +angular.module('Tasks').filter('counterFormatter', function() { + return function(count) { + switch (false) { + case count !== 0: + return ''; + case !(count > 999): + return '999+'; + default: + return count; + } + }; +}); + +angular.module('Tasks').filter('dateDetails', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").locale('details').calendar(); + } else { + return t('tasks', 'Set due date'); + } + }; +}); + +angular.module('Tasks').filter('dateDetailsShort', function() { + return function(reminder) { + if (moment(reminder, "YYYYMMDDTHHmmss").isValid()) { + return moment(reminder, "YYYYMMDDTHHmmss").locale('details_short').calendar(); + } else { + return ''; + } + }; +}); + +angular.module('Tasks').filter('dateFromNow', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").fromNow(); + } else { + return ''; + } + }; +}); + +angular.module('Tasks').filter('dateTaskList', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").locale('tasks').calendar(); + } else { + return ''; + } + }; +}); + +angular.module('Tasks').filter('day', function() { + return function(i) { + return moment().add('days', i).locale('list_week').calendar(); + }; +}); + +angular.module('Tasks').filter('dayTaskList', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").locale('tasks').calendar(); + } else { + return ''; + } + }; +}); + +angular.module('Tasks').filter('percentDetails', function() { + return function(percent) { + return t('tasks', '%s %% completed').replace('%s', percent).replace('%%', '%'); + }; +}); + +angular.module('Tasks').filter('priorityDetails', function() { + return function(priority) { + var string; + string = t('tasks', 'priority %s: ').replace('%s', priority); + if (+priority === 6 || +priority === 7 || +priority === 8 || +priority === 9) { + return string + ' ' + t('tasks', 'high'); + } else if (+priority === 5) { + return string + ' ' + t('tasks', 'medium'); + } else if (+priority === 1 || +priority === 2 || +priority === 3 || +priority === 4) { + return string + ' ' + t('tasks', 'low'); + } else { + return t('tasks', 'no priority assigned'); + } + }; +}); + +(function() { + angular.module('Tasks').filter('reminderDetails', function() { + return function(reminder, scope) { + var ds, time, token, _i, _len, _ref; + if (!(angular.isUndefined(reminder) || reminder === null)) { + if (reminder.type === 'DATE-TIME' && moment(reminder.date, "YYYYMMDDTHHmmss").isValid()) { + return moment(reminder.date, "YYYYMMDDTHHmmss").locale('reminder').calendar(); + } else if (reminder.type === 'DURATION' && reminder.duration) { + ds = t('tasks', 'Remind me'); + _ref = scope.durations; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + token = _ref[_i]; + if (+reminder.duration[token.id]) { + time = 1; + ds += ' ' + reminder.duration[token.id] + ' '; + if (+reminder.duration[token.id] === 1) { + ds += token.name; + } else { + ds += token.names; + } + } + } + if (!time) { + if (reminder.duration.params.related === 'END') { + ds += ' ' + t('tasks', 'at the end'); + } else { + ds += ' ' + t('tasks', 'at the beginning'); + } + } else { + if (reminder.duration.params.invert) { + if (reminder.duration.params.related === 'END') { + ds += ' ' + t('tasks', 'before end'); + } else { + ds += ' ' + t('tasks', 'before beginning'); + } + } else { + if (reminder.duration.params.related === 'END') { + ds += ' ' + t('tasks', 'after end'); + } else { + ds += ' ' + t('tasks', 'after beginning'); + } + } + } + return ds; + } else { + return t('tasks', 'Remind me'); + } + } else { + return t('tasks', 'Remind me'); + } + }; + }); + +}).call(this); + +angular.module('Tasks').filter('startDetails', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").locale('start').calendar(); + } else { + return t('tasks', 'Set start date'); + } + }; +}); + +angular.module('Tasks').filter('timeTaskList', function() { + return function(due) { + if (moment(due, "YYYYMMDDTHHmmss").isValid()) { + return moment(due, "YYYYMMDDTHHmmss").format('HH:mm'); + } else { + return ''; + } + }; +}); + +(function() { angular.module('Tasks').factory('ListsBusinessLayer', [ - 'ListsModel', 'Persistence', 'TasksBusinessLayer', 'CalendarService', function(ListsModel, Persistence, TasksBusinessLayer, CalendarService) { - var ListsBusinessLayer; - ListsBusinessLayer = (function() { - function ListsBusinessLayer(_$listsmodel, _persistence, _$tasksbusinesslayer, _$calendarservice) { - this._$listsmodel = _$listsmodel; - this._persistence = _persistence; - this._$tasksbusinesslayer = _$tasksbusinesslayer; - this._$calendarservice = _$calendarservice; - } + 'ListsModel', 'Persistence', 'TasksBusinessLayer', 'CalendarService', function(ListsModel, Persistence, TasksBusinessLayer, CalendarService) { + var ListsBusinessLayer; + ListsBusinessLayer = (function() { + function ListsBusinessLayer(_$listsmodel, _persistence, _$tasksbusinesslayer, _$calendarservice) { + this._$listsmodel = _$listsmodel; + this._persistence = _persistence; + this._$tasksbusinesslayer = _$tasksbusinesslayer; + this._$calendarservice = _$calendarservice; + } - ListsBusinessLayer.prototype.init = function() { - return this._$calendarservice.getAll().then(function(calendars) { - var calendar, _i, _len, _results; - _results = []; - for (_i = 0, _len = calendars.length; _i < _len; _i++) { - calendar = calendars[_i]; - _results.push(ListsModel.add(calendar)); - } - return _results; - }); - }; - - ListsBusinessLayer.prototype.add = function(calendar, onSuccess, onFailure) { - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - return this._$calendarservice.create(calendar, '#FF7A66', ['vtodo']).then(function(calendar) { - ListsModel.add(calendar); - return calendar; - }); - }; - - ListsBusinessLayer.prototype["delete"] = function(calendar) { - return this._$calendarservice["delete"](calendar).then(function() { - return ListsModel["delete"](calendar); - }); - }; - - ListsBusinessLayer.prototype.rename = function(calendar) { - return this._persistence.setListName(this._$listsmodel.getById(listID)); - }; - - return ListsBusinessLayer; + ListsBusinessLayer.prototype.init = function() { + return this._$calendarservice.getAll().then(function(calendars) { + var calendar, _i, _len, _results; + _results = []; + for (_i = 0, _len = calendars.length; _i < _len; _i++) { + calendar = calendars[_i]; + _results.push(ListsModel.add(calendar)); + } + return _results; + }); + }; - })(); - return new ListsBusinessLayer(ListsModel, Persistence, TasksBusinessLayer, CalendarService); - } + ListsBusinessLayer.prototype.add = function(calendar, onSuccess, onFailure) { + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + return this._$calendarservice.create(calendar, '#FF7A66', ['vtodo']).then(function(calendar) { + ListsModel.add(calendar); + return calendar; + }); + }; + + ListsBusinessLayer.prototype["delete"] = function(calendar) { + return this._$calendarservice["delete"](calendar).then(function() { + return ListsModel["delete"](calendar); + }); + }; + + ListsBusinessLayer.prototype.rename = function(calendar) { + return this._persistence.setListName(this._$listsmodel.getById(listID)); + }; + + return ListsBusinessLayer; + + })(); + return new ListsBusinessLayer(ListsModel, Persistence, TasksBusinessLayer, CalendarService); + } ]); }).call(this); @@ -1349,680 +1504,680 @@ 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.attach = __bind(this.attach, this); - this.initialize(); - this._$searchString = ''; - } + '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.attach = __bind(this.attach, this); + this.initialize(); + this._$searchString = ''; + } - SearchBusinessLayer.prototype.attach = function(search) { - var _this = this; - search.setFilter('tasks', function(query) { - return _this._$rootScope.$apply(function() { - return _this.setFilter(query); - }); - }); - search.setRenderer('task', this.renderTaskResult.bind(this)); - return search.setHandler('task', this.handleTaskClick.bind(this)); - }; - - SearchBusinessLayer.prototype.setFilter = function(query) { - return this._$searchString = query; - }; - - SearchBusinessLayer.prototype.getFilter = function() { - return this._$searchString; - }; - - SearchBusinessLayer.prototype.initialize = function() { - var _this = this; - this.handleTaskClick = function($row, result, event) { - return _this._$location.path('/lists/' + result.calendarid + '/tasks/' + result.id); - }; - this.renderTaskResult = function($row, result) { - var $template; - if (!_this._$tasksmodel.filterTasks(result, _this._$routeparams.listID) || !_this._$tasksmodel.isLoaded(result)) { - $template = $('div.task-item.template'); - $template = $template.clone(); - $row = $('<tr class="result"></tr>').append($template.removeClass('template')); - $row.data('result', result); - $row.find('span.title').text(result.name); - if (result.starred) { - $row.find('span.task-star').addClass('task-starred'); - } - if (result.completed) { - $row.find('div.task-item').addClass('done'); - $row.find('span.task-checkbox').addClass('task-checked'); - } - if (result.complete) { - $row.find('div.percentdone').css({ - 'width': result.complete + '%', - 'background-color': '' + _this._$listsmodel.getColor(result.calendarid) - }); - } - if (result.note) { - $row.find('div.title-wrapper').addClass('attachment'); - } - return $row; - } else { - return null; - } - }; - return OC.Plugins.register('OCA.Search', this); - }; + SearchBusinessLayer.prototype.attach = function(search) { + var _this = this; + search.setFilter('tasks', function(query) { + return _this._$rootScope.$apply(function() { + return _this.setFilter(query); + }); + }); + search.setRenderer('task', this.renderTaskResult.bind(this)); + return search.setHandler('task', this.handleTaskClick.bind(this)); + }; - return SearchBusinessLayer; + SearchBusinessLayer.prototype.setFilter = function(query) { + return this._$searchString = query; + }; - })(); - return new SearchBusinessLayer(ListsModel, Persistence, TasksModel, $rootScope, $routeParams, $location); - } + SearchBusinessLayer.prototype.getFilter = function() { + return this._$searchString; + }; + + SearchBusinessLayer.prototype.initialize = function() { + var _this = this; + this.handleTaskClick = function($row, result, event) { + return _this._$location.path('/lists/' + result.calendarid + '/tasks/' + result.id); + }; + this.renderTaskResult = function($row, result) { + var $template; + if (!_this._$tasksmodel.filterTasks(result, _this._$routeparams.listID) || !_this._$tasksmodel.isLoaded(result)) { + $template = $('div.task-item.template'); + $template = $template.clone(); + $row = $('<tr class="result"></tr>').append($template.removeClass('template')); + $row.data('result', result); + $row.find('span.title').text(result.name); + if (result.starred) { + $row.find('span.task-star').addClass('task-starred'); + } + if (result.completed) { + $row.find('div.task-item').addClass('done'); + $row.find('span.task-checkbox').addClass('task-checked'); + } + if (result.complete) { + $row.find('div.percentdone').css({ + 'width': result.complete + '%', + 'background-color': '' + _this._$listsmodel.getColor(result.calendarid) + }); + } + if (result.note) { + $row.find('div.title-wrapper').addClass('attachment'); + } + return $row; + } else { + return null; + } + }; + return OC.Plugins.register('OCA.Search', this); + }; + + return SearchBusinessLayer; + + })(); + return new SearchBusinessLayer(ListsModel, Persistence, TasksModel, $rootScope, $routeParams, $location); + } ]); }).call(this); (function() { angular.module('Tasks').factory('SettingsBusinessLayer', [ - 'Persistence', 'SettingsModel', function(Persistence, SettingsModel) { - var SettingsBusinessLayer; - SettingsBusinessLayer = (function() { - function SettingsBusinessLayer(_persistence, _$settingsmodel) { - this._persistence = _persistence; - this._$settingsmodel = _$settingsmodel; - } + 'Persistence', 'SettingsModel', function(Persistence, SettingsModel) { + var SettingsBusinessLayer; + SettingsBusinessLayer = (function() { + function SettingsBusinessLayer(_persistence, _$settingsmodel) { + this._persistence = _persistence; + this._$settingsmodel = _$settingsmodel; + } - SettingsBusinessLayer.prototype.updateModel = function() { - var success, - _this = this; - success = function() {}; - return this._persistence.getCollections(success, true); - }; + SettingsBusinessLayer.prototype.updateModel = function() { + var success, + _this = this; + success = function() {}; + return this._persistence.getCollections(success, true); + }; - SettingsBusinessLayer.prototype.setVisibility = function(collectionID, visibility) { - return this._persistence.setVisibility(collectionID, visibility); - }; + SettingsBusinessLayer.prototype.setVisibility = function(collectionID, visibility) { + return this._persistence.setVisibility(collectionID, visibility); + }; - SettingsBusinessLayer.prototype.toggle = function(type, setting) { - var value; - this._$settingsmodel.toggle(type, setting); - value = this._$settingsmodel.getById(type)[setting]; - return this._persistence.setting(type, setting, value); - }; + SettingsBusinessLayer.prototype.toggle = function(type, setting) { + var value; + this._$settingsmodel.toggle(type, setting); + value = this._$settingsmodel.getById(type)[setting]; + return this._persistence.setting(type, setting, value); + }; - SettingsBusinessLayer.prototype.set = function(type, setting, value) { - return this._persistence.setting(type, setting, value); - }; + SettingsBusinessLayer.prototype.set = function(type, setting, value) { + return this._persistence.setting(type, setting, value); + }; - return SettingsBusinessLayer; + return SettingsBusinessLayer; - })(); - return new SettingsBusinessLayer(Persistence, SettingsModel); - } + })(); + return new SettingsBusinessLayer(Persistence, SettingsModel); + } ]); }).call(this); (function() { angular.module('Tasks').factory('TasksBusinessLayer', [ - 'TasksModel', 'Persistence', function(TasksModel, Persistence) { - var TasksBusinessLayer; - TasksBusinessLayer = (function() { - function TasksBusinessLayer(_$tasksmodel, _persistence) { - this._$tasksmodel = _$tasksmodel; - this._persistence = _persistence; - } + 'TasksModel', 'Persistence', function(TasksModel, Persistence) { + var TasksBusinessLayer; + TasksBusinessLayer = (function() { + function TasksBusinessLayer(_$tasksmodel, _persistence) { + this._$tasksmodel = _$tasksmodel; + this._persistence = _persistence; + } - TasksBusinessLayer.prototype.addTask = function(task, onSuccess, onFailure) { - var parentID, success, - _this = this; - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - onSuccess || (onSuccess = function() {}); - onFailure || (onFailure = function() {}); - this._$tasksmodel.add(task); - this.uncompleteParents(task.related); - parentID = this._$tasksmodel.getIdByUid(task.related); - if (parentID) { - this.unhideSubtasks(parentID); - } - success = function(response) { - if (response.status === 'error') { - return onFailure(); - } else { - return onSuccess(response.data); - } - }; - return this._persistence.addTask(task, success); - }; - - TasksBusinessLayer.prototype.getAll = function(calendar) {}; - - TasksBusinessLayer.prototype.getTask = function(taskID, onSuccess, onFailure) { - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - onSuccess || (onSuccess = function() {}); - return this._persistence.getTask(taskID, onSuccess, true); - }; - - TasksBusinessLayer.prototype.setPriority = function(taskID, priority) { - this._$tasksmodel.setPriority(taskID, priority); - if (+priority === 6 || +priority === 7 || +priority === 8 || +priority === 9) { - this._$tasksmodel.star(taskID); - } else { - this._$tasksmodel.unstar(taskID); - } - return this._persistence.setPriority(taskID, priority); - }; - - TasksBusinessLayer.prototype.starTask = function(taskID) { - return this.setPriority(taskID, '9'); - }; - - TasksBusinessLayer.prototype.unstarTask = function(taskID) { - return this.setPriority(taskID, '0'); - }; - - TasksBusinessLayer.prototype.setPercentComplete = function(taskID, percentComplete) { - var task; - this._$tasksmodel.setPercentComplete(taskID, percentComplete); - if (percentComplete < 100) { - this._$tasksmodel.uncomplete(taskID); - task = this._$tasksmodel.getById(taskID); - this.uncompleteParents(task.related); - } else { - this._$tasksmodel.complete(taskID); - this.completeChildren(taskID); - } - return this._persistence.setPercentComplete(taskID, percentComplete); - }; - - TasksBusinessLayer.prototype.completeTask = function(taskID) { - this.setPercentComplete(taskID, 100); - return this.hideSubtasks(taskID); - }; - - TasksBusinessLayer.prototype.uncompleteTask = function(taskID) { - return this.setPercentComplete(taskID, 0); - }; - - TasksBusinessLayer.prototype.completeChildren = function(taskID) { - var childID, childrenID, _i, _len, _results; - childrenID = this._$tasksmodel.getChildrenID(taskID); - _results = []; - for (_i = 0, _len = childrenID.length; _i < _len; _i++) { - childID = childrenID[_i]; - _results.push(this.setPercentComplete(childID, 100)); - } - return _results; - }; - - TasksBusinessLayer.prototype.uncompleteParents = function(uid) { - var parentID; - if (uid) { - parentID = this._$tasksmodel.getIdByUid(uid); - if (this._$tasksmodel.completed(parentID)) { - return this.setPercentComplete(parentID, 0); - } - } - }; - - TasksBusinessLayer.prototype.unhideSubtasks = function(taskID) { - this._$tasksmodel.setHideSubtasks(taskID, false); - return this._persistence.setHideSubtasks(taskID, false); - }; - - TasksBusinessLayer.prototype.hideSubtasks = function(taskID) { - this._$tasksmodel.setHideSubtasks(taskID, true); - return this._persistence.setHideSubtasks(taskID, true); - }; - - TasksBusinessLayer.prototype.deleteTask = function(taskID) { - var childID, childrenID, _i, _len; - childrenID = this._$tasksmodel.getChildrenID(taskID); - for (_i = 0, _len = childrenID.length; _i < _len; _i++) { - childID = childrenID[_i]; - this.deleteTask(childID); - } - this._$tasksmodel.removeById(taskID); - return this._persistence.deleteTask(taskID); - }; - - TasksBusinessLayer.prototype.initDueDate = function(taskID) { - var due; - due = moment(this._$tasksmodel.getById(taskID).due, "YYYYMMDDTHHmmss"); - if (!due.isValid()) { - return this.setDue(taskID, moment().startOf('hour').add(1, 'h'), 'time'); - } - }; - - TasksBusinessLayer.prototype.setDue = function(taskID, date, type) { - var due; - if (type == null) { - type = 'day'; - } - due = moment(this._$tasksmodel.getById(taskID).due, "YYYYMMDDTHHmmss"); - if (type === 'day') { - if (moment(due).isValid()) { - due.year(date.year()).month(date.month()).date(date.date()); - } else { - due = date.add(12, 'h'); - } - } else if (type === 'time') { - if (moment(due).isValid()) { - due.hour(date.hour()).minute(date.minute()); - } else { - due = date; - } - } else if (type === 'all') { - due = date; - } else { - return; - } - this._$tasksmodel.setDueDate(taskID, due.format('YYYYMMDDTHHmmss')); - this.checkReminderDate(taskID); - return this._persistence.setDueDate(taskID, due.isValid() ? due.unix() : false); - }; - - TasksBusinessLayer.prototype.deleteDueDate = function(taskID) { - var reminder; - reminder = this._$tasksmodel.getById(taskID).reminder; - if (reminder !== null && reminder.type === 'DURATION' && reminder.duration.params.related === 'END') { - this.deleteReminderDate(taskID); - } - this._$tasksmodel.setDueDate(taskID, null); - return this._persistence.setDueDate(taskID, false); - }; - - TasksBusinessLayer.prototype.initStartDate = function(taskID) { - var start; - start = moment(this._$tasksmodel.getById(taskID).start, "YYYYMMDDTHHmmss"); - if (!start.isValid()) { - return this.setStart(taskID, moment().startOf('hour').add(1, 'h'), 'time'); - } - }; - - TasksBusinessLayer.prototype.setStart = function(taskID, date, type) { - var start; - if (type == null) { - type = 'day'; - } - start = moment(this._$tasksmodel.getById(taskID).start, "YYYYMMDDTHHmmss"); - if (type === 'day') { - if (moment(start).isValid()) { - start.year(date.year()).month(date.month()).date(date.date()); - } else { - start = date.add(12, 'h'); - } - } else if (type === 'time') { - if (moment(start).isValid()) { - start.hour(date.hour()).minute(date.minute()); - } else { - start = date; - } - } else { - return; - } - this._$tasksmodel.setStartDate(taskID, start.format('YYYYMMDDTHHmmss')); - this.checkReminderDate(taskID); - return this._persistence.setStartDate(taskID, start.isValid() ? start.unix() : false); - }; - - TasksBusinessLayer.prototype.deleteStartDate = function(taskID) { - var reminder; - reminder = this._$tasksmodel.getById(taskID).reminder; - if (reminder !== null && reminder.type === 'DURATION' && reminder.duration.params.related === 'START') { - this.deleteReminderDate(taskID); - } - this._$tasksmodel.setStartDate(taskID, null); - return this._persistence.setStartDate(taskID, false); - }; - - TasksBusinessLayer.prototype.initReminder = function(taskID) { - var p, task; - if (!this.checkReminderDate(taskID)) { - task = this._$tasksmodel.getById(taskID); - task.reminder = { - type: 'DURATION', - action: 'DISPLAY', - duration: { - token: 'week', - week: 0, - day: 0, - hour: 0, - minute: 0, - second: 0, - params: { - invert: true - } - } - }; - if (moment(task.start, "YYYYMMDDTHHmmss").isValid()) { - p = task.reminder.duration.params; - p.related = 'START'; - p.id = '10'; - } else if (moment(task.due, "YYYYMMDDTHHmmss").isValid()) { - p = task.reminder.duration.params; - p.related = 'END'; - p.id = '11'; - } else { - task.reminder.type = 'DATE-TIME'; - task.reminder.date = moment().startOf('hour').add(1, 'h').format('YYYYMMDDTHHmmss'); - } - return this.setReminder(taskID); - } - }; - - TasksBusinessLayer.prototype.setReminderDate = function(taskID, date, type) { - var newreminder, reminder, reminderdate; - if (type == null) { - type = 'day'; - } - reminder = this._$tasksmodel.getById(taskID).reminder; - newreminder = { - type: 'DATE-TIME', - action: 'DISPLAY', - duration: null - }; - if (type === 'day') { - if (this.checkReminderDate(taskID) || reminder === null) { - reminderdate = moment(reminder.date, "YYYYMMDDTHHmmss"); - newreminder.action = reminder.action; - if (reminderdate.isValid() && reminder.type === 'DATE-TIME') { - reminderdate.year(date.year()).month(date.month()).date(date.date()); - } else { - reminderdate = date.add(12, 'h'); - } - } else { - reminderdate = date.add(12, 'h'); - } - } else if (type === 'time') { - if (this.checkReminderDate(taskID) || reminder === null) { - reminderdate = moment(reminder.date, "YYYYMMDDTHHmmss"); - newreminder.action = reminder.action; - if (reminderdate.isValid() && reminder.type === 'DATE-TIME') { - reminderdate.hour(date.hour()).minute(date.minute()); - } else { - reminderdate = date; - } - } else { - reminderdate = date; - } - } else { - return; - } - newreminder.date = reminderdate.format('YYYYMMDDTHHmmss'); - this._$tasksmodel.setReminder(taskID, newreminder); - return this._persistence.setReminder(taskID, newreminder); - }; - - TasksBusinessLayer.prototype.setReminder = function(taskID) { - var reminder; - if (this.checkReminderDate(taskID)) { - reminder = this._$tasksmodel.getById(taskID).reminder; - return this._persistence.setReminder(taskID, reminder); - } - }; - - TasksBusinessLayer.prototype.checkReminderDate = function(taskID) { - var d, date, duration, rel, related, reminder, seg, task, token; - task = this._$tasksmodel.getById(taskID); - reminder = task.reminder; - if (reminder !== null && reminder.type === 'DURATION') { - if (!reminder.duration) { - return false; - } else if (reminder.duration.params.related === 'START') { - token = 'start'; - } else if (reminder.duration.params.related === 'END') { - token = 'due'; - } else { - return false; - } - date = moment(task[token], "YYYYMMDDTHHmmss"); - duration = reminder.duration; - d = { - w: duration.week, - d: duration.day, - h: duration.hour, - m: duration.minute, - s: duration.second - }; - if (duration.params.invert) { - date = date.subtract(d); - } else { - date = date.add(d); - } - task.reminder.date = date.format('YYYYMMDDTHHmmss'); - } else if (reminder !== null && reminder.type === 'DATE-TIME') { - duration = reminder.duration; - date = moment(reminder.date, "YYYYMMDDTHHmmss"); - if (!date.isValid()) { - return false; - } - if (duration) { - if (duration.params.related === 'START') { - related = moment(task.start, "YYYYMMDDTHHmmss"); - } else { - related = moment(task.due, "YYYYMMDDTHHmmss"); - } - seg = this.secondsToSegments(date.diff(related, 'seconds')); - duration.params.invert = seg.invert; - duration.token = 'week'; - duration.week = seg.week; - duration.day = seg.day; - duration.hour = seg.hour; - duration.minute = seg.minute; - duration.second = seg.second; - } else { - if (task.start) { - related = moment(task.start, "YYYYMMDDTHHmmss"); - rel = 'START'; - d = 0; - } else if (task.due) { - related = moment(task.due, "YYYYMMDDTHHmmss"); - rel = 'END'; - d = 1; - } else { - return true; - } - seg = this.secondsToSegments(date.diff(related, 'seconds')); - reminder.duration = { - token: 'week', - params: { - related: rel, - invert: seg.invert, - id: +seg.invert + '' + d - }, - week: seg.week, - day: seg.day, - hour: seg.hour, - minute: seg.minute, - second: seg.second - }; - } - } else { - return false; - } - return true; - }; - - TasksBusinessLayer.prototype.secondsToSegments = function(s) { - var d, h, i, m, w; - if (s < 0) { - s *= -1; - i = true; - } else { - i = false; - } - w = Math.floor(s / 604800); - s -= w * 604800; - d = Math.floor(s / 86400); - s -= d * 86400; - h = Math.floor(s / 3600); - s -= h * 3600; - m = Math.floor(s / 60); - s -= m * 60; - return { - week: w, - day: d, - hour: h, - minute: m, - second: s, - invert: i - }; - }; - - TasksBusinessLayer.prototype.deleteReminderDate = function(taskID) { - this._$tasksmodel.setReminder(taskID, null); - return this._persistence.setReminder(taskID, false); - }; - - TasksBusinessLayer.prototype.changeCalendarId = function(taskID, calendarID) { - var child, childID, childrenID, parent, parentID, task, _i, _len; - this._$tasksmodel.changeCalendarId(taskID, calendarID); - this._persistence.changeCalendarId(taskID, calendarID); - childrenID = this._$tasksmodel.getChildrenID(taskID); - task = this._$tasksmodel.getById(taskID); - for (_i = 0, _len = childrenID.length; _i < _len; _i++) { - childID = childrenID[_i]; - child = this._$tasksmodel.getById(childID); - if (child.calendarid !== task.calendarid) { - this.changeCalendarId(childID, task.calendarid); - } - } - if (!this._$tasksmodel.hasNoParent(task)) { - parentID = this._$tasksmodel.getIdByUid(task.related); - parent = this._$tasksmodel.getById(parentID); - if (parent.calendarid !== task.calendarid) { - return this.changeParent(taskID, '', ''); - } - } - }; - - TasksBusinessLayer.prototype.setTaskNote = function(taskID, note) { - return this._persistence.setTaskNote(taskID, note); - }; - - TasksBusinessLayer.prototype.setTaskName = function(taskID, name) { - return this._persistence.setTaskName(taskID, name); - }; - - TasksBusinessLayer.prototype.changeCollection = function(taskID, collectionID) { - switch (collectionID) { - case 'starred': - return this.starTask(taskID); - case 'completed': - return this.completeTask(taskID); - case 'uncompleted': - return this.uncompleteTask(taskID); - case 'today': - return this.setDue(taskID, moment().startOf('day').add(12, 'h'), 'all'); - case 'week': - case 'all': - return false; - default: - return false; - } - }; - - TasksBusinessLayer.prototype.changeParent = function(taskID, parentID, collectionID) { - var parent, related, task; - task = this._$tasksmodel.getById(taskID); - if (parentID) { - parent = this._$tasksmodel.getById(parentID); - this.unhideSubtasks(parentID); - related = parent.uid; - if (parent.completed && !task.completed) { - this.uncompleteTask(parentID); - } - if (parent.calendarid !== task.calendarid) { - this.changeCalendarId(taskID, parent.calendarid); - } - } else { - related = ""; - if (collectionID !== "completed" && task.completed) { - this.uncompleteTask(taskID); - } - } - this._$tasksmodel.changeParent(taskID, related); - return this._persistence.changeParent(taskID, related); - }; - - TasksBusinessLayer.prototype.updateModel = function() { - var success, - _this = this; - this._$tasksmodel.voidAll(); - success = function() { - return _this._$tasksmodel.removeVoid(); - }; - return this._persistence.getTasks('init', 'all', success, true); - }; - - TasksBusinessLayer.prototype.setShowHidden = function(showHidden) { - return this._persistence.setShowHidden(showHidden); - }; - - TasksBusinessLayer.prototype.addComment = function(comment, onSuccess, onFailure) { - var success, - _this = this; - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - onSuccess || (onSuccess = function() {}); - onFailure || (onFailure = function() {}); - this._$tasksmodel.addComment(comment); - success = function(response) { - if (response.status === 'error') { - return onFailure(); - } else { - return onSuccess(response.data); - } - }; - return this._persistence.addComment(comment, success); - }; + TasksBusinessLayer.prototype.addTask = function(task, onSuccess, onFailure) { + var parentID, success, + _this = this; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + this._$tasksmodel.add(task); + this.uncompleteParents(task.related); + parentID = this._$tasksmodel.getIdByUid(task.related); + if (parentID) { + this.unhideSubtasks(parentID); + } + success = function(response) { + if (response.status === 'error') { + return onFailure(); + } else { + return onSuccess(response.data); + } + }; + return this._persistence.addTask(task, success); + }; - TasksBusinessLayer.prototype.deleteComment = function(taskID, commentID) { - this._$tasksmodel.deleteComment(taskID, commentID); - return this._persistence.deleteComment(taskID, commentID); - }; + TasksBusinessLayer.prototype.getAll = function(calendar) {}; + + TasksBusinessLayer.prototype.getTask = function(taskID, onSuccess, onFailure) { + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + return this._persistence.getTask(taskID, onSuccess, true); + }; - TasksBusinessLayer.prototype.getCompletedTasks = function(listID) { - return this._persistence.getTasks('completed', listID); - }; + TasksBusinessLayer.prototype.setPriority = function(taskID, priority) { + this._$tasksmodel.setPriority(taskID, priority); + if (+priority === 6 || +priority === 7 || +priority === 8 || +priority === 9) { + this._$tasksmodel.star(taskID); + } else { + this._$tasksmodel.unstar(taskID); + } + return this._persistence.setPriority(taskID, priority); + }; - TasksBusinessLayer.prototype.addCategory = function(taskID, category) { - return this._persistence.addCategory(taskID, category); - }; + TasksBusinessLayer.prototype.starTask = function(taskID) { + return this.setPriority(taskID, '9'); + }; - TasksBusinessLayer.prototype.removeCategory = function(taskID, category) { - return this._persistence.removeCategory(taskID, category); - }; + TasksBusinessLayer.prototype.unstarTask = function(taskID) { + return this.setPriority(taskID, '0'); + }; - return TasksBusinessLayer; + TasksBusinessLayer.prototype.setPercentComplete = function(taskID, percentComplete) { + var task; + this._$tasksmodel.setPercentComplete(taskID, percentComplete); + if (percentComplete < 100) { + this._$tasksmodel.uncomplete(taskID); + task = this._$tasksmodel.getById(taskID); + this.uncompleteParents(task.related); + } else { + this._$tasksmodel.complete(taskID); + this.completeChildren(taskID); + } + return this._persistence.setPercentComplete(taskID, percentComplete); + }; - })(); - return new TasksBusinessLayer(TasksModel, Persistence); - } + TasksBusinessLayer.prototype.completeTask = function(taskID) { + this.setPercentComplete(taskID, 100); + return this.hideSubtasks(taskID); + }; + + TasksBusinessLayer.prototype.uncompleteTask = function(taskID) { + return this.setPercentComplete(taskID, 0); + }; + + TasksBusinessLayer.prototype.completeChildren = function(taskID) { + var childID, childrenID, _i, _len, _results; + childrenID = this._$tasksmodel.getChildrenID(taskID); + _results = []; + for (_i = 0, _len = childrenID.length; _i < _len; _i++) { + childID = childrenID[_i]; + _results.push(this.setPercentComplete(childID, 100)); + } + return _results; + }; + + TasksBusinessLayer.prototype.uncompleteParents = function(uid) { + var parentID; + if (uid) { + parentID = this._$tasksmodel.getIdByUid(uid); + if (this._$tasksmodel.completed(parentID)) { + return this.setPercentComplete(parentID, 0); + } + } + }; + + TasksBusinessLayer.prototype.unhideSubtasks = function(taskID) { + this._$tasksmodel.setHideSubtasks(taskID, false); + return this._persistence.setHideSubtasks(taskID, false); + }; + + TasksBusinessLayer.prototype.hideSubtasks = function(taskID) { + this._$tasksmodel.setHideSubtasks(taskID, true); + return this._persistence.setHideSubtasks(taskID, true); + }; + + TasksBusinessLayer.prototype.deleteTask = function(taskID) { + var childID, childrenID, _i, _len; + childrenID = this._$tasksmodel.getChildrenID(taskID); + for (_i = 0, _len = childrenID.length; _i < _len; _i++) { + childID = childrenID[_i]; + this.deleteTask(childID); + } + this._$tasksmodel.removeById(taskID); + return this._persistence.deleteTask(taskID); + }; + + TasksBusinessLayer.prototype.initDueDate = function(taskID) { + var due; + due = moment(this._$tasksmodel.getById(taskID).due, "YYYYMMDDTHHmmss"); + if (!due.isValid()) { + return this.setDue(taskID, moment().startOf('hour').add(1, 'h'), 'time'); + } + }; + + TasksBusinessLayer.prototype.setDue = function(taskID, date, type) { + var due; + if (type == null) { + type = 'day'; + } + due = moment(this._$tasksmodel.getById(taskID).due, "YYYYMMDDTHHmmss"); + if (type === 'day') { + if (moment(due).isValid()) { + due.year(date.year()).month(date.month()).date(date.date()); + } else { + due = date.add(12, 'h'); + } + } else if (type === 'time') { + if (moment(due).isValid()) { + due.hour(date.hour()).minute(date.minute()); + } else { + due = date; + } + } else if (type === 'all') { + due = date; + } else { + return; + } + this._$tasksmodel.setDueDate(taskID, due.format('YYYYMMDDTHHmmss')); + this.checkReminderDate(taskID); + return this._persistence.setDueDate(taskID, due.isValid() ? due.unix() : false); + }; + + TasksBusinessLayer.prototype.deleteDueDate = function(taskID) { + var reminder; + reminder = this._$tasksmodel.getById(taskID).reminder; + if (reminder !== null && reminder.type === 'DURATION' && reminder.duration.params.related === 'END') { + this.deleteReminderDate(taskID); + } + this._$tasksmodel.setDueDate(taskID, null); + return this._persistence.setDueDate(taskID, false); + }; + + TasksBusinessLayer.prototype.initStartDate = function(taskID) { + var start; + start = moment(this._$tasksmodel.getById(taskID).start, "YYYYMMDDTHHmmss"); + if (!start.isValid()) { + return this.setStart(taskID, moment().startOf('hour').add(1, 'h'), 'time'); + } + }; + + TasksBusinessLayer.prototype.setStart = function(taskID, date, type) { + var start; + if (type == null) { + type = 'day'; + } + start = moment(this._$tasksmodel.getById(taskID).start, "YYYYMMDDTHHmmss"); + if (type === 'day') { + if (moment(start).isValid()) { + start.year(date.year()).month(date.month()).date(date.date()); + } else { + start = date.add(12, 'h'); + } + } else if (type === 'time') { + if (moment(start).isValid()) { + start.hour(date.hour()).minute(date.minute()); + } else { + start = date; + } + } else { + return; + } + this._$tasksmodel.setStartDate(taskID, start.format('YYYYMMDDTHHmmss')); + this.checkReminderDate(taskID); + return this._persistence.setStartDate(taskID, start.isValid() ? start.unix() : false); + }; + + TasksBusinessLayer.prototype.deleteStartDate = function(taskID) { + var reminder; + reminder = this._$tasksmodel.getById(taskID).reminder; + if (reminder !== null && reminder.type === 'DURATION' && reminder.duration.params.related === 'START') { + this.deleteReminderDate(taskID); + } + this._$tasksmodel.setStartDate(taskID, null); + return this._persistence.setStartDate(taskID, false); + }; + + TasksBusinessLayer.prototype.initReminder = function(taskID) { + var p, task; + if (!this.checkReminderDate(taskID)) { + task = this._$tasksmodel.getById(taskID); + task.reminder = { + type: 'DURATION', + action: 'DISPLAY', + duration: { + token: 'week', + week: 0, + day: 0, + hour: 0, + minute: 0, + second: 0, + params: { + invert: true + } + } + }; + if (moment(task.start, "YYYYMMDDTHHmmss").isValid()) { + p = task.reminder.duration.params; + p.related = 'START'; + p.id = '10'; + } else if (moment(task.due, "YYYYMMDDTHHmmss").isValid()) { + p = task.reminder.duration.params; + p.related = 'END'; + p.id = '11'; + } else { + task.reminder.type = 'DATE-TIME'; + task.reminder.date = moment().startOf('hour').add(1, 'h').format('YYYYMMDDTHHmmss'); + } + return this.setReminder(taskID); + } + }; + + TasksBusinessLayer.prototype.setReminderDate = function(taskID, date, type) { + var newreminder, reminder, reminderdate; + if (type == null) { + type = 'day'; + } + reminder = this._$tasksmodel.getById(taskID).reminder; + newreminder = { + type: 'DATE-TIME', + action: 'DISPLAY', + duration: null + }; + if (type === 'day') { + if (this.checkReminderDate(taskID) || reminder === null) { + reminderdate = moment(reminder.date, "YYYYMMDDTHHmmss"); + newreminder.action = reminder.action; + if (reminderdate.isValid() && reminder.type === 'DATE-TIME') { + reminderdate.year(date.year()).month(date.month()).date(date.date()); + } else { + reminderdate = date.add(12, 'h'); + } + } else { + reminderdate = date.add(12, 'h'); + } + } else if (type === 'time') { + if (this.checkReminderDate(taskID) || reminder === null) { + reminderdate = moment(reminder.date, "YYYYMMDDTHHmmss"); + newreminder.action = reminder.action; + if (reminderdate.isValid() && reminder.type === 'DATE-TIME') { + reminderdate.hour(date.hour()).minute(date.minute()); + } else { + reminderdate = date; + } + } else { + reminderdate = date; + } + } else { + return; + } + newreminder.date = reminderdate.format('YYYYMMDDTHHmmss'); + this._$tasksmodel.setReminder(taskID, newreminder); + return this._persistence.setReminder(taskID, newreminder); + }; + + TasksBusinessLayer.prototype.setReminder = function(taskID) { + var reminder; + if (this.checkReminderDate(taskID)) { + reminder = this._$tasksmodel.getById(taskID).reminder; + return this._persistence.setReminder(taskID, reminder); + } + }; + + TasksBusinessLayer.prototype.checkReminderDate = function(taskID) { + var d, date, duration, rel, related, reminder, seg, task, token; + task = this._$tasksmodel.getById(taskID); + reminder = task.reminder; + if (reminder !== null && reminder.type === 'DURATION') { + if (!reminder.duration) { + return false; + } else if (reminder.duration.params.related === 'START') { + token = 'start'; + } else if (reminder.duration.params.related === 'END') { + token = 'due'; + } else { + return false; + } + date = moment(task[token], "YYYYMMDDTHHmmss"); + duration = reminder.duration; + d = { + w: duration.week, + d: duration.day, + h: duration.hour, + m: duration.minute, + s: duration.second + }; + if (duration.params.invert) { + date = date.subtract(d); + } else { + date = date.add(d); + } + task.reminder.date = date.format('YYYYMMDDTHHmmss'); + } else if (reminder !== null && reminder.type === 'DATE-TIME') { + duration = reminder.duration; + date = moment(reminder.date, "YYYYMMDDTHHmmss"); + if (!date.isValid()) { + return false; + } + if (duration) { + if (duration.params.related === 'START') { + related = moment(task.start, "YYYYMMDDTHHmmss"); + } else { + related = moment(task.due, "YYYYMMDDTHHmmss"); + } + seg = this.secondsToSegments(date.diff(related, 'seconds')); + duration.params.invert = seg.invert; + duration.token = 'week'; + duration.week = seg.week; + duration.day = seg.day; + duration.hour = seg.hour; + duration.minute = seg.minute; + duration.second = seg.second; + } else { + if (task.start) { + related = moment(task.start, "YYYYMMDDTHHmmss"); + rel = 'START'; + d = 0; + } else if (task.due) { + related = moment(task.due, "YYYYMMDDTHHmmss"); + rel = 'END'; + d = 1; + } else { + return true; + } + seg = this.secondsToSegments(date.diff(related, 'seconds')); + reminder.duration = { + token: 'week', + params: { + related: rel, + invert: seg.invert, + id: +seg.invert + '' + d + }, + week: seg.week, + day: seg.day, + hour: seg.hour, + minute: seg.minute, + second: seg.second + }; + } + } else { + return false; + } + return true; + }; + + TasksBusinessLayer.prototype.secondsToSegments = function(s) { + var d, h, i, m, w; + if (s < 0) { + s *= -1; + i = true; + } else { + i = false; + } + w = Math.floor(s / 604800); + s -= w * 604800; + d = Math.floor(s / 86400); + s -= d * 86400; + h = Math.floor(s / 3600); + s -= h * 3600; + m = Math.floor(s / 60); + s -= m * 60; + return { + week: w, + day: d, + hour: h, + minute: m, + second: s, + invert: i + }; + }; + + TasksBusinessLayer.prototype.deleteReminderDate = function(taskID) { + this._$tasksmodel.setReminder(taskID, null); + return this._persistence.setReminder(taskID, false); + }; + + TasksBusinessLayer.prototype.changeCalendarId = function(taskID, calendarID) { + var child, childID, childrenID, parent, parentID, task, _i, _len; + this._$tasksmodel.changeCalendarId(taskID, calendarID); + this._persistence.changeCalendarId(taskID, calendarID); + childrenID = this._$tasksmodel.getChildrenID(taskID); + task = this._$tasksmodel.getById(taskID); + for (_i = 0, _len = childrenID.length; _i < _len; _i++) { + childID = childrenID[_i]; + child = this._$tasksmodel.getById(childID); + if (child.calendarid !== task.calendarid) { + this.changeCalendarId(childID, task.calendarid); + } + } + if (!this._$tasksmodel.hasNoParent(task)) { + parentID = this._$tasksmodel.getIdByUid(task.related); + parent = this._$tasksmodel.getById(parentID); + if (parent.calendarid !== task.calendarid) { + return this.changeParent(taskID, '', ''); + } + } + }; + + TasksBusinessLayer.prototype.setTaskNote = function(taskID, note) { + return this._persistence.setTaskNote(taskID, note); + }; + + TasksBusinessLayer.prototype.setTaskName = function(taskID, name) { + return this._persistence.setTaskName(taskID, name); + }; + + TasksBusinessLayer.prototype.changeCollection = function(taskID, collectionID) { + switch (collectionID) { + case 'starred': + return this.starTask(taskID); + case 'completed': + return this.completeTask(taskID); + case 'uncompleted': + return this.uncompleteTask(taskID); + case 'today': + return this.setDue(taskID, moment().startOf('day').add(12, 'h'), 'all'); + case 'week': + case 'all': + return false; + default: + return false; + } + }; + + TasksBusinessLayer.prototype.changeParent = function(taskID, parentID, collectionID) { + var parent, related, task; + task = this._$tasksmodel.getById(taskID); + if (parentID) { + parent = this._$tasksmodel.getById(parentID); + this.unhideSubtasks(parentID); + related = parent.uid; + if (parent.completed && !task.completed) { + this.uncompleteTask(parentID); + } + if (parent.calendarid !== task.calendarid) { + this.changeCalendarId(taskID, parent.calendarid); + } + } else { + related = ""; + if (collectionID !== "completed" && task.completed) { + this.uncompleteTask(taskID); + } + } + this._$tasksmodel.changeParent(taskID, related); + return this._persistence.changeParent(taskID, related); + }; + + TasksBusinessLayer.prototype.updateModel = function() { + var success, + _this = this; + this._$tasksmodel.voidAll(); + success = function() { + return _this._$tasksmodel.removeVoid(); + }; + return this._persistence.getTasks('init', 'all', success, true); + }; + + TasksBusinessLayer.prototype.setShowHidden = function(showHidden) { + return this._persistence.setShowHidden(showHidden); + }; + + TasksBusinessLayer.prototype.addComment = function(comment, onSuccess, onFailure) { + var success, + _this = this; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + this._$tasksmodel.addComment(comment); + success = function(response) { + if (response.status === 'error') { + return onFailure(); + } else { + return onSuccess(response.data); + } + }; + return this._persistence.addComment(comment, success); + }; + + TasksBusinessLayer.prototype.deleteComment = function(taskID, commentID) { + this._$tasksmodel.deleteComment(taskID, commentID); + return this._persistence.deleteComment(taskID, commentID); + }; + + TasksBusinessLayer.prototype.getCompletedTasks = function(listID) { + return this._persistence.getTasks('completed', listID); + }; + + TasksBusinessLayer.prototype.addCategory = function(taskID, category) { + return this._persistence.addCategory(taskID, category); + }; + + TasksBusinessLayer.prototype.removeCategory = function(taskID, category) { + return this._persistence.removeCategory(taskID, category); + }; + + return TasksBusinessLayer; + + })(); + return new TasksBusinessLayer(TasksModel, Persistence); + } ]); }).call(this); @@ -2466,184 +2621,184 @@ angular.module('Tasks').service('CalendarService', ['DavClient', 'Calendar', fun (function() { angular.module('Tasks').service('DavClient', [ - function() { - var client; - client = new dav.Client({ - baseUrl: OC.linkToRemote('dav/calendars'), - xmlNamespaces: { - 'DAV:': 'd', - 'urn:ietf:params:xml:ns:caldav': 'c', - 'http://apple.com/ns/ical/': 'aapl', - 'http://owncloud.org/ns': 'oc', - 'http://calendarserver.org/ns/': 'cs' - } - }); - angular.extend(client, { - NS_DAV: 'DAV:', - NS_IETF: 'urn:ietf:params:xml:ns:caldav', - NS_APPLE: 'http://apple.com/ns/ical/', - NS_OWNCLOUD: 'http://owncloud.org/ns', - NS_CALENDARSERVER: 'http://calendarserver.org/ns/', - buildUrl: function(path) { - return window.location.protocol + '//' + window.location.host + path; - }, - wasRequestSuccessful: function(status) { - return status >= 200 && status <= 299; - } - }); - return client; - } + function() { + var client; + client = new dav.Client({ + baseUrl: OC.linkToRemote('dav/calendars'), + xmlNamespaces: { + 'DAV:': 'd', + 'urn:ietf:params:xml:ns:caldav': 'c', + 'http://apple.com/ns/ical/': 'aapl', + 'http://owncloud.org/ns': 'oc', + 'http://calendarserver.org/ns/': 'cs' + } + }); + angular.extend(client, { + NS_DAV: 'DAV:', + NS_IETF: 'urn:ietf:params:xml:ns:caldav', + NS_APPLE: 'http://apple.com/ns/ical/', + NS_OWNCLOUD: 'http://owncloud.org/ns', + NS_CALENDARSERVER: 'http://calendarserver.org/ns/', + buildUrl: function(path) { + return window.location.protocol + '//' + window.location.host + path; + }, + wasRequestSuccessful: function(status) { + return status >= 200 && status <= 299; + } + }); + return client; + } ]); }).call(this); (function() { angular.module('Tasks').factory('Loading', [ - function() { - var Loading; - Loading = (function() { - function Loading() { - this.count = 0; - } + function() { + var Loading; + Loading = (function() { + function Loading() { + this.count = 0; + } - Loading.prototype.increase = function() { - return this.count += 1; - }; + Loading.prototype.increase = function() { + return this.count += 1; + }; - Loading.prototype.decrease = function() { - return this.count -= 1; - }; + Loading.prototype.decrease = function() { + return this.count -= 1; + }; - Loading.prototype.getCount = function() { - return this.count; - }; + Loading.prototype.getCount = function() { + return this.count; + }; - Loading.prototype.isLoading = function() { - return this.count > 0; - }; + Loading.prototype.isLoading = function() { + return this.count > 0; + }; - return Loading; + return Loading; - })(); - return new Loading(); - } + })(); + return new Loading(); + } ]); }).call(this); (function() { angular.module('Tasks').factory('_Model', [ - function() { - var Model; - Model = (function() { - function Model() { - this._data = []; - this._dataMap = {}; - this._filterCache = {}; - } + function() { + var Model; + Model = (function() { + function Model() { + this._data = []; + this._dataMap = {}; + this._filterCache = {}; + } - Model.prototype.handle = function(data) { - var item, _i, _len, _results; - _results = []; - for (_i = 0, _len = data.length; _i < _len; _i++) { - item = data[_i]; - _results.push(this.add(item)); - } - return _results; - }; - - Model.prototype.add = function(data, clearCache) { - if (clearCache == null) { - clearCache = true; - } - if (clearCache) { - this._invalidateCache(); - } - if (angular.isDefined(this._dataMap[data.id])) { - return this.update(data, clearCache); - } else { - this._data.push(data); - return this._dataMap[data.id] = data; - } - }; - - Model.prototype.update = function(data, clearCache) { - var entry, key, value, _results; - if (clearCache == null) { - clearCache = true; - } - if (clearCache) { - this._invalidateCache(); - } - entry = this.getById(data.id); - _results = []; - for (key in data) { - value = data[key]; - if (key === 'id') { - continue; - } else { - _results.push(entry[key] = value); - } - } - return _results; - }; - - Model.prototype.getById = function(id) { - return this._dataMap[id]; - }; - - Model.prototype.getAll = function() { - return this._data; - }; - - Model.prototype.removeById = function(id, 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.id === id) { - this._data.splice(counter, 1); - data = this._dataMap[id]; - delete this._dataMap[id]; - if (clearCache) { - this._invalidateCache(); - } - return data; - } - } - }; - - Model.prototype.clear = function() { - this._data.length = 0; - this._dataMap = {}; - return this._invalidateCache(); - }; - - Model.prototype._invalidateCache = function() { - return this._filterCache = {}; - }; - - Model.prototype.get = function(query) { - var hash; - hash = query.hashCode(); - if (!angular.isDefined(this._filterCache[hash])) { - this._filterCache[hash] = query.exec(this._data); - } - return this._filterCache[hash]; - }; - - Model.prototype.size = function() { - return this._data.length; - }; - - return Model; + Model.prototype.handle = function(data) { + var item, _i, _len, _results; + _results = []; + for (_i = 0, _len = data.length; _i < _len; _i++) { + item = data[_i]; + _results.push(this.add(item)); + } + return _results; + }; - })(); - return Model; - } + Model.prototype.add = function(data, clearCache) { + if (clearCache == null) { + clearCache = true; + } + if (clearCache) { + this._invalidateCache(); + } + if (angular.isDefined(this._dataMap[data.id])) { + return this.update(data, clearCache); + } else { + this._data.push(data); + return this._dataMap[data.id] = data; + } + }; + + Model.prototype.update = function(data, clearCache) { + var entry, key, value, _results; + if (clearCache == null) { + clearCache = true; + } + if (clearCache) { + this._invalidateCache(); + } + entry = this.getById(data.id); + _results = []; + for (key in data) { + value = data[key]; + if (key === 'id') { + continue; + } else { + _results.push(entry[key] = value); + } + } + return _results; + }; + + Model.prototype.getById = function(id) { + return this._dataMap[id]; + }; + + Model.prototype.getAll = function() { + return this._data; + }; + + Model.prototype.removeById = function(id, 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.id === id) { + this._data.splice(counter, 1); + data = this._dataMap[id]; + delete this._dataMap[id]; + if (clearCache) { + this._invalidateCache(); + } + return data; + } + } + }; + + Model.prototype.clear = function() { + this._data.length = 0; + this._dataMap = {}; + return this._invalidateCache(); + }; + + Model.prototype._invalidateCache = function() { + return this._filterCache = {}; + }; + + Model.prototype.get = function(query) { + var hash; + hash = query.hashCode(); + if (!angular.isDefined(this._filterCache[hash])) { + this._filterCache[hash] = query.exec(this._data); + } + return this._filterCache[hash]; + }; + + Model.prototype.size = function() { + return this._data.length; + }; + + return Model; + + })(); + return Model; + } ]); }).call(this); @@ -2888,1770 +3043,1571 @@ angular.module('Tasks').factory('Calendar', ['$rootScope', '$filter', function($ (function() { 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; }; + __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; }; angular.module('Tasks').factory('CollectionsModel', [ - 'TasksModel', '_Model', function(TasksModel, _Model) { - var CollectionsModel; - CollectionsModel = (function(_super) { - __extends(CollectionsModel, _super); - - function CollectionsModel(_$tasksmodel) { - this._$tasksmodel = _$tasksmodel; - this._nameCache = {}; - CollectionsModel.__super__.constructor.call(this); - } + 'TasksModel', '_Model', function(TasksModel, _Model) { + var CollectionsModel; + CollectionsModel = (function(_super) { + __extends(CollectionsModel, _super); + + function CollectionsModel(_$tasksmodel) { + this._$tasksmodel = _$tasksmodel; + this._nameCache = {}; + CollectionsModel.__super__.constructor.call(this); + } - CollectionsModel.prototype.add = function(data, clearCache) { - if (clearCache == null) { - clearCache = true; - } - this._nameCache[data.displayname] = data; - if (angular.isDefined(data.id)) { - return CollectionsModel.__super__.add.call(this, data, clearCache); - } - }; - - CollectionsModel.prototype.getCount = function(collectionID, filter) { - var count, task, tasks, _i, _len; - if (filter == null) { - filter = ''; - } - count = 0; - tasks = this._$tasksmodel.filteredTasks(filter); - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - count += this._$tasksmodel.filterTasks(task, collectionID) && !task.related; - } - return count; - }; - - return CollectionsModel; - - })(_Model); - return new CollectionsModel(TasksModel); - } + CollectionsModel.prototype.add = function(data, clearCache) { + if (clearCache == null) { + clearCache = true; + } + this._nameCache[data.displayname] = data; + if (angular.isDefined(data.id)) { + return CollectionsModel.__super__.add.call(this, data, clearCache); + } + }; + + CollectionsModel.prototype.getCount = function(collectionID, filter) { + var count, task, tasks, _i, _len; + if (filter == null) { + filter = ''; + } + count = 0; + tasks = this._$tasksmodel.filteredTasks(filter); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + count += this._$tasksmodel.filterTasks(task, collectionID) && !task.related; + } + return count; + }; + + return CollectionsModel; + + })(_Model); + return new CollectionsModel(TasksModel); + } ]); }).call(this); (function() { 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; }; + __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; }; angular.module('Tasks').factory('ListsModel', [ - 'TasksModel', '_Model', function(TasksModel, _Model) { - var ListsModel; - ListsModel = (function(_super) { - __extends(ListsModel, _super); - - function ListsModel(_$tasksmodel) { - this._$tasksmodel = _$tasksmodel; - this._tmpUriCache = {}; - this._data = []; - this._dataMap = {}; - this._filterCache = {}; - } + 'TasksModel', '_Model', function(TasksModel, _Model) { + var ListsModel; + ListsModel = (function(_super) { + __extends(ListsModel, _super); + + function ListsModel(_$tasksmodel) { + this._$tasksmodel = _$tasksmodel; + this._tmpUriCache = {}; + this._data = []; + this._dataMap = {}; + this._filterCache = {}; + } - ListsModel.prototype.insert = function(cal) { - var access, calendar, component, components, href, name, owner, readWrite, share, shares, _i, _j, _len, _len1; - calendar = { - id: this.size(), - url: cal.url, - enabled: cal.props['{http://owncloud.org/ns}calendar-enabled'] === '1', - displayname: cal.props['{DAV:}displayname'] || 'Unnamed', - color: cal.props['{http://apple.com/ns/ical/}calendar-color'] || '#1d2d44', - order: parseInt(cal.props['{http://apple.com/ns/ical/}calendar-order']) || 0, - components: { - vevent: false, - vjournal: false, - vtodo: false - }, - writable: cal.props.canWrite, - shareable: cal.props.canWrite, - sharedWith: { - users: [], - groups: [] - }, - owner: '' - }; - components = cal.props['{urn:ietf:params:xml:ns:caldav}' + 'supported-calendar-component-set']; - for (_i = 0, _len = components.length; _i < _len; _i++) { - component = components[_i]; - name = component.attributes.getNamedItem('name').textContent.toLowerCase(); - if (calendar.components.hasOwnProperty(name)) { - calendar.components[name] = true; - } - } - shares = cal.props['{http://owncloud.org/ns}invite']; - if (typeof shares !== 'undefined') { - for (_j = 0, _len1 = shares.length; _j < _len1; _j++) { - share = shares[_j]; - href = share.getElementsByTagNameNS('DAV:', 'href'); - if (href.length === 0) { - continue; - } - href = href[0].textContent; - access = share.getElementsByTagNameNS('http://owncloud.org/ns', 'access'); - if (access.length === 0) { - continue; - } - access = access[0]; - readWrite = access.getElementsByTagNameNS('http://owncloud.org/ns', 'read-write'); - readWrite = readWrite.length !== 0; - if (href.startsWith('principal:principals/users/')) { - this.sharedWith.users.push({ - id: href.substr(27), - displayname: href.substr(27), - writable: readWrite - }); - } else if (href.startsWith('principal:principals/groups/')) { - this.sharedWith.groups.push({ - id: href.substr(28), - displayname: href.substr(28), - writable: readWrite - }); - } - } - } - owner = cal.props['{DAV:}owner']; - if (typeof owner !== 'undefined' && owner.length !== 0) { - owner = owner[0].textContent.slice(0, -1); - if (owner.startsWith('/remote.php/dav/principals/users/')) { - this.owner = owner.substr(33); - } - } - this.add(calendar); - return calendar; - }; - - ListsModel.prototype.add = function(calendar, clearCache) { - var updateByUri; - if (clearCache == null) { - clearCache = true; - } - updateByUri = angular.isDefined(calendar.uri) && angular.isDefined(this.getByUri(calendar.uri)); - if (updateByUri) { - return this.update(calendar, clearCache); - } else { - if (angular.isDefined(calendar.uri)) { - if (clearCache) { - this._invalidateCache(); - } - if (angular.isDefined(this._dataMap[calendar.uri])) { - - } else { - this._data.push(calendar); - return this._dataMap[calendar.uri] = calendar; - } - } - } - }; - - ListsModel.prototype.getByUri = function(uri) { - return this._dataMap[uri]; - }; - - ListsModel.prototype.update = function(list, clearCache) { - var tmplist; - if (clearCache == null) { - clearCache = true; - } - tmplist = this._tmpIdCache[list.tmpID]; - if (angular.isDefined(list.id) && angular.isDefined(tmplist) && angular.isUndefined(tmplist.id)) { - tmplist.id = list.id; - this._dataMap[list.id] = tmplist; - } - list["void"] = false; - return ListsModel.__super__.update.call(this, list, clearCache); - }; - - ListsModel.prototype["delete"] = function(calendar, 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 === calendar) { - this._data.splice(counter, 1); - data = this._dataMap[calendar.uri]; - delete this._dataMap[calendar.uri]; - if (clearCache) { - this._invalidateCache(); - } - return data; - } - } - }; - - ListsModel.prototype.voidAll = function() { - var list, lists, _i, _len, _results; - lists = this.getAll(); - _results = []; - for (_i = 0, _len = lists.length; _i < _len; _i++) { - list = lists[_i]; - _results.push(list["void"] = true); - } - return _results; - }; - - ListsModel.prototype.removeVoid = function() { - var id, list, listIDs, lists, _i, _j, _len, _len1, _results; - lists = this.getAll(); - listIDs = []; - for (_i = 0, _len = lists.length; _i < _len; _i++) { - list = lists[_i]; - if (list["void"]) { - listIDs.push(list.id); - } - } - _results = []; - for (_j = 0, _len1 = listIDs.length; _j < _len1; _j++) { - id = listIDs[_j]; - _results.push(this.removeById(id)); - } - return _results; - }; - - ListsModel.prototype.getStandardList = function() { - var calendars; - if (this.size()) { - calendars = this.getAll(); - return calendars[0]; - } - }; - - ListsModel.prototype.checkName = function(listName, listID) { - var list, lists, ret, _i, _len; - if (listID == null) { - listID = void 0; - } - lists = this.getAll(); - ret = true; - for (_i = 0, _len = lists.length; _i < _len; _i++) { - list = lists[_i]; - if (list.displayname === listName && listID !== list.id) { - ret = false; - } - } - return ret; - }; - - ListsModel.prototype.getCount = function(listID, collectionID, filter) { - var count, task, tasks, _i, _len; - if (filter == null) { - filter = ''; - } - count = 0; - tasks = this._$tasksmodel.filteredTasks(filter); - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - count += this._$tasksmodel.filterTasks(task, collectionID) && task.calendarid === listID && !task.related; - } - if (collectionID === 'completed' && filter === '') { - count += this.notLoaded(listID); - } - return count; - }; - - ListsModel.prototype.notLoaded = function(listID) { - if (angular.isUndefined(this.getById(listID))) { - return 0; - } else { - return this.getById(listID).notLoaded; - } - }; - - ListsModel.prototype.loadedAll = function(listID) { - return !this.notLoaded(listID); - }; - - ListsModel.prototype.getColor = function(listID) { - if (angular.isUndefined(this.getById(listID))) { - return '#CCCCCC'; - } else { - return this.getById(listID).calendarcolor; - } - }; - - ListsModel.prototype.getName = function(listID) { - if (angular.isUndefined(this.getById(listID))) { - return ''; - } else { - return this.getById(listID).displayname; - } - }; - - return ListsModel; - - })(_Model); - return new ListsModel(TasksModel); - } + ListsModel.prototype.insert = function(cal) { + var access, calendar, component, components, href, name, owner, readWrite, share, shares, _i, _j, _len, _len1; + calendar = { + id: this.size(), + url: cal.url, + enabled: cal.props['{http://owncloud.org/ns}calendar-enabled'] === '1', + displayname: cal.props['{DAV:}displayname'] || 'Unnamed', + color: cal.props['{http://apple.com/ns/ical/}calendar-color'] || '#1d2d44', + order: parseInt(cal.props['{http://apple.com/ns/ical/}calendar-order']) || 0, + components: { + vevent: false, + vjournal: false, + vtodo: false + }, + writable: cal.props.canWrite, + shareable: cal.props.canWrite, + sharedWith: { + users: [], + groups: [] + }, + owner: '' + }; + components = cal.props['{urn:ietf:params:xml:ns:caldav}' + 'supported-calendar-component-set']; + for (_i = 0, _len = components.length; _i < _len; _i++) { + component = components[_i]; + name = component.attributes.getNamedItem('name').textContent.toLowerCase(); + if (calendar.components.hasOwnProperty(name)) { + calendar.components[name] = true; + } + } + shares = cal.props['{http://owncloud.org/ns}invite']; + if (typeof shares !== 'undefined') { + for (_j = 0, _len1 = shares.length; _j < _len1; _j++) { + share = shares[_j]; + href = share.getElementsByTagNameNS('DAV:', 'href'); + if (href.length === 0) { + continue; + } + href = href[0].textContent; + access = share.getElementsByTagNameNS('http://owncloud.org/ns', 'access'); + if (access.length === 0) { + continue; + } + access = access[0]; + readWrite = access.getElementsByTagNameNS('http://owncloud.org/ns', 'read-write'); + readWrite = readWrite.length !== 0; + if (href.startsWith('principal:principals/users/')) { + this.sharedWith.users.push({ + id: href.substr(27), + displayname: href.substr(27), + writable: readWrite + }); + } else if (href.startsWith('principal:principals/groups/')) { + this.sharedWith.groups.push({ + id: href.substr(28), + displayname: href.substr(28), + writable: readWrite + }); + } + } + } + owner = cal.props['{DAV:}owner']; + if (typeof owner !== 'undefined' && owner.length !== 0) { + owner = owner[0].textContent.slice(0, -1); + if (owner.startsWith('/remote.php/dav/principals/users/')) { + this.owner = owner.substr(33); + } + } + this.add(calendar); + return calendar; + }; + + ListsModel.prototype.add = function(calendar, clearCache) { + var updateByUri; + if (clearCache == null) { + clearCache = true; + } + updateByUri = angular.isDefined(calendar.uri) && angular.isDefined(this.getByUri(calendar.uri)); + if (updateByUri) { + return this.update(calendar, clearCache); + } else { + if (angular.isDefined(calendar.uri)) { + if (clearCache) { + this._invalidateCache(); + } + if (angular.isDefined(this._dataMap[calendar.uri])) { + + } else { + this._data.push(calendar); + return this._dataMap[calendar.uri] = calendar; + } + } + } + }; + + ListsModel.prototype.getByUri = function(uri) { + return this._dataMap[uri]; + }; + + ListsModel.prototype.update = function(list, clearCache) { + var tmplist; + if (clearCache == null) { + clearCache = true; + } + tmplist = this._tmpIdCache[list.tmpID]; + if (angular.isDefined(list.id) && angular.isDefined(tmplist) && angular.isUndefined(tmplist.id)) { + tmplist.id = list.id; + this._dataMap[list.id] = tmplist; + } + list["void"] = false; + return ListsModel.__super__.update.call(this, list, clearCache); + }; + + ListsModel.prototype["delete"] = function(calendar, 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 === calendar) { + this._data.splice(counter, 1); + data = this._dataMap[calendar.uri]; + delete this._dataMap[calendar.uri]; + if (clearCache) { + this._invalidateCache(); + } + return data; + } + } + }; + + ListsModel.prototype.voidAll = function() { + var list, lists, _i, _len, _results; + lists = this.getAll(); + _results = []; + for (_i = 0, _len = lists.length; _i < _len; _i++) { + list = lists[_i]; + _results.push(list["void"] = true); + } + return _results; + }; + + ListsModel.prototype.removeVoid = function() { + var id, list, listIDs, lists, _i, _j, _len, _len1, _results; + lists = this.getAll(); + listIDs = []; + for (_i = 0, _len = lists.length; _i < _len; _i++) { + list = lists[_i]; + if (list["void"]) { + listIDs.push(list.id); + } + } + _results = []; + for (_j = 0, _len1 = listIDs.length; _j < _len1; _j++) { + id = listIDs[_j]; + _results.push(this.removeById(id)); + } + return _results; + }; + + ListsModel.prototype.getStandardList = function() { + var calendars; + if (this.size()) { + calendars = this.getAll(); + return calendars[0]; + } + }; + + ListsModel.prototype.checkName = function(listName, listID) { + var list, lists, ret, _i, _len; + if (listID == null) { + listID = void 0; + } + lists = this.getAll(); + ret = true; + for (_i = 0, _len = lists.length; _i < _len; _i++) { + list = lists[_i]; + if (list.displayname === listName && listID !== list.id) { + ret = false; + } + } + return ret; + }; + + ListsModel.prototype.getCount = function(listID, collectionID, filter) { + var count, task, tasks, _i, _len; + if (filter == null) { + filter = ''; + } + count = 0; + tasks = this._$tasksmodel.filteredTasks(filter); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + count += this._$tasksmodel.filterTasks(task, collectionID) && task.calendarid === listID && !task.related; + } + if (collectionID === 'completed' && filter === '') { + count += this.notLoaded(listID); + } + return count; + }; + + ListsModel.prototype.notLoaded = function(listID) { + if (angular.isUndefined(this.getById(listID))) { + return 0; + } else { + return this.getById(listID).notLoaded; + } + }; + + ListsModel.prototype.loadedAll = function(listID) { + return !this.notLoaded(listID); + }; + + ListsModel.prototype.getColor = function(listID) { + if (angular.isUndefined(this.getById(listID))) { + return '#CCCCCC'; + } else { + return this.getById(listID).calendarcolor; + } + }; + + ListsModel.prototype.getName = function(listID) { + if (angular.isUndefined(this.getById(listID))) { + return ''; + } else { + return this.getById(listID).displayname; + } + }; + + return ListsModel; + + })(_Model); + return new ListsModel(TasksModel); + } ]); }).call(this); (function() { 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; }; + __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; }; angular.module('Tasks').factory('SettingsModel', [ - '_Model', function(_Model) { - var SettingsModel; - SettingsModel = (function(_super) { - __extends(SettingsModel, _super); - - function SettingsModel() { - this._nameCache = {}; - SettingsModel.__super__.constructor.call(this); - } + '_Model', function(_Model) { + var SettingsModel; + SettingsModel = (function(_super) { + __extends(SettingsModel, _super); + + function SettingsModel() { + this._nameCache = {}; + SettingsModel.__super__.constructor.call(this); + } - SettingsModel.prototype.add = function(data, clearCache) { - if (clearCache == null) { - clearCache = true; - } - this._nameCache[data.displayname] = data; - if (angular.isDefined(data.id)) { - return SettingsModel.__super__.add.call(this, data, clearCache); - } else { - return this._data.push(data); - } - }; - - SettingsModel.prototype.toggle = function(type, setting) { - var set; - set = this.getById(type); - return this.getById(type)[setting] = !set[setting]; - }; - - return SettingsModel; - - })(_Model); - return new SettingsModel(); - } + SettingsModel.prototype.add = function(data, clearCache) { + if (clearCache == null) { + clearCache = true; + } + this._nameCache[data.displayname] = data; + if (angular.isDefined(data.id)) { + return SettingsModel.__super__.add.call(this, data, clearCache); + } else { + return this._data.push(data); + } + }; + + SettingsModel.prototype.toggle = function(type, setting) { + var set; + set = this.getById(type); + return this.getById(type)[setting] = !set[setting]; + }; + + return SettingsModel; + + })(_Model); + return new SettingsModel(); + } ]); }).call(this); (function() { 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; }; + __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; - TasksModel = (function(_super) { - __extends(TasksModel, _super); - - function TasksModel() { - this._tmpIdCache = {}; - TasksModel.__super__.constructor.call(this); - } + '_Model', function(_Model) { + var TasksModel; + TasksModel = (function(_super) { + __extends(TasksModel, _super); + + function TasksModel() { + this._tmpIdCache = {}; + TasksModel.__super__.constructor.call(this); + } - TasksModel.prototype.add = function(task, clearCache) { - var tmptask, updateById, updateByTmpId; - if (clearCache == null) { - clearCache = true; - } - tmptask = this._tmpIdCache[task.tmpID]; - updateById = angular.isDefined(task.id) && angular.isDefined(this.getById(task.id)); - updateByTmpId = angular.isDefined(tmptask); - if (updateById || updateByTmpId) { - return this.update(task, clearCache); - } else { - if (angular.isDefined(task.id) && angular.isUndefined(task.tmpID)) { - return TasksModel.__super__.add.call(this, task, clearCache); - } else { - this._tmpIdCache[task.tmpID] = task; - this._data.push(task); - if (clearCache) { - return this._invalidateCache(); - } - } - } - }; - - TasksModel.prototype.update = function(task, clearCache) { - var tmptask; - if (clearCache == null) { - clearCache = true; - } - tmptask = this._tmpIdCache[task.tmpID]; - if (angular.isDefined(task.id) && angular.isDefined(tmptask)) { - tmptask.id = task.id; - this._dataMap[task.id] = tmptask; - } - task["void"] = false; - return TasksModel.__super__.update.call(this, task, clearCache); - }; - - TasksModel.prototype.removeById = function(taskID) { - return TasksModel.__super__.removeById.call(this, taskID); - }; - - TasksModel.prototype.voidAll = function() { - var task, tasks, _i, _len, _results; - tasks = this.getAll(); - _results = []; - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - _results.push(task["void"] = true); - } - return _results; - }; - - TasksModel.prototype.removeVoid = function() { - var id, task, taskIDs, tasks, _i, _j, _len, _len1, _results; - tasks = this.getAll(); - taskIDs = []; - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - if (task["void"]) { - taskIDs.push(task.id); - } - } - _results = []; - for (_j = 0, _len1 = taskIDs.length; _j < _len1; _j++) { - id = taskIDs[_j]; - _results.push(this.removeById(id)); - } - return _results; - }; - - TasksModel.prototype.removeByList = function(listID) { - var id, task, taskIDs, tasks, _i, _j, _len, _len1, _results; - tasks = this.getAll(); - taskIDs = []; - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - if (task.calendarid === listID) { - taskIDs.push(task.id); - } - } - _results = []; - for (_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.getById(task.id)) { - return true; - } else { - return false; - } - }; - - TasksModel.prototype.hasSubtasks = function(uid) { - var task, tasks, _i, _len; - tasks = this.getAll(); - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - if (task.related === uid) { - return true; - } - } - return false; - }; - - TasksModel.prototype.hasNoParent = function(task) { - var t, tasks, _i, _len; - if (!task.related) { - return true; - } else { - tasks = this.getAll(); - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - t = tasks[_i]; - if (task.related === t.uid) { - return false; - } - } - return true; - } - }; - - TasksModel.prototype.getIdByUid = function(uid) { - var task, tasks, _i, _len; - tasks = this.getAll(); - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - if (task.uid === uid) { - return task.id; - } - } - return false; - }; - - TasksModel.prototype.getChildrenID = function(taskID) { - var childrenID, t, task, tasks, _i, _len; - task = this.getById(taskID); - tasks = this.getAll(); - childrenID = []; - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - t = tasks[_i]; - if (t.related === task.uid) { - childrenID.push(t.id); - } - } - return childrenID; - }; - - TasksModel.prototype.getDescendantID = function(taskID) { - var childID, childrenID, descendantID, _i, _len; - childrenID = this.getChildrenID(taskID); - descendantID = []; - descendantID = descendantID.concat(childrenID); - for (_i = 0, _len = childrenID.length; _i < _len; _i++) { - childID = childrenID[_i]; - descendantID = descendantID.concat(this.getDescendantID(childID)); - } - return descendantID; - }; - - 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.starred === true; - 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.calendarid === '' + filter; - } - }; - - TasksModel.prototype.filteredTasks = function(needle) { - var ancestors, parentID, ret, task, tasks, _i, _len; - ret = []; - tasks = this.getAll(); - if (!needle) { - ret = tasks; - } else { - for (_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.getIdByUid(task.related); - ancestors = this.getAncestor(parentID, ret); - if (ancestors) { - ret = ret.concat(ancestors); - } - } - } - } - return ret; - }; - - TasksModel.prototype.objectExists = function(task, ret) { - var re, _i, _len; - for (_i = 0, _len = ret.length; _i < _len; _i++) { - re = ret[_i]; - if (re.id === task.id) { - return true; - } - } - return false; - }; - - TasksModel.prototype.getAncestor = function(taskID, ret) { - var ancestors, parentID, task, tasks; - tasks = []; - task = this.getById(taskID); - if (task) { - if (this.objectExists(task, ret)) { - return tasks; - } - tasks.push(task); - if (this.hasNoParent(task)) { - return tasks; - } - parentID = this.getIdByUid(task.related); - ancestors = this.getAncestor(parentID, ret); - if (ancestors) { - tasks = tasks.concat(ancestors); - } - } - return tasks; - }; - - TasksModel.prototype.filterTasksByString = function(task, filter) { - var category, comment, key, keys, value, _i, _j, _len, _len1, _ref, _ref1; - keys = ['name', 'note', 'location', 'categories', 'comments']; - filter = filter.toLowerCase(); - for (key in task) { - value = task[key]; - if (__indexOf.call(keys, key) >= 0) { - if (key === 'comments') { - _ref = task.comments; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - comment = _ref[_i]; - if (comment.comment.toLowerCase().indexOf(filter) !== -1) { - return true; - } - } - } else if (key === 'categories') { - _ref1 = task.categories; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - category = _ref1[_j]; - if (category.toLowerCase().indexOf(filter) !== -1) { - return true; - } - } - } else if (value.toLowerCase().indexOf(filter) !== -1) { - return true; - } - } - } - return false; - }; - - TasksModel.prototype.hideSubtasks = function(taskID) { - return this.getById(taskID).hidesubtasks; - }; - - TasksModel.prototype.setHideSubtasks = function(taskID, hide) { - return this.update({ - id: taskID, - hidesubtasks: hide - }); - }; - - TasksModel.prototype.starred = function(taskID) { - return this.getById(taskID).starred; - }; - - TasksModel.prototype.star = function(taskID) { - return this.update({ - id: taskID, - starred: true - }); - }; - - TasksModel.prototype.unstar = function(taskID) { - return this.update({ - id: taskID, - starred: false - }); - }; - - TasksModel.prototype.setPriority = function(taskID, priority) { - return this.update({ - id: taskID, - priority: priority - }); - }; - - TasksModel.prototype.completed = function(taskID) { - return this.getById(taskID).completed; - }; - - TasksModel.prototype.complete = function(taskID) { - return this.update({ - id: taskID, - completed: true, - completed_date: moment().format("YYYYMMDDTHHmmss") - }); - }; - - TasksModel.prototype.uncomplete = function(taskID) { - return this.update({ - id: taskID, - completed: false, - completed_date: null - }); - }; - - TasksModel.prototype.setPercentComplete = function(taskID, complete) { - return this.update({ - id: taskID, - complete: complete - }); - }; - - TasksModel.prototype.setDueDate = function(taskID, date) { - return this.update({ - id: taskID, - due: date - }); - }; - - TasksModel.prototype.setReminder = function(taskID, reminder) { - return this.update({ - id: taskID, - reminder: reminder - }); - }; - - TasksModel.prototype.setStartDate = function(taskID, date) { - return this.update({ - id: taskID, - start: date - }); - }; - - 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; - }; - - TasksModel.prototype.changeCalendarId = function(taskID, calendarID) { - return this.update({ - id: taskID, - calendarid: calendarID - }); - }; - - TasksModel.prototype.changeParent = function(taskID, related) { - return this.update({ - id: taskID, - related: related - }); - }; - - TasksModel.prototype.setNote = function(taskID, note) { - return this.update({ - id: taskID, - note: note - }); - }; - - TasksModel.prototype.addComment = function(comment) { - var task; - task = this.getById(comment.taskID); - if (task.comments) { - return task.comments.push(comment); - } else { - return task.comments = [comment]; - } - }; - - TasksModel.prototype.updateComment = function(comment) { - var com, i, task, _i, _len, _ref, _results; - task = this.getById(comment.taskID); - i = 0; - _ref = task.comments; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - com = _ref[_i]; - if (com.tmpID === comment.tmpID) { - task.comments[i] = comment; - break; - } - _results.push(i++); - } - return _results; - }; - - TasksModel.prototype.deleteComment = function(taskID, commentID) { - var comment, i, task, _i, _len, _ref, _results; - task = this.getById(taskID); - i = 0; - _ref = task.comments; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - comment = _ref[_i]; - if (comment.id === commentID) { - task.comments.splice(i, 1); - break; - } - _results.push(i++); - } - return _results; - }; + TasksModel.prototype.add = function(task, clearCache) { + var tmptask, updateById, updateByTmpId; + if (clearCache == null) { + clearCache = true; + } + tmptask = this._tmpIdCache[task.tmpID]; + updateById = angular.isDefined(task.id) && angular.isDefined(this.getById(task.id)); + updateByTmpId = angular.isDefined(tmptask); + if (updateById || updateByTmpId) { + return this.update(task, clearCache); + } else { + if (angular.isDefined(task.id) && angular.isUndefined(task.tmpID)) { + return TasksModel.__super__.add.call(this, task, clearCache); + } else { + this._tmpIdCache[task.tmpID] = task; + this._data.push(task); + if (clearCache) { + return this._invalidateCache(); + } + } + } + }; - return TasksModel; + TasksModel.prototype.update = function(task, clearCache) { + var tmptask; + if (clearCache == null) { + clearCache = true; + } + tmptask = this._tmpIdCache[task.tmpID]; + if (angular.isDefined(task.id) && angular.isDefined(tmptask)) { + tmptask.id = task.id; + this._dataMap[task.id] = tmptask; + } + task["void"] = false; + return TasksModel.__super__.update.call(this, task, clearCache); + }; - })(_Model); - return new TasksModel(); - } + TasksModel.prototype.removeById = function(taskID) { + return TasksModel.__super__.removeById.call(this, taskID); + }; + + TasksModel.prototype.voidAll = function() { + var task, tasks, _i, _len, _results; + tasks = this.getAll(); + _results = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + _results.push(task["void"] = true); + } + return _results; + }; + + TasksModel.prototype.removeVoid = function() { + var id, task, taskIDs, tasks, _i, _j, _len, _len1, _results; + tasks = this.getAll(); + taskIDs = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task["void"]) { + taskIDs.push(task.id); + } + } + _results = []; + for (_j = 0, _len1 = taskIDs.length; _j < _len1; _j++) { + id = taskIDs[_j]; + _results.push(this.removeById(id)); + } + return _results; + }; + + TasksModel.prototype.removeByList = function(listID) { + var id, task, taskIDs, tasks, _i, _j, _len, _len1, _results; + tasks = this.getAll(); + taskIDs = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.calendarid === listID) { + taskIDs.push(task.id); + } + } + _results = []; + for (_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.getById(task.id)) { + return true; + } else { + return false; + } + }; + + TasksModel.prototype.hasSubtasks = function(uid) { + var task, tasks, _i, _len; + tasks = this.getAll(); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.related === uid) { + return true; + } + } + return false; + }; + + TasksModel.prototype.hasNoParent = function(task) { + var t, tasks, _i, _len; + if (!task.related) { + return true; + } else { + tasks = this.getAll(); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + t = tasks[_i]; + if (task.related === t.uid) { + return false; + } + } + return true; + } + }; + + TasksModel.prototype.getIdByUid = function(uid) { + var task, tasks, _i, _len; + tasks = this.getAll(); + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + if (task.uid === uid) { + return task.id; + } + } + return false; + }; + + TasksModel.prototype.getChildrenID = function(taskID) { + var childrenID, t, task, tasks, _i, _len; + task = this.getById(taskID); + tasks = this.getAll(); + childrenID = []; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + t = tasks[_i]; + if (t.related === task.uid) { + childrenID.push(t.id); + } + } + return childrenID; + }; + + TasksModel.prototype.getDescendantID = function(taskID) { + var childID, childrenID, descendantID, _i, _len; + childrenID = this.getChildrenID(taskID); + descendantID = []; + descendantID = descendantID.concat(childrenID); + for (_i = 0, _len = childrenID.length; _i < _len; _i++) { + childID = childrenID[_i]; + descendantID = descendantID.concat(this.getDescendantID(childID)); + } + return descendantID; + }; + + 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.starred === true; + 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.calendarid === '' + filter; + } + }; + + TasksModel.prototype.filteredTasks = function(needle) { + var ancestors, parentID, ret, task, tasks, _i, _len; + ret = []; + tasks = this.getAll(); + if (!needle) { + ret = tasks; + } else { + for (_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.getIdByUid(task.related); + ancestors = this.getAncestor(parentID, ret); + if (ancestors) { + ret = ret.concat(ancestors); + } + } + } + } + return ret; + }; + + TasksModel.prototype.objectExists = function(task, ret) { + var re, _i, _len; + for (_i = 0, _len = ret.length; _i < _len; _i++) { + re = ret[_i]; + if (re.id === task.id) { + return true; + } + } + return false; + }; + + TasksModel.prototype.getAncestor = function(taskID, ret) { + var ancestors, parentID, task, tasks; + tasks = []; + task = this.getById(taskID); + if (task) { + if (this.objectExists(task, ret)) { + return tasks; + } + tasks.push(task); + if (this.hasNoParent(task)) { + return tasks; + } + parentID = this.getIdByUid(task.related); + ancestors = this.getAncestor(parentID, ret); + if (ancestors) { + tasks = tasks.concat(ancestors); + } + } + return tasks; + }; + + TasksModel.prototype.filterTasksByString = function(task, filter) { + var category, comment, key, keys, value, _i, _j, _len, _len1, _ref, _ref1; + keys = ['name', 'note', 'location', 'categories', 'comments']; + filter = filter.toLowerCase(); + for (key in task) { + value = task[key]; + if (__indexOf.call(keys, key) >= 0) { + if (key === 'comments') { + _ref = task.comments; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + comment = _ref[_i]; + if (comment.comment.toLowerCase().indexOf(filter) !== -1) { + return true; + } + } + } else if (key === 'categories') { + _ref1 = task.categories; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + category = _ref1[_j]; + if (category.toLowerCase().indexOf(filter) !== -1) { + return true; + } + } + } else if (value.toLowerCase().indexOf(filter) !== -1) { + return true; + } + } + } + return false; + }; + + TasksModel.prototype.hideSubtasks = function(taskID) { + return this.getById(taskID).hidesubtasks; + }; + + TasksModel.prototype.setHideSubtasks = function(taskID, hide) { + return this.update({ + id: taskID, + hidesubtasks: hide + }); + }; + + TasksModel.prototype.starred = function(taskID) { + return this.getById(taskID).starred; + }; + + TasksModel.prototype.star = function(taskID) { + return this.update({ + id: taskID, + starred: true + }); + }; + + TasksModel.prototype.unstar = function(taskID) { + return this.update({ + id: taskID, + starred: false + }); + }; + + TasksModel.prototype.setPriority = function(taskID, priority) { + return this.update({ + id: taskID, + priority: priority + }); + }; + + TasksModel.prototype.completed = function(taskID) { + return this.getById(taskID).completed; + }; + + TasksModel.prototype.complete = function(taskID) { + return this.update({ + id: taskID, + completed: true, + completed_date: moment().format("YYYYMMDDTHHmmss") + }); + }; + + TasksModel.prototype.uncomplete = function(taskID) { + return this.update({ + id: taskID, + completed: false, + completed_date: null + }); + }; + + TasksModel.prototype.setPercentComplete = function(taskID, complete) { + return this.update({ + id: taskID, + complete: complete + }); + }; + + TasksModel.prototype.setDueDate = function(taskID, date) { + return this.update({ + id: taskID, + due: date + }); + }; + + TasksModel.prototype.setReminder = function(taskID, reminder) { + return this.update({ + id: taskID, + reminder: reminder + }); + }; + + TasksModel.prototype.setStartDate = function(taskID, date) { + return this.update({ + id: taskID, + start: date + }); + }; + + 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; + }; + + TasksModel.prototype.changeCalendarId = function(taskID, calendarID) { + return this.update({ + id: taskID, + calendarid: calendarID + }); + }; + + TasksModel.prototype.changeParent = function(taskID, related) { + return this.update({ + id: taskID, + related: related + }); + }; + + TasksModel.prototype.setNote = function(taskID, note) { + return this.update({ + id: taskID, + note: note + }); + }; + + TasksModel.prototype.addComment = function(comment) { + var task; + task = this.getById(comment.taskID); + if (task.comments) { + return task.comments.push(comment); + } else { + return task.comments = [comment]; + } + }; + + TasksModel.prototype.updateComment = function(comment) { + var com, i, task, _i, _len, _ref, _results; + task = this.getById(comment.taskID); + i = 0; + _ref = task.comments; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + com = _ref[_i]; + if (com.tmpID === comment.tmpID) { + task.comments[i] = comment; + break; + } + _results.push(i++); + } + return _results; + }; + + TasksModel.prototype.deleteComment = function(taskID, commentID) { + var comment, i, task, _i, _len, _ref, _results; + task = this.getById(taskID); + i = 0; + _ref = task.comments; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + comment = _ref[_i]; + if (comment.id === commentID) { + task.comments.splice(i, 1); + break; + } + _results.push(i++); + } + return _results; + }; + + return TasksModel; + + })(_Model); + return new TasksModel(); + } ]); }).call(this); (function() { angular.module('Tasks').factory('Persistence', [ - 'Request', 'Loading', '$rootScope', '$q', 'CalendarService', function(Request, Loading, $rootScope, $q, CalendarService) { - var Persistence; - Persistence = (function() { - function Persistence(_request, _Loading, _$rootScope, _CalendarService) { - this._request = _request; - this._Loading = _Loading; - this._$rootScope = _$rootScope; - this._CalendarService = _CalendarService; - } + 'Request', 'Loading', '$rootScope', '$q', 'CalendarService', function(Request, Loading, $rootScope, $q, CalendarService) { + var Persistence; + Persistence = (function() { + function Persistence(_request, _Loading, _$rootScope, _CalendarService) { + this._request = _request; + this._Loading = _Loading; + this._$rootScope = _$rootScope; + this._CalendarService = _CalendarService; + } - Persistence.prototype.init = function() { - var successCallback, - _this = this; - this.deferred = $q.defer(); - successCallback = function() { - return _this.deferred.resolve(); - }; - this.getCollections(); - this.getSettings(); - return this.deferred.promise; - }; - - Persistence.prototype.getCollections = function(onSuccess, showLoading) { - var failureCallbackWrapper, params, successCallbackWrapper, - _this = this; - if (showLoading == null) { - showLoading = true; - } - onSuccess || (onSuccess = function() {}); - if (showLoading) { - this._Loading.increase(); - successCallbackWrapper = function(data) { - onSuccess(); - return _this._Loading.decrease(); - }; - failureCallbackWrapper = function(data) { - return _this._Loading.decrease(); - }; - } else { - successCallbackWrapper = function(data) { - return onSuccess(); - }; - failureCallbackWrapper = function(data) {}; - } - params = { - onSuccess: successCallbackWrapper, - onFailure: failureCallbackWrapper - }; - return this._request.get('/apps/tasks/collections', params); - }; - - Persistence.prototype.getSettings = function(onSuccess, showLoading) { - var failureCallbackWrapper, params, successCallbackWrapper, - _this = this; - if (showLoading == null) { - showLoading = true; - } - onSuccess || (onSuccess = function() {}); - if (showLoading) { - this._Loading.increase(); - successCallbackWrapper = function(data) { - onSuccess(); - return _this._Loading.decrease(); - }; - failureCallbackWrapper = function(data) { - return _this._Loading.decrease(); - }; - } else { - successCallbackWrapper = function(data) { - return onSuccess(); - }; - failureCallbackWrapper = function(data) {}; - } - params = { - onSuccess: successCallbackWrapper, - onFailure: failureCallbackWrapper - }; - return this._request.get('/apps/tasks/settings', params); - }; - - Persistence.prototype.setVisibility = function(collectionID, visibility) { - var params; - params = { - routeParams: { - collectionID: collectionID, - visibility: visibility - } - }; - return this._request.post('/apps/tasks/collection/\ + Persistence.prototype.init = function() { + var successCallback, + _this = this; + this.deferred = $q.defer(); + successCallback = function() { + return _this.deferred.resolve(); + }; + this.getCollections(); + this.getSettings(); + return this.deferred.promise; + }; + + Persistence.prototype.getCollections = function(onSuccess, showLoading) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (showLoading == null) { + showLoading = true; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function(data) { + return onSuccess(); + }; + failureCallbackWrapper = function(data) {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('/apps/tasks/collections', params); + }; + + Persistence.prototype.getSettings = function(onSuccess, showLoading) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (showLoading == null) { + showLoading = true; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function(data) { + return onSuccess(); + }; + failureCallbackWrapper = function(data) {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper + }; + return this._request.get('/apps/tasks/settings', params); + }; + + Persistence.prototype.setVisibility = function(collectionID, visibility) { + var params; + params = { + routeParams: { + collectionID: collectionID, + visibility: visibility + } + }; + return this._request.post('/apps/tasks/collection/\ {collectionID}/visibility/{visibility}', params); - }; - - Persistence.prototype.setting = function(type, setting, value) { - var params; - params = { - routeParams: { - type: type, - setting: setting, - value: +value - } - }; - return this._request.post('/apps/tasks/settings/\ + }; + + Persistence.prototype.setting = function(type, setting, value) { + var params; + params = { + routeParams: { + type: type, + setting: setting, + value: +value + } + }; + return this._request.post('/apps/tasks/settings/\ {type}/{setting}/{value}', params); - }; - - Persistence.prototype.getLists = function(onSuccess, showLoading, which) { - var failureCallbackWrapper, params, successCallbackWrapper, - _this = this; - if (showLoading == null) { - showLoading = true; - } - if (which == null) { - which = 'all'; - } - onSuccess || (onSuccess = function() {}); - if (showLoading) { - this._Loading.increase(); - successCallbackWrapper = function(data) { - onSuccess(); - return _this._Loading.decrease(); - }; - failureCallbackWrapper = function(data) { - return _this._Loading.decrease(); - }; - } else { - successCallbackWrapper = function(data) { - return onSuccess(); - }; - failureCallbackWrapper = function(data) {}; - } - params = { - onSuccess: successCallbackWrapper, - onFailure: failureCallbackWrapper, - routeParams: { - request: which - } - }; - return this._request.get('/apps/tasks/lists', params); - }; - - Persistence.prototype.addList = function(list, onSuccess, onFailure) { - var params; - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - onSuccess || (onSuccess = function() {}); - onFailure || (onFailure = function() {}); - params = { - data: { - name: list.displayname, - tmpID: list.tmpID - }, - onSuccess: onSuccess, - onFailure: onFailure - }; - return this._request.post('/apps/tasks/lists/add', params); - }; - - Persistence.prototype.setListName = function(list) { - var params; - params = { - routeParams: { - listID: list.id - }, - data: { - name: list.displayname - } - }; - return this._request.post('/apps/tasks/lists/{listID}/name', params); - }; - - Persistence.prototype.deleteList = function(listID) { - var params; - params = { - routeParams: { - listID: listID - } - }; - return this._request.post('/apps/tasks/lists/{listID}/delete', params); - }; - - Persistence.prototype.getTasks = function(type, listID, onSuccess, showLoading) { - var failureCallbackWrapper, params, successCallbackWrapper, - _this = this; - if (type == null) { - type = 'init'; - } - if (listID == null) { - listID = 'all'; - } - if (showLoading == null) { - showLoading = true; - } - onSuccess || (onSuccess = function() {}); - if (showLoading) { - this._Loading.increase(); - successCallbackWrapper = function(data) { - onSuccess(); - return _this._Loading.decrease(); - }; - failureCallbackWrapper = function(data) { - return _this._Loading.decrease(); - }; - } else { - successCallbackWrapper = function(data) { - return onSuccess(); - }; - failureCallbackWrapper = function(data) {}; - } - params = { - onSuccess: successCallbackWrapper, - onFailure: failureCallbackWrapper, - routeParams: { - listID: listID, - type: type - } - }; - return this._request.get('/apps/tasks/tasks/{type}/{listID}', params); - }; - - Persistence.prototype.getTask = function(taskID, onSuccess, showLoading) { - var failureCallbackWrapper, params, successCallbackWrapper, - _this = this; - if (showLoading == null) { - showLoading = true; - } - onSuccess || (onSuccess = function() {}); - if (showLoading) { - this._Loading.increase(); - successCallbackWrapper = function() { - onSuccess(); - return _this._Loading.decrease(); - }; - failureCallbackWrapper = function() { - return _this._Loading.decrease(); - }; - } else { - successCallbackWrapper = function() { - return onSuccess(); - }; - failureCallbackWrapper = function() {}; - } - params = { - onSuccess: successCallbackWrapper, - onFailure: failureCallbackWrapper, - routeParams: { - taskID: taskID - } - }; - return this._request.get('/apps/tasks/task/{taskID}', params); - }; - - Persistence.prototype.setPercentComplete = function(taskID, complete) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - complete: complete - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/percentcomplete', params); - }; - - Persistence.prototype.setPriority = function(taskID, priority) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - priority: priority - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/priority', params); - }; - - Persistence.prototype.setHideSubtasks = function(taskID, hide) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - hide: hide - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/hidesubtasks', params); - }; - - Persistence.prototype.addTask = function(task, onSuccess, onFailure) { - var params; - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - onSuccess || (onSuccess = function() {}); - onFailure || (onFailure = function() {}); - params = { - data: { - name: task.name, - related: task.related, - calendarID: task.calendarid, - starred: task.starred, - due: task.due, - start: task.start, - tmpID: task.tmpID - }, - onSuccess: onSuccess, - onFailure: onFailure - }; - return this._request.post('/apps/tasks/tasks/add', params); - }; - - Persistence.prototype.deleteTask = function(taskID) { - var params; - params = { - routeParams: { - taskID: taskID - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/delete', params); - }; - - Persistence.prototype.setDueDate = function(taskID, due) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - due: due - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/due', params); - }; - - Persistence.prototype.setStartDate = function(taskID, start) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - start: start - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/start', params); - }; - - Persistence.prototype.setReminder = function(taskID, reminder) { - var params; - if (reminder === false) { - params = { - routeParams: { - taskID: taskID - }, - data: { - type: false - } - }; - } else if (reminder.type === 'DATE-TIME') { - params = { - routeParams: { - taskID: taskID - }, - data: { - type: reminder.type, - action: reminder.action, - date: moment(reminder.date, 'YYYYMMDDTHHmmss').unix() - } - }; - } else if (reminder.type === 'DURATION') { - params = { - routeParams: { - taskID: taskID - }, - data: { - type: reminder.type, - action: reminder.action, - week: reminder.duration.week, - day: reminder.duration.day, - hour: reminder.duration.hour, - minute: reminder.duration.minute, - second: reminder.duration.second, - invert: reminder.duration.params.invert, - related: reminder.duration.params.related - } - }; - } else { - return; - } - return this._request.post('/apps/tasks/tasks/{taskID}/reminder', params); - }; - - Persistence.prototype.changeCalendarId = function(taskID, calendarID) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - calendarID: calendarID - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/calendar', params); - }; - - Persistence.prototype.changeParent = function(taskID, related) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - related: related - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/parent', params); - }; - - Persistence.prototype.setTaskName = function(taskID, name) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - name: name - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/name', params); - }; - - Persistence.prototype.setTaskNote = function(taskID, note) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - note: note - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/note', params); - }; - - Persistence.prototype.setShowHidden = function(showHidden) { - var params; - params = { - routeParams: { - showHidden: +showHidden - } - }; - return this._request.post('/apps/tasks/settings/showhidden/{showHidden}', params); - }; - - Persistence.prototype.addComment = function(comment, onSuccess, onFailure) { - var params; - if (onSuccess == null) { - onSuccess = null; - } - if (onFailure == null) { - onFailure = null; - } - params = { - routeParams: { - taskID: comment.taskID - }, - data: { - comment: comment.comment, - tmpID: comment.tmpID - }, - onSuccess: onSuccess, - onFailure: onFailure - }; - return this._request.post('/apps/tasks/tasks/{taskID}/comment', params); - }; - - Persistence.prototype.deleteComment = function(taskID, commentID) { - var params; - params = { - routeParams: { - taskID: taskID, - commentID: commentID - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/comment/\ - {commentID}/delete', params); - }; - - Persistence.prototype.addCategory = function(taskID, category) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - category: category - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/category/add', params); - }; - - Persistence.prototype.removeCategory = function(taskID, category) { - var params; - params = { - routeParams: { - taskID: taskID - }, - data: { - category: category - } - }; - return this._request.post('/apps/tasks/tasks/{taskID}/category/remove', params); - }; + }; - return Persistence; + Persistence.prototype.getLists = function(onSuccess, showLoading, which) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (showLoading == null) { + showLoading = true; + } + if (which == null) { + which = 'all'; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function(data) { + return onSuccess(); + }; + failureCallbackWrapper = function(data) {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper, + routeParams: { + request: which + } + }; + return this._request.get('/apps/tasks/lists', params); + }; - })(); - return new Persistence(Request, Loading, $rootScope, CalendarService); - } - ]); + Persistence.prototype.addList = function(list, onSuccess, onFailure) { + var params; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + params = { + data: { + name: list.displayname, + tmpID: list.tmpID + }, + onSuccess: onSuccess, + onFailure: onFailure + }; + return this._request.post('/apps/tasks/lists/add', params); + }; -}).call(this); + Persistence.prototype.setListName = function(list) { + var params; + params = { + routeParams: { + listID: list.id + }, + data: { + name: list.displayname + } + }; + return this._request.post('/apps/tasks/lists/{listID}/name', params); + }; -(function() { - angular.module('Tasks').factory('Publisher', [ - 'CollectionsModel', 'SettingsModel', function(CollectionsModel, SettingsModel) { - var Publisher; - Publisher = (function() { - function Publisher(_$collectionsmodel, _$settingsmodel) { - this._$collectionsmodel = _$collectionsmodel; - this._$settingsmodel = _$settingsmodel; - this._subscriptions = {}; - this.subscribeObjectTo(this._$collectionsmodel, 'collections'); - this.subscribeObjectTo(this._$settingsmodel, 'settings'); - } + Persistence.prototype.deleteList = function(listID) { + var params; + params = { + routeParams: { + listID: listID + } + }; + return this._request.post('/apps/tasks/lists/{listID}/delete', params); + }; - Publisher.prototype.subscribeObjectTo = function(object, name) { - var base; - (base = this._subscriptions)[name] || (base[name] = []); - return this._subscriptions[name].push(object); - }; - - Publisher.prototype.publishDataTo = function(data, name) { - var ref, results, subscriber, _i, _len; - ref = this._subscriptions[name] || []; - results = []; - for (_i = 0, _len = ref.length; _i < _len; _i++) { - subscriber = ref[_i]; - results.push(subscriber.handle(data)); - } - return results; - }; - - return Publisher; + Persistence.prototype.getTasks = function(type, listID, onSuccess, showLoading) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (type == null) { + type = 'init'; + } + if (listID == null) { + listID = 'all'; + } + if (showLoading == null) { + showLoading = true; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function(data) { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function(data) { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function(data) { + return onSuccess(); + }; + failureCallbackWrapper = function(data) {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper, + routeParams: { + listID: listID, + type: type + } + }; + return this._request.get('/apps/tasks/tasks/{type}/{listID}', params); + }; - })(); - return new Publisher(CollectionsModel, SettingsModel); - } - ]); + Persistence.prototype.getTask = function(taskID, onSuccess, showLoading) { + var failureCallbackWrapper, params, successCallbackWrapper, + _this = this; + if (showLoading == null) { + showLoading = true; + } + onSuccess || (onSuccess = function() {}); + if (showLoading) { + this._Loading.increase(); + successCallbackWrapper = function() { + onSuccess(); + return _this._Loading.decrease(); + }; + failureCallbackWrapper = function() { + return _this._Loading.decrease(); + }; + } else { + successCallbackWrapper = function() { + return onSuccess(); + }; + failureCallbackWrapper = function() {}; + } + params = { + onSuccess: successCallbackWrapper, + onFailure: failureCallbackWrapper, + routeParams: { + taskID: taskID + } + }; + return this._request.get('/apps/tasks/task/{taskID}', params); + }; -}).call(this); + Persistence.prototype.setPercentComplete = function(taskID, complete) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + complete: complete + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/percentcomplete', params); + }; -(function() { - angular.module('Tasks').factory('Request', [ - '$http', 'Publisher', function($http, Publisher) { - var Request; - Request = (function() { - function Request($http, publisher) { - this.$http = $http; - this.publisher = publisher; - this.count = 0; - this.initialized = false; - this.shelvedRequests = []; - this.initialized = true; - this._executeShelvedRequests(); - } + Persistence.prototype.setPriority = function(taskID, priority) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + priority: priority + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/priority', params); + }; - Request.prototype.request = function(route, data) { - var defaultConfig, defaultData, url; - if (data === null) { - data = {}; - } - defaultData = { - routeParams: {}, - data: {}, - onSuccess: function() { - return {}; - }, - onFailure: function() { - return {}; - }, - config: {} - }; - angular.extend(defaultData, data); - if (!this.initialized) { - this._shelveRequest(route, defaultData); - return; - } - url = OC.generateUrl(route, defaultData.routeParams); - defaultConfig = { - url: url, - data: defaultData.data - }; - angular.extend(defaultConfig, defaultData.config); - if (defaultConfig.method === 'GET') { - defaultConfig.params = defaultConfig.data; - } - return this.$http(defaultConfig).success((function(_this) { - return function(data, status, headers, config) { - var name, ref, value; - ref = data.data; - for (name in ref) { - value = ref[name]; - _this.publisher.publishDataTo(value, name); - } - return defaultData.onSuccess(data, status, headers, config); - }; - })(this)).error(function(data, status, headers, config) { - return defaultData.onFailure(data, status, headers, config); - }); - }; - - Request.prototype.post = function(route, data) { - if (data === null) { - data = {}; - } - data.config || (data.config = {}); - data.config.method = 'POST'; - return this.request(route, data); - }; - - Request.prototype.get = function(route, data) { - if (data === null) { - data = {}; - } - data.config || (data.config = {}); - data.config.method = 'GET'; - return this.request(route, data); - }; - - Request.prototype.put = function(route, data) { - if (data === null) { - data = {}; - } - data.config || (data.config = {}); - data.config.method = 'PUT'; - return this.request(route, data); - }; - - Request.prototype["delete"] = function(route, data) { - if (data === null) { - data = {}; - } - data.config || (data.config = {}); - data.config.method = 'DELETE'; - return this.request(route, data); - }; - - Request.prototype._shelveRequest = function(route, data) { - var request; - request = { - route: route, - data: data - }; - return this.shelvedRequests.push(request); - }; - - Request.prototype._executeShelvedRequests = function() { - var r, ref, results, _i, _len; - ref = this.shelvedRequests; - results = []; - for (_i = 0, _len = ref.length; _i < _len; _i++) { - r = ref[_i]; - results.push(this.request(r.route, r.data)); - } - return results; - }; - - return Request; + Persistence.prototype.setHideSubtasks = function(taskID, hide) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + hide: hide + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/hidesubtasks', params); + }; - })(); - return new Request($http, Publisher); - } - ]); + Persistence.prototype.addTask = function(task, onSuccess, onFailure) { + var params; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + onSuccess || (onSuccess = function() {}); + onFailure || (onFailure = function() {}); + params = { + data: { + name: task.name, + related: task.related, + calendarID: task.calendarid, + starred: task.starred, + due: task.due, + start: task.start, + tmpID: task.tmpID + }, + onSuccess: onSuccess, + onFailure: onFailure + }; + return this._request.post('/apps/tasks/tasks/add', params); + }; -}).call(this); + Persistence.prototype.deleteTask = function(taskID) { + var params; + params = { + routeParams: { + taskID: taskID + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/delete', params); + }; -(function() { - angular.module('Tasks').factory('Status', [ - function() { - var Status; - Status = (function() { - function Status() { - this._$status = { - addingList: false, - focusTaskInput: false - }; - } + Persistence.prototype.setDueDate = function(taskID, due) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + due: due + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/due', params); + }; - Status.prototype.getStatus = function() { - return this._$status; - }; + Persistence.prototype.setStartDate = function(taskID, start) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + start: start + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/start', params); + }; - return Status; + Persistence.prototype.setReminder = function(taskID, reminder) { + var params; + if (reminder === false) { + params = { + routeParams: { + taskID: taskID + }, + data: { + type: false + } + }; + } else if (reminder.type === 'DATE-TIME') { + params = { + routeParams: { + taskID: taskID + }, + data: { + type: reminder.type, + action: reminder.action, + date: moment(reminder.date, 'YYYYMMDDTHHmmss').unix() + } + }; + } else if (reminder.type === 'DURATION') { + params = { + routeParams: { + taskID: taskID + }, + data: { + type: reminder.type, + action: reminder.action, + week: reminder.duration.week, + day: reminder.duration.day, + hour: reminder.duration.hour, + minute: reminder.duration.minute, + second: reminder.duration.second, + invert: reminder.duration.params.invert, + related: reminder.duration.params.related + } + }; + } else { + return; + } + return this._request.post('/apps/tasks/tasks/{taskID}/reminder', params); + }; - })(); - return new Status(); - } - ]); + Persistence.prototype.changeCalendarId = function(taskID, calendarID) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + calendarID: calendarID + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/calendar', params); + }; -}).call(this); + Persistence.prototype.changeParent = function(taskID, related) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + related: related + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/parent', params); + }; -(function() { - angular.module('Tasks').filter('counterFormatter', function() { - return function(count) { - switch (false) { - case count !== 0: - return ''; - case !(count > 999): - return '999+'; - default: - return count; - } - }; - }); + Persistence.prototype.setTaskName = function(taskID, name) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + name: name + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/name', params); + }; -}).call(this); + Persistence.prototype.setTaskNote = function(taskID, note) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + note: note + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/note', params); + }; -(function() { - angular.module('Tasks').filter('dateDetails', function() { - return function(due) { - if (moment(due, "YYYYMMDDTHHmmss").isValid()) { - return moment(due, "YYYYMMDDTHHmmss").locale('details').calendar(); - } else { - return t('tasks', 'Set due date'); - } - }; - }); + Persistence.prototype.setShowHidden = function(showHidden) { + var params; + params = { + routeParams: { + showHidden: +showHidden + } + }; + return this._request.post('/apps/tasks/settings/showhidden/{showHidden}', params); + }; -}).call(this); + Persistence.prototype.addComment = function(comment, onSuccess, onFailure) { + var params; + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + params = { + routeParams: { + taskID: comment.taskID + }, + data: { + comment: comment.comment, + tmpID: comment.tmpID + }, + onSuccess: onSuccess, + onFailure: onFailure + }; + return this._request.post('/apps/tasks/tasks/{taskID}/comment', params); + }; -(function() { - angular.module('Tasks').filter('dateDetailsShort', function() { - return function(reminder) { - if (moment(reminder, "YYYYMMDDTHHmmss").isValid()) { - return moment(reminder, "YYYYMMDDTHHmmss").locale('details_short').calendar(); - } else { - return ''; - } - }; - }); + Persistence.prototype.deleteComment = function(taskID, commentID) { + var params; + params = { + routeParams: { + taskID: taskID, + commentID: commentID + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/comment/\ + {commentID}/delete', params); + }; -}).call(this); + Persistence.prototype.addCategory = function(taskID, category) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + category: category + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/category/add', params); + }; -(function() { - angular.module('Tasks').filter('dateFromNow', function() { - return function(due) { - if (moment(due, "YYYYMMDDTHHmmss").isValid()) { - return moment(due, "YYYYMMDDTHHmmss").fromNow(); - } else { - return ''; - } - }; - }); + Persistence.prototype.removeCategory = function(taskID, category) { + var params; + params = { + routeParams: { + taskID: taskID + }, + data: { + category: category + } + }; + return this._request.post('/apps/tasks/tasks/{taskID}/category/remove', params); + }; -}).call(this); + return Persistence; -(function() { - angular.module('Tasks').filter('dateTaskList', function() { - return function(due) { - if (moment(due, "YYYYMMDDTHHmmss").isValid()) { - return moment(due, "YYYYMMDDTHHmmss").locale('tasks').calendar(); - } else { - return ''; - } - }; - }); + })(); + return new Persistence(Request, Loading, $rootScope, CalendarService); + } + ]); }).call(this); (function() { - angular.module('Tasks').filter('day', function() { - return function(i) { - return moment().add('days', i).locale('list_week').calendar(); - }; - }); + angular.module('Tasks').factory('Publisher', [ + 'CollectionsModel', 'SettingsModel', function(CollectionsModel, SettingsModel) { + var Publisher; + Publisher = (function() { + function Publisher(_$collectionsmodel, _$settingsmodel) { + this._$collectionsmodel = _$collectionsmodel; + this._$settingsmodel = _$settingsmodel; + this._subscriptions = {}; + this.subscribeObjectTo(this._$collectionsmodel, 'collections'); + this.subscribeObjectTo(this._$settingsmodel, 'settings'); + } -}).call(this); + Publisher.prototype.subscribeObjectTo = function(object, name) { + var base; + (base = this._subscriptions)[name] || (base[name] = []); + return this._subscriptions[name].push(object); + }; -(function() { - angular.module('Tasks').filter('dayTaskList', function() { - return function(due) { - if (moment(due, "YYYYMMDDTHHmmss").isValid()) { - return moment(due, "YYYYMMDDTHHmmss").locale('tasks').calendar(); - } else { - return ''; - } - }; - }); + Publisher.prototype.publishDataTo = function(data, name) { + var ref, results, subscriber, _i, _len; + ref = this._subscriptions[name] || []; + results = []; + for (_i = 0, _len = ref.length; _i < _len; _i++) { + subscriber = ref[_i]; + results.push(subscriber.handle(data)); + } + return results; + }; -}).call(this); + return Publisher; -(function() { - angular.module('Tasks').filter('percentDetails', function() { - return function(percent) { - return t('tasks', '%s %% completed').replace('%s', percent).replace('%%', '%'); - }; - }); + })(); + return new Publisher(CollectionsModel, SettingsModel); + } + ]); }).call(this); (function() { - angular.module('Tasks').filter('priorityDetails', function() { - return function(priority) { - var string; - string = t('tasks', 'priority %s: ').replace('%s', priority); - if (+priority === 6 || +priority === 7 || +priority === 8 || +priority === 9) { - return string + ' ' + t('tasks', 'high'); - } else if (+priority === 5) { - return string + ' ' + t('tasks', 'medium'); - } else if (+priority === 1 || +priority === 2 || +priority === 3 || +priority === 4) { - return string + ' ' + t('tasks', 'low'); - } else { - return t('tasks', 'no priority assigned'); - } - }; - }); + angular.module('Tasks').factory('Request', [ + '$http', 'Publisher', function($http, Publisher) { + var Request; + Request = (function() { + function Request($http, publisher) { + this.$http = $http; + this.publisher = publisher; + this.count = 0; + this.initialized = false; + this.shelvedRequests = []; + this.initialized = true; + this._executeShelvedRequests(); + } -}).call(this); + Request.prototype.request = function(route, data) { + var defaultConfig, defaultData, url; + if (data === null) { + data = {}; + } + defaultData = { + routeParams: {}, + data: {}, + onSuccess: function() { + return {}; + }, + onFailure: function() { + return {}; + }, + config: {} + }; + angular.extend(defaultData, data); + if (!this.initialized) { + this._shelveRequest(route, defaultData); + return; + } + url = OC.generateUrl(route, defaultData.routeParams); + defaultConfig = { + url: url, + data: defaultData.data + }; + angular.extend(defaultConfig, defaultData.config); + if (defaultConfig.method === 'GET') { + defaultConfig.params = defaultConfig.data; + } + return this.$http(defaultConfig).success((function(_this) { + return function(data, status, headers, config) { + var name, ref, value; + ref = data.data; + for (name in ref) { + value = ref[name]; + _this.publisher.publishDataTo(value, name); + } + return defaultData.onSuccess(data, status, headers, config); + }; + })(this)).error(function(data, status, headers, config) { + return defaultData.onFailure(data, status, headers, config); + }); + }; -(function() { - angular.module('Tasks').filter('reminderDetails', function() { - return function(reminder, scope) { - var ds, time, token, _i, _len, _ref; - if (!(angular.isUndefined(reminder) || reminder === null)) { - if (reminder.type === 'DATE-TIME' && moment(reminder.date, "YYYYMMDDTHHmmss").isValid()) { - return moment(reminder.date, "YYYYMMDDTHHmmss").locale('reminder').calendar(); - } else if (reminder.type === 'DURATION' && reminder.duration) { - ds = t('tasks', 'Remind me'); - _ref = scope.durations; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - token = _ref[_i]; - if (+reminder.duration[token.id]) { - time = 1; - ds += ' ' + reminder.duration[token.id] + ' '; - if (+reminder.duration[token.id] === 1) { - ds += token.name; - } else { - ds += token.names; - } - } - } - if (!time) { - if (reminder.duration.params.related === 'END') { - ds += ' ' + t('tasks', 'at the end'); - } else { - ds += ' ' + t('tasks', 'at the beginning'); - } - } else { - if (reminder.duration.params.invert) { - if (reminder.duration.params.related === 'END') { - ds += ' ' + t('tasks', 'before end'); - } else { - ds += ' ' + t('tasks', 'before beginning'); - } - } else { - if (reminder.duration.params.related === 'END') { - ds += ' ' + t('tasks', 'after end'); - } else { - ds += ' ' + t('tasks', 'after beginning'); - } - } - } - return ds; - } else { - return t('tasks', 'Remind me'); - } - } else { - return t('tasks', 'Remind me'); - } - }; - }); + Request.prototype.post = function(route, data) { + if (data === null) { + data = {}; + } + data.config || (data.config = {}); + data.config.method = 'POST'; + return this.request(route, data); + }; -}).call(this); + Request.prototype.get = function(route, data) { + if (data === null) { + data = {}; + } + data.config || (data.config = {}); + data.config.method = 'GET'; + return this.request(route, data); + }; -(function() { - angular.module('Tasks').filter('startDetails', function() { - return function(due) { - if (moment(due, "YYYYMMDDTHHmmss").isValid()) { - return moment(due, "YYYYMMDDTHHmmss").locale('start').calendar(); - } else { - return t('tasks', 'Set start date'); - } - }; - }); + Request.prototype.put = function(route, data) { + if (data === null) { + data = {}; + } + data.config || (data.config = {}); + data.config.method = 'PUT'; + return this.request(route, data); + }; + + Request.prototype["delete"] = function(route, data) { + if (data === null) { + data = {}; + } + data.config || (data.config = {}); + data.config.method = 'DELETE'; + return this.request(route, data); + }; + + Request.prototype._shelveRequest = function(route, data) { + var request; + request = { + route: route, + data: data + }; + return this.shelvedRequests.push(request); + }; + + Request.prototype._executeShelvedRequests = function() { + var r, ref, results, _i, _len; + ref = this.shelvedRequests; + results = []; + for (_i = 0, _len = ref.length; _i < _len; _i++) { + r = ref[_i]; + results.push(this.request(r.route, r.data)); + } + return results; + }; + + return Request; + + })(); + return new Request($http, Publisher); + } + ]); }).call(this); (function() { - angular.module('Tasks').filter('timeTaskList', function() { - return function(due) { - if (moment(due, "YYYYMMDDTHHmmss").isValid()) { - return moment(due, "YYYYMMDDTHHmmss").format('HH:mm'); - } else { - return ''; - } - }; - }); + angular.module('Tasks').factory('Status', [ + function() { + var Status; + Status = (function() { + function Status() { + this._$status = { + addingList: false, + focusTaskInput: false + }; + } + + Status.prototype.getStatus = function() { + return this._$status; + }; + + return Status; + + })(); + return new Status(); + } + ]); }).call(this); -})(window.angular, window.jQuery, window.moment);
\ No newline at end of file +})(window.angular, window.jQuery, oc_requesttoken);
\ No newline at end of file |