Permalink
Browse files

revisionen löschen aus der revisionsübersicht ermöglichen

  • Loading branch information...
1 parent 077a61f commit de49d9b3bae5cf598f5b8be127c1b10713e09cb6 Stephan committed Dec 18, 2012
Showing with 96 additions and 14 deletions.
  1. +21 −1 app/modules/localeEdit/localeEdit.js
  2. +72 −13 localeEditFileManager.js
  3. +3 −0 server.js
View
22 app/modules/localeEdit/localeEdit.js
@@ -156,7 +156,7 @@ function(app, jquery, Views ) {
}).appendTo($fileWrapper);
$text.html('Größe: ' + value.size);
- var $btnDownlaod = $('<button>', {
+ var $btnDownlaod = $('<button>', {
type : "button",
'class' : "pull-right btn btn-primary",
'data-loading-text' : "downloading"
@@ -167,6 +167,26 @@ function(app, jquery, Views ) {
window.open(value.url, 'Download ' + value.name);
});
+ var $btnSwitchTo = $('<button>', {
+ type : "button",
+ 'class' : "pull-right btn btn-primary",
+ 'data-loading-text' : "switch to Revison"
+ }).appendTo($fileWrapper);
+ $btnSwitchTo.html('Switch To Revison');
+
+ $btnSwitchTo.click(function(){
+ $.ajax({ url: '/api/switchToRevisionFolder/',
+ type: 'POST',
+ data: {
+ RevisionFolder: value.name
+ }
+ }).success(function(data){
+ Localeedit.InitRevisionListUi();
+ });
+ });
+
+
+
var $btnDelete = $('<button>', {
type : "button",
'class' : "pull-right btn btn-primary",
View
85 localeEditFileManager.js
@@ -42,6 +42,8 @@ exports.GetUserFolderName = function(req) {
return 'user_' + req.session.passport.user;
};
+
+
exports.GetUserFiles = function(req, res) {
var dirName = getUserFolder(req);
console.log('Retrieving UserFiles: ');
@@ -94,19 +96,76 @@ exports.DeleteRevisionFolder = function(req, res) {
var dirName = getUserFolder(req);
var folderToDelete = req.body.Foldername;
-
- fs.rmdir(dirName + '/' + folderToDelete, function (err) {
- if (err) {
- //ToDo Error: EISDIR, unlink '/home/stephan/workspaces/locale-js-editor/files/user_1/201211117942_backUp'
- res.writeHead(200, { 'Content-Type': 'application/json' });
- res.write(JSON.stringify( { state: 'error'}));
- res.end();
- } else {
- res.writeHead(200, { 'Content-Type': 'application/json' });
- res.write(JSON.stringify( { state: 'success'}));
- res.end();
- }
- });
+ var doResponse = function(err){
+ if (err) {
+ res.writeHead(200, { 'Content-Type': 'application/json' });
+ res.write(JSON.stringify( { state: 'error'}));
+ res.end();
+ } else {
+ res.writeHead(200, { 'Content-Type': 'application/json' });
+ res.write(JSON.stringify( { state: 'success'}));
+ res.end();
+ }
+ };
+
+ deleteFolder(dirName + '/' + folderToDelete, doResponse );
+
+};
+
+function deleteAllFilesInFolder(folder, callback) {
+ fs.readdir(folder, function(err, files){
+
+ // nur die js Dateien ohne Ordner
+ var file = null;
+ var done = 0;
+
+ for (var i in files) {
+ file = files[i];
+
+ var stats = fs.lstatSync(folder + '/' + file);
+
+ if (stats.isFile()) {
+ fs.unlink(folder + '/' + file, function (err) {
+ if (err) {
+ console.log(err);
+ } else {
+ console.log('deleteAllFilesInFolder ' + folder + '/' + file);
+ }
+ ++done;
+ if(done === files.length ) {
+ callback();
+ }
+ });
+ }
+ }
+
+
+ });
+};
+
+function deleteFolder(folder, callback){
+
+ var procceed = function(){
+ fs.rmdir(folder, function (err) {
+ if (err) {
+ callback(true);
+ } else {
+ callback(false);
+ }
+ });
+ }
+
+
+ deleteAllFilesInFolder(folder, procceed);
+
+
+};
+
+exports.SwitchToRevision = function(req, res) {
+ var dirName = getUserFolder(req);
+ var revisionFolderToSwitchTo = req.body.RevisionFolder;
+
+
};
exports.GetCurrentRevisions = function(req, res) {
View
3 server.js
@@ -181,6 +181,9 @@ app.get('/api/currentfiles', filemanager.GetUserFiles);
app.get('/api/getCurrentRevisions', filemanager.GetCurrentRevisions);
app.post('/api/deleteRevisionFolder', express.bodyParser(), filemanager.DeleteRevisionFolder);
+app.post('/api/switchToRevisionFolder', express.bodyParser(), filemanager.SwitchToRevision);
+
+
//get the locales as json array of locale objects
app.get('/api/getworkinglocales', filemanager.GetCurrentWorkingLocales);
app.post('/api/deleteUserFile',express.bodyParser(), filemanager.DeleteUserFile);

0 comments on commit de49d9b

Please sign in to comment.