Skip to content
Snippets Groups Projects
Commit c1721850 authored by alvaro's avatar alvaro
Browse files

Improving creation/deletion of files

parent 43b45006
No related branches found
No related tags found
No related merge requests found
...@@ -730,15 +730,19 @@ class AdminModule extends abstractModule{ ...@@ -730,15 +730,19 @@ class AdminModule extends abstractModule{
exit(0); exit(0);
} }
$return_var = 0; $return_var = 0;
exec ("rm ".$path, &$output, $return_var); if(strpos($path, "components") === 0 && strpos($path, '..') === FALSE){
if($return_var !== 0){ exec ("rm ".$path, &$output, $return_var);
echo json_encode(array('success' => false, path => $path)); if($return_var !== 0){
echo json_encode(array('success' => false, path => $path));
}else{
echo json_encode(array('success' => true, path => $path));
}
}else{ }else{
echo json_encode(array('success' => true, path => $path)); HTTPStatus::send406();
exit(0);
} }
}else{ }else{
HTTPStatus::send406(); echo json_encode(array('success' => false, path => $path));
exit(0);
} }
} }
......
...@@ -94,18 +94,22 @@ $(document).ready(function(){ ...@@ -94,18 +94,22 @@ $(document).ready(function(){
var fileName = ""; var fileName = "";
if($(this).hasClass("new-file-button-view")){ if($(this).hasClass("new-file-button-view")){
fileName = prompt("Please enter the name of the new view","json.template"); fileName = prompt("Please enter the name of the new view","json.template");
fileName = /\w+\.template$/g.exec(fileName); if(! /[^\/\s]+\.template$/g.test(fileName)){
alert("File name is not valid. It has to end with a .template");
return;
}
}else{ }else{
fileName = prompt("Please enter the name of the new model","newModel.query"); fileName = prompt("Please enter the name of the new model","newModel.query");
fileName = /\w+\.query$/g.exec(fileName); if(! /^(endpoint\.[^\/\s]+\/)*[^\/\s]+\.query$/.test(fileName)){
alert("File name is not valid. Format is [endpoint.ENDPOINTPREFIX/]*FILENAME.query");
return;
}
} }
if(fileName != null){ if(fileName != null){
var url = "components/add/"+$(this).attr("data-component")+"/"+fileName; var url = "components/add/"+$(this).attr("data-component")+"/"+fileName;
var data = {content: $("#template-editor").val()}; var data = {content: $("#template-editor").val()};
var msgId = "#component-msg"; var msgId = "#component-msg";
executePost(url, data, {id:msgId, success: "Saved!", failure: "Can't create new file. Probably permissions problem or file already exists", error: "Error creating a new file!"}); executePost(url, data, {id:msgId, success: "Saved!", failure: "Can't create new file. Probably permissions problem or file already exists", error: "Error creating a new file!"});
}else{
alert("File name is not valid. It has to end with a .query for models and with .template for views");
} }
}); });
...@@ -145,10 +149,10 @@ $(document).ready(function(){ ...@@ -145,10 +149,10 @@ $(document).ready(function(){
$.each(data.models, function(i, item){ $.each(data.models, function(i, item){
var modelUrl = relPos+componentType+"/"+componentName+"/queries/"+item; var modelUrl = relPos+componentType+"/"+componentName+"/queries/"+item;
var modelFileUrl = componentType+"/"+componentName+"/queries/"+item; var modelFileUrl = componentType+"/"+componentName+"/queries/"+item;
$("#query-list").append("<li class='file-li'><button type='button' class='close hide lodspk-delete-file' data-parent='"+dataParent+"' data-file='"+modelFileUrl+"' style='align:left'>x</button><a href='#query-save-button' class='lodspk-query' data-url='"+modelUrl+"'>"+item+"</a></li>"); $("#query-list").append("<li class='file-li'><button type='button' class='close hide lodspk-delete-file' data-parent='"+dataParent+"' data-file='"+modelFileUrl+"' style='align:left'>x</button><a href='#' class='lodspk-query' data-url='"+modelUrl+"'>"+item+"</a></li>");
$('html, body').stop().animate({ $('html, body').stop().animate({
scrollTop: $('#query-list').offset().top scrollTop: $('#template-list').offset().top - 100
}, 100); }, 500);
}); });
updateEvents(); updateEvents();
$(".new-file-button").removeClass("hide"); $(".new-file-button").removeClass("hide");
...@@ -223,8 +227,8 @@ $(document).ready(function(){ ...@@ -223,8 +227,8 @@ $(document).ready(function(){
templateBuffer = data; templateBuffer = data;
$("#template-save-button").attr("data-url", fileUrl).addClass("disabled"); $("#template-save-button").attr("data-url", fileUrl).addClass("disabled");
$('html, body').stop().animate({ $('html, body').stop().animate({
scrollTop: $('body').offset().top scrollTop: $('body').offset().top-100
}, 100); }, 500);
} }
}); });
}); });
...@@ -239,9 +243,9 @@ $(document).ready(function(){ ...@@ -239,9 +243,9 @@ $(document).ready(function(){
queryEditor.setValue(data); queryEditor.setValue(data);
queryBuffer = data; queryBuffer = data;
$("#query-save-button").attr("data-url", fileUrl).addClass("disabled"); $("#query-save-button").attr("data-url", fileUrl).addClass("disabled");
$('#query-editor').stop().animate({ $('html, body').stop().animate({
scrollTop: $('body').offset().top scrollTop: $('.bs-docs-query').offset().top-100
}, 100); }, 1000);
} }
}); });
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment