Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Added editor side support for Importing Files
Browse files Browse the repository at this point in the history
Signed-off-by: Kamidi Preetham <kamidi@live.com>
  • Loading branch information
Kamidi Preetham committed Jul 6, 2016
1 parent 2286348 commit d2405d1
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
38 changes: 38 additions & 0 deletions client/css/app.css
Expand Up @@ -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;
Expand Down
84 changes: 84 additions & 0 deletions client/js/controllers/editor.js
Expand Up @@ -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 = $('<div></div>').
html($compile('<form ng-submit="Upload()">'+
' <div class="spin_sync" style="margin-top: -9px; float: right;'+
' margin-right: 46px;" us-spinner="{radius:6.5, width:3, length:4}"'+
' spinner-key="spinner-1"></div> <input'+
' type="file" id="inputFile" class="inputFileControls"' +
' onChange="angular.element(this).scope().filesChanged(this)"/>'+
' <label for="inputFile">Select File</label>'+
' <li class="list-item" ng-repeat="file in files">{{file.name}}</li>'+
' </form>')($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();
Expand Down Expand Up @@ -1016,6 +1097,9 @@
case "file.save":
$scope.saveFileManually();
break;
case "file.importfile":
$scope.importFile();
break;
case "file.remove":
$scope.remove();
break;
Expand Down
6 changes: 6 additions & 0 deletions server/views/index.html
Expand Up @@ -191,6 +191,12 @@
New File
</md-button>
</md-menu-item>
<md-menu-divider></md-menu-divider>
<md-menu-item>
<md-button ng-click="ctrl.menuAction('file.importfile', $event)">
Import File
</md-button>
</md-menu-item>
<md-menu-divider></md-menu-divider>
<md-menu-item>
<md-button ng-disabled="!shouldSave" ng-click="ctrl.menuAction('file.save', $event)">
Expand Down

0 comments on commit d2405d1

Please sign in to comment.