From d2405d1e049ae37573416e50f7f334247b78b108 Mon Sep 17 00:00:00 2001 From: Kamidi Preetham Date: Thu, 2 Jun 2016 01:40:39 +0530 Subject: [PATCH] Added editor side support for Importing Files Signed-off-by: Kamidi Preetham --- client/css/app.css | 38 +++++++++++++++ client/js/controllers/editor.js | 84 +++++++++++++++++++++++++++++++++ server/views/index.html | 6 +++ 3 files changed, 128 insertions(+) diff --git a/client/css/app.css b/client/css/app.css index 43d9579..12b9fda 100644 --- a/client/css/app.css +++ b/client/css/app.css @@ -176,6 +176,44 @@ font-family: clearsans-light; padding-left: 10px; border-radius: 20px; } +.inputFileControls { + background-color: #262a2e; + border: 0; + color: #8c8c8c; + width: 0.1px; + height: 0.1px; + opacity: 0; + overflow: hidden; + position: absolute; + z-index: -1; +} +.inputFileControls + label { + font-size: 14px !important; + font-weight: normal; + font-family: clearsans !important; + color: #8c8c8c; + background-color: white; + display: inline-block; + margin-right: 10px; + padding: .4em 1em; + border-radius: 20px; + cursor: pointer; + text-align: center; +} +.list-item { + font-size: 14px !important; + width: 67%; + font-weight: normal; + font-family: clearsans !important; + background-color: #262a2e; + margin-right: 10px; + padding: .45em 1em; + list-style-type: none; + border-radius: 13px; + color: #8c8c8c; + text-align: center; + display: inline-block; +} /* Overwrite jquery ui class*/ .ui-autocomplete-input, .ui-corner-right { background: none !important; diff --git a/client/js/controllers/editor.js b/client/js/controllers/editor.js index ce6a07e..461aa66 100644 --- a/client/js/controllers/editor.js +++ b/client/js/controllers/editor.js @@ -907,6 +907,87 @@ } }; + $scope.filesChanged = function(elm) { + $scope.files = elm.files; + $scope.$apply(); + } + + $scope.importFile = function () { + var file = filePath; + if (file) { + if (isLeaf) { + var cached = file.split("/"); + cached.pop(); + file = cached.join("/"); + } + if($scope.folder !== 'demo') { + var dialog = $('
'). + html($compile('
'+ + '
'+ + ' '+ + '
  • {{file.name}}
  • '+ + ' ')($scope)). + dialog({ + title: "Choose file to import", + autoOpen: false, + modal: true, + position: { at: "center top"}, + height: 175, + width: 520, + show: { effect: "fade", duration: 300 }, + hide: { effect: "fade", duration: 300 }, + resizable: 'disable', + buttons: { + "Upload": function() { + var formdata = new FormData(); + var data=String(file); + formdata.append("upload_path", data); + angular.forEach($scope.files,function(file) { + formdata.append('file', file); + }); + $http.post('/api/file/upload',formdata, { + transformRequest: angular.identity, + headers:{'Content-Type':undefined} + }) + .success(function(d) { + console.log(d); + $scope.refreshTree(); + $scope.stopSpin(); + $(".ui-dialog-buttonpane button:contains('Cancel')").button("enable"); + $(".ui-dialog-buttonpane button:contains('Upload')").button("enable"); + }) + .error(function(d) { + alert(d); + $scope.stopSpin(); + $(".ui-dialog-buttonpane button:contains('Cancel')").button("enable"); + $(".ui-dialog-buttonpane button:contains('Upload')").button("enable"); + }); + $scope.startSpin(); + $(".ui-dialog-buttonpane button:contains('Cancel')").button("disable"); + $(".ui-dialog-buttonpane button:contains('Upload')").button("disable"); + $(this).dialog("close"); + }, + Cancel: function() { + $(this).dialog("close"); + } + }, + close: function(ev, ui) { + $(this).dialog("close"); + } + }); + dialog.dialog("open"); + } else { + alert("Error: Upload to demo folder is not allowed") + } + } else { + alert("Folder destination must be selected!"); + } + }; + $scope.remove = function () { if (filePath) { var file_name = filePath.split("/").pop(); @@ -1016,6 +1097,9 @@ case "file.save": $scope.saveFileManually(); break; + case "file.importfile": + $scope.importFile(); + break; case "file.remove": $scope.remove(); break; diff --git a/server/views/index.html b/server/views/index.html index 2e0b3f3..efd9d71 100644 --- a/server/views/index.html +++ b/server/views/index.html @@ -191,6 +191,12 @@ New File + + + + Import File + +