|
@@ -150,10 +150,10 @@ function createCloudFile(filename) {
|
|
|
* AJAX to get file in the cloud and load into workspace
|
|
|
* @param {String} filename : the name of file
|
|
|
*/
|
|
|
-function openCloudFile(filename) {
|
|
|
+function openCloudFile(fileid) {
|
|
|
var _token = window.localStorage.Token;
|
|
|
if (_token) {
|
|
|
- $.ajax(`https://demo-lecode.smartedu.lenovo.com/api/web/v1/blockpy/project/` + filename, {
|
|
|
+ $.ajax(`/api/web/v1/blockpy/project/` + fileid, {
|
|
|
type: "GET",
|
|
|
headers: { 'Authorization': "Bearer " + _token },
|
|
|
before: () => { $("#cloud_modal_preload").css("display", "block") },
|
|
@@ -161,12 +161,12 @@ function openCloudFile(filename) {
|
|
|
var file = data.data.instructions;
|
|
|
var date = data.data.updateTime;
|
|
|
Materialize.toast(CCB.str_group.success_downloadFile, 4000);
|
|
|
- loadCloudXmlFile(file, data.data.id);
|
|
|
+ loadCloudXmlFile(file, data.data.title);
|
|
|
$("#cloud_storage_modal").modal("close");
|
|
|
$("#cloud_modal_preload").css("display", "none");
|
|
|
let i = indexGet(data.data.id, CCB.cloudFileList);
|
|
|
- CCB.selectCloudFile = filename;
|
|
|
- relistCloudFile(filename);
|
|
|
+ CCB.selectCloudFile = fileid;
|
|
|
+ relistCloudFile(data.data.title);
|
|
|
updateCloudFilePanel();
|
|
|
},
|
|
|
error: () => {
|
|
@@ -438,7 +438,7 @@ function updateCloudFilePanel() {
|
|
|
// * *
|
|
|
' <ul class="cloud-btnPanel">' +
|
|
|
' <li class="cloudBtn-open"><img src="./images/cloudfileopen.png" class="material-icons" style="width:22px;margin-right:6px;top:-1px;position:relative;cursor:pointer" onclick="fileOpen(' + i + ')"></li>' +
|
|
|
- ' <li class="cloudBtn-share"><i class="material-icons" href="#share" onclick="fileShare(' + i + ')" >share</i></li>' +
|
|
|
+ //' <li class="cloudBtn-share"><i class="material-icons" href="#share" onclick="fileShare(' + CCB.cloudFileList[i].filenameId + ')" >share</i></li>' +
|
|
|
// ' <li style="float:left;" class="unblock cloudBtn-update"><i class="material-icons" onclick="fileUpdate(' + i + ')">save</i></li>' +
|
|
|
' <li style="float:left;" class="cloudBtn-update"><i class="material-icons" onclick="fileUpdate(' + i + ')">save</i></li>' +
|
|
|
' <li class="cloudBtn-rename"><i class="material-icons" onclick="fileRename(' + i + ')">edit</i></li>' +
|
|
@@ -543,7 +543,18 @@ function copyText(text) {
|
|
|
*/
|
|
|
function fileUpdate(i) {
|
|
|
$("#cloud_modal_preload").css("display", "block")
|
|
|
- updateCloudFile(CCB.cloudFileList[i].filename);
|
|
|
+ uploadlxfilecontentbyid(CCB.cloudFileList[i].filenameId, Ardublockly.generateXml(), function (data) {
|
|
|
+ if (data.success) {
|
|
|
+ $("#cloud_modal_preload").css("display", "none");
|
|
|
+ Materialize.toast(CCB.str_group.success_updateFile, 4000);
|
|
|
+ $("#cloud_time" + i).html(getCurrentDate());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $("#cloud_modal_preload").css("display", "none");
|
|
|
+ Materialize.toast(CCB.str_group.error_updateFile, 4000);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ //updateCloudFile(CCB.cloudFileList[i].filename);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -575,7 +586,21 @@ function confirmRename(i) {
|
|
|
if (filename == originname) {
|
|
|
cloudFileState("over", i);
|
|
|
} else if (checkFileName(filename)) {
|
|
|
- renameCloudFile(filename, originname);
|
|
|
+ upadtelxfilenamebyid(CCB.cloudFileList[i].filenameId, filename, function (data) {
|
|
|
+ if (data.success) {
|
|
|
+ $("#cloud_modal_preload").css("display", "none");
|
|
|
+ Materialize.toast(CCB.str_group.success_renameFile, 4000);
|
|
|
+ CCB.cloudFileList[i].filename = filename;
|
|
|
+ $("#cloud_name" + i).html(filename + ".xml");
|
|
|
+ document.getElementById("cloud_name" + i).title = filename + ".xml";
|
|
|
+ cloudFileState("over", i);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $("#cloud_modal_preload").css("display", "none");
|
|
|
+ Materialize.toast(CCB.str_group.error_renameFile, 4000);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -592,7 +617,23 @@ function cancelRename(i) {
|
|
|
* check the current filelist and launch a funciton to rename it
|
|
|
*/
|
|
|
function confirmDelete(i) {
|
|
|
- deleteCloudFile(CCB.cloudFileList[i].filename);
|
|
|
+ // deleteCloudFile(CCB.cloudFileList[i].filename);
|
|
|
+ dellxfilebyid(CCB.cloudFileList[i].filenameId, function (data) {
|
|
|
+ if (data.success) {
|
|
|
+ $("#cloud_modal_preload").css("display", "none");
|
|
|
+ Materialize.toast(CCB.str_group.success_deleteFile, 4000);
|
|
|
+ if (CCB.selectCloudFile == CCB.cloudFileList[i].filenameId) {
|
|
|
+ CCB.selectCloudFile = null;
|
|
|
+ }
|
|
|
+ CCB.cloudFileList.splice(i, 1);
|
|
|
+ cloudFileState("over", i);
|
|
|
+ updateCloudFilePanel();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $("#cloud_modal_preload").css("display", "none");
|
|
|
+ Materialize.toast(CCB.str_group.error_deleteFile, 4000);
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -617,7 +658,28 @@ function confirmCreateNew() {
|
|
|
var filename = $("#cloud_sketch_name").val();
|
|
|
filename = filename.replace(/(\s*$)/g, "");
|
|
|
if (checkFileName(filename) && filename !== '') {
|
|
|
- createCloudFile(filename);
|
|
|
+ savelxfile(filename, Ardublockly.generateXml(), function (data) {
|
|
|
+ if (data.success) {
|
|
|
+ $("#cloud_modal_preload").css("display", "none");
|
|
|
+ Materialize.toast(CCB.str_group.success_uploadFile, 4000);
|
|
|
+ let fileobject = {
|
|
|
+ filenameId: data.data.id,
|
|
|
+ filename: filename,
|
|
|
+ time: getCurrentDate(),
|
|
|
+ timestamp: (new Date()).valueOf()
|
|
|
+ };
|
|
|
+ CCB.cloudFileList.push(fileobject);
|
|
|
+ CCB.selectCloudFile = data.data.filenameid;
|
|
|
+ relistCloudFile(filename);
|
|
|
+ updateCloudFilePanel();
|
|
|
+ cloudFileState("over", 0);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $("#cloud_modal_preload").css("display", "none");
|
|
|
+ Materialize.toast(CCB.str_group.error_uploadFile, 4000);
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|