Skip to content

Commit

Permalink
warn if note is saved and window would be closed, fix #52
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Posselt committed Feb 20, 2015
1 parent 588795e commit d20e28c
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 135 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
owncloud-notes (1.0.0)
* **Bugfix**: Remove flying loading icon
* **Enhancement**: Make app ready for ownCloud 8
* **Enhancement**: Show a spinner to signal when app is saving
* **Enhancement**: Prevent closing the window when app is saving

owncloud-notes (0.9)
* Security: Remove markdown support because of [XSS in markdown-js library](https://github.com/evilstreak/markdown-js/pull/52)
* **Security**: Remove markdown support because of [XSS in markdown-js library](https://github.com/evilstreak/markdown-js/pull/52)

owncloud-notes (0.7)
* Port to ownCloud internal app framework. Additional installation of the appframework app is not needed anymore
Expand Down
13 changes: 10 additions & 3 deletions js/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-wrap');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-phpunit');

grunt.loadNpmTasks('grunt-ng-annotate');

grunt.initConfig({

Expand Down Expand Up @@ -123,12 +123,19 @@ module.exports = function(grunt) {
browsers: ['PhantomJS'],
reporters: ['progress']
}
}
},

ngAnnotate: {
app: {
src: ['<%= meta.production %>app.js'],
dest: '<%= meta.production %>app.js'
}
},

});

// make tasks available under simpler commands
grunt.registerTask('build', ['jshint', 'concat', 'wrap:app']);
grunt.registerTask('build', ['jshint', 'concat', 'wrap:app', 'ngAnnotate']);
grunt.registerTask('default', ['build']);

};
5 changes: 2 additions & 3 deletions js/app/controllers/appcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
* See the COPYING file.
*/

app.controller('AppController', ['$scope', '$location', 'is',
function ($scope, $location, is) {
app.controller('AppController', function ($scope, $location, is) {
$scope.is = is;

$scope.init = function (lastViewedNote) {
if(lastViewedNote !== 0) {
$location.path('/notes/' + lastViewedNote);
}
};
}]);
});
7 changes: 3 additions & 4 deletions js/app/controllers/notecontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* See the COPYING file.
*/

app.controller('NoteController', ['$routeParams', '$scope', 'NotesModel',
'SaveQueue', 'note', 'Config',
function($routeParams, $scope, NotesModel, SaveQueue, note, Config) {
app.controller('NoteController', function($routeParams, $scope, NotesModel,
SaveQueue, note, Config) {

NotesModel.updateIfExists(note);

Expand All @@ -33,4 +32,4 @@ app.controller('NoteController', ['$routeParams', '$scope', 'NotesModel',
Config.sync();
};

}]);
});
9 changes: 4 additions & 5 deletions js/app/controllers/notescontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
*/

// This is available by using ng-controller="NotesController" in your HTML
app.controller('NotesController', ['$routeParams', '$scope', '$location',
'Restangular', 'NotesModel',
function($routeParams, $scope, $location, Restangular, NotesModel) {
app.controller('NotesController', function($routeParams, $scope, $location,
Restangular, NotesModel) {

$scope.route = $routeParams;
$scope.notes = NotesModel.getAll();
Expand All @@ -31,7 +30,7 @@ app.controller('NotesController', ['$routeParams', '$scope', '$location',
note.remove().then(function () {
NotesModel.remove(noteId);
$scope.$emit('$routeChangeError');
});
});
};

}]);
});
8 changes: 2 additions & 6 deletions js/app/directives/autofocus.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
* See the COPYING file.
*/

/**
* Like ng-change only that it does not fire when you type faster than
* 300 ms
*/
app.directive('notesAutofocus', [function () {
app.directive('notesAutofocus', function () {
return {
restrict: 'A',
link: function (scope, element, attributes) {
element.focus();
}
};
}]);
});
24 changes: 24 additions & 0 deletions js/app/directives/issaving.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2013, Bernhard Posselt <[email protected]>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING file.
*/

app.directive('notesIsSaving', function ($window) {
return {
restrict: 'A',
scope: {
'notesIsSaving': '='
},
link: function (scope, element, attributes) {
$window.onbeforeunload = function () {
if (scope.notesIsSaving) {
return t('notes', 'Note is currently saving. Leaving ' +
'the page will delete all changes!');
} else {
return null;
}
};
}
};
});
4 changes: 2 additions & 2 deletions js/app/directives/timeoutchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Like ng-change only that it does not fire when you type faster than
* 300 ms
*/
app.directive('notesTimeoutChange', ['$timeout', function ($timeout) {
app.directive('notesTimeoutChange', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attributes) {
Expand All @@ -24,4 +24,4 @@ app.directive('notesTimeoutChange', ['$timeout', function ($timeout) {
});
}
};
}]);
});
4 changes: 2 additions & 2 deletions js/app/directives/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* See the COPYING file.
*/

app.directive('notesTooltip', [function () {
app.directive('notesTooltip', function () {
return {
restrict: 'A',
link: function (scope, element, attributes) {
element.tooltip();
}
};
}]);
});
6 changes: 3 additions & 3 deletions js/app/services/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Copyright (c) 2013, Bernhard Posselt <[email protected]>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING file.
* See the COPYING file.
*/

app.factory('Config', ['Restangular', function (Restangular) {
app.factory('Config', function (Restangular) {
var Config = function (Restangular) {
this._markdown = false;
this._Restangular = Restangular;
Expand Down Expand Up @@ -32,4 +32,4 @@ app.factory('Config', ['Restangular', function (Restangular) {
};

return new Config(Restangular);
}]);
});
4 changes: 2 additions & 2 deletions js/app/services/savequeue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See the COPYING file.
*/

app.factory('SaveQueue', ['$q', function($q) {
app.factory('SaveQueue', function($q) {
var SaveQueue = function () {
this._queue = {};
this._flushLock = false;
Expand Down Expand Up @@ -54,4 +54,4 @@ app.factory('SaveQueue', ['$q', function($q) {
};

return new SaveQueue();
}]);
});
17 changes: 7 additions & 10 deletions js/config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
*/

var app = angular.module('Notes', ['restangular', 'ngRoute']).
config(['$provide', '$routeProvider', 'RestangularProvider', '$httpProvider',
'$windowProvider',
function($provide, $routeProvider, RestangularProvider, $httpProvider,
$windowProvider) {
config(function($provide, $routeProvider, RestangularProvider, $httpProvider,
$windowProvider) {
// Always send the CSRF token by default
$httpProvider.defaults.headers.common.requesttoken = oc_requesttoken;

Expand All @@ -26,8 +24,8 @@ config(['$provide', '$routeProvider', 'RestangularProvider', '$httpProvider',
// $routeParams does not work inside resolve so use $route
// note is the name of the argument that will be injected into the
// controller
note: ['$route', '$q', 'is', 'Restangular',
function ($route, $q, is, Restangular) {
/* @ngInject */
note: function ($route, $q, is, Restangular) {

var deferred = $q.defer();
var noteId = $route.current.params.noteId;
Expand All @@ -42,7 +40,7 @@ config(['$provide', '$routeProvider', 'RestangularProvider', '$httpProvider',
});

return deferred.promise;
}]
}
}
}).otherwise({
redirectTo: '/'
Expand All @@ -57,8 +55,7 @@ config(['$provide', '$routeProvider', 'RestangularProvider', '$httpProvider',



}]).run(['$rootScope', '$location', 'NotesModel', 'Config',
function ($rootScope, $location, NotesModel, Config) {
}).run(function ($rootScope, $location, NotesModel, Config) {

// get config
Config.load();
Expand All @@ -81,4 +78,4 @@ config(['$provide', '$routeProvider', 'RestangularProvider', '$httpProvider',
$location.path('/');
}
});
}]);
});
62 changes: 32 additions & 30 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
{
"name": "notes",
"description": "Notes app",
"version": "0.0.1",
"private": true,
"homepage": "https://github.com/owncloud/notes",
"repository": {
"type": "git",
"url": "[email protected]:owncloud/notes.git"
},
"bugs": "https://github.com/owncloud/notes/issues",
"dependencies": {},
"devDependencies": {
"grunt": "*",
"grunt-cli": "*",
"grunt-contrib-concat": "*",
"grunt-contrib-jshint": "*",
"grunt-contrib-watch": "*",
"karma": "*",
"grunt-karma": "*",
"grunt-wrap": "*",
"phantomjs": "*",
"grunt-phpunit": "*",
"bower": "*",
"karma-jasmine": "*",
"karma-phantomjs-launcher": "*",
"karma-chrome-launcher": "*",
"karma-firefox-launcher": "*"
},
"engine": "node >= 0.8"
}
"name": "notes",
"description": "Notes app",
"version": "0.0.1",
"private": true,
"homepage": "https://github.com/owncloud/notes",
"repository": {
"type": "git",
"url": "[email protected]:owncloud/notes.git"
},
"bugs": "https://github.com/owncloud/notes/issues",
"dependencies": {
"grunt-ng-annotate": "^0.10.0"
},
"devDependencies": {
"grunt": "*",
"grunt-cli": "*",
"grunt-contrib-concat": "*",
"grunt-contrib-jshint": "*",
"grunt-contrib-watch": "*",
"karma": "*",
"grunt-karma": "*",
"grunt-wrap": "*",
"phantomjs": "*",
"grunt-phpunit": "*",
"bower": "*",
"karma-jasmine": "*",
"karma-phantomjs-launcher": "*",
"karma-chrome-launcher": "*",
"karma-firefox-launcher": "*"
},
"engine": "node >= 0.8"
}
Loading

0 comments on commit d20e28c

Please sign in to comment.