frontend load/save
Este commit está contenido en:
@@ -1024,52 +1024,71 @@ var setup = function()
|
||||
// load button
|
||||
$(".load-button").off().click(function() {
|
||||
|
||||
if (!localStorage)
|
||||
{
|
||||
alert("Your browser must support HTML5 local storage in order to use this feature");
|
||||
return;
|
||||
}
|
||||
// if (!localStorage)
|
||||
// {
|
||||
// alert("Your browser must support HTML5 local storage in order to use this feature");
|
||||
// return;
|
||||
// }
|
||||
|
||||
var configString = localStorage.getItem("alpacaDesignerConfig");
|
||||
if (!configString)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// var configString = localStorage.getItem("alpacaDesignerConfig");
|
||||
// if (!configString)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
try
|
||||
{
|
||||
var config = JSON.parse(configString);
|
||||
if (!config.schema) {
|
||||
config.schema = {};
|
||||
// try
|
||||
// {
|
||||
// var config = JSON.parse(configString);
|
||||
// if (!config.schema) {
|
||||
// config.schema = {};
|
||||
// }
|
||||
// if (!config.options) {
|
||||
// config.options = {};
|
||||
// }
|
||||
// if (!config.data) {
|
||||
// config.data = {};
|
||||
// }
|
||||
var config = {};
|
||||
if (schema)
|
||||
{
|
||||
config.schema = schema;
|
||||
}
|
||||
if (!config.options) {
|
||||
config.options = {};
|
||||
if (options)
|
||||
{
|
||||
config.options = options;
|
||||
}
|
||||
if (!config.data) {
|
||||
config.data = {};
|
||||
if (data)
|
||||
{
|
||||
config.data = data;
|
||||
}
|
||||
|
||||
editor1.setValue(JSON.stringify(config.schema, null, " "));
|
||||
editor2.setValue(JSON.stringify(config.options, null, " "));
|
||||
editor3.setValue(JSON.stringify(config.data, null, " "));
|
||||
|
||||
$.ajax({
|
||||
url: '/api/load/' + $('.select-form option:selected').text(),
|
||||
success: function(config) {
|
||||
editor1.setValue(JSON.stringify(config.schema, null, " "));
|
||||
editor2.setValue(JSON.stringify(config.options, null, " "));
|
||||
editor3.setValue(JSON.stringify(config.data, null, " "));
|
||||
alert("Formulario " + $('.select-form option:selected').text() + " cargado correctamente.")
|
||||
},
|
||||
error: function() {
|
||||
alert("Hubo un error al cargar el formulario")
|
||||
}})
|
||||
//alert("Your form was loaded from HTML5 local storage");
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
// bad value
|
||||
}
|
||||
// }
|
||||
// catch (e)
|
||||
// {
|
||||
// // bad value
|
||||
// }
|
||||
|
||||
});
|
||||
|
||||
// save button
|
||||
$(".save-button").off().click(function() {
|
||||
|
||||
if (!localStorage)
|
||||
{
|
||||
alert("Your browser must support HTML5 local storage in order to use this feature");
|
||||
return;
|
||||
}
|
||||
// if (!localStorage)
|
||||
// {
|
||||
// alert("Your browser must support HTML5 local storage in order to use this feature");
|
||||
// return;
|
||||
// }
|
||||
|
||||
var config = {};
|
||||
if (schema)
|
||||
@@ -1084,9 +1103,21 @@ var setup = function()
|
||||
{
|
||||
config.data = data;
|
||||
}
|
||||
var configString = JSON.stringify(config);
|
||||
//var configString = JSON.stringify(config);
|
||||
|
||||
localStorage.setItem("alpacaDesignerConfig", configString);
|
||||
$.ajax({
|
||||
url: '/api/save/'+ $('#form').val(),
|
||||
data : JSON.stringify(config),
|
||||
contentType : 'application/json',
|
||||
type : 'POST',
|
||||
success: function() {
|
||||
$('.select-form').append($('<option>', {value:$('#form').val(), text: $('#form').val()}))
|
||||
alert("Formulario " + $('#form').val() + " almacenado.")
|
||||
},
|
||||
error: function() {
|
||||
alert("Hubo un error al almacenar el formulario")
|
||||
}})
|
||||
//localStorage.setItem("alpacaDesignerConfig", configString);
|
||||
|
||||
//alert("Your form was saved in HTML5 local storage");
|
||||
});
|
||||
@@ -1097,5 +1128,21 @@ $(document).ready(function() {
|
||||
// wait a bit to allow ACE to load
|
||||
setTimeout(function() {
|
||||
setup();
|
||||
$.ajax({
|
||||
url: '/api/all',
|
||||
contentType : 'application/json',
|
||||
type : 'GET',
|
||||
success: function(forms) {
|
||||
$('.select-form').empty()
|
||||
for(var i = 0; i < forms.length; i++) {
|
||||
$('.select-form').append($('<option>', {value:forms[i]._id, text: forms[i]._id}))
|
||||
}
|
||||
$('.select-form').change(function(e) {
|
||||
$('#form').val($('.select-form option:selected').text())
|
||||
})
|
||||
alert("Formularios cargados correctamente.")
|
||||
}, error: function() {
|
||||
alert("Formularios cargados correctamente.")
|
||||
}})
|
||||
}, 200);
|
||||
});
|
||||
|
||||
Referencia en una nueva incidencia
Block a user