Autosave function
parent
8dabf4065d
commit
7ed00a70aa
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
function isAjax() {
|
||||
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
|
||||
$_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
|
||||
}
|
||||
|
||||
function saveForm() {
|
||||
$type = getMethod();
|
||||
$id = ($type=='GET') ? $_GET['autosaveid'] : $_POST['autosaveid'];
|
||||
$_SESSION[$id] = $_SERVER['QUERY_STRING'];
|
||||
echo date('H:i | d/m/y',time());
|
||||
}
|
||||
|
||||
function loadForm() {
|
||||
$type = getMethod();
|
||||
$id = ($type=='GET') ? $_GET['autosaveid'] : $_POST['autosaveid'];
|
||||
if(isset($_SESSION[$id]))
|
||||
echo $_SESSION[$id];
|
||||
}
|
||||
|
||||
function isLoad() {
|
||||
$type = getMethod();
|
||||
if($type=='GET' and isset($_GET['autosave'])) return true;
|
||||
elseif(isset($_POST['autosave'])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function getMethod() {
|
||||
return $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
if(isAjax()) {
|
||||
if(isLoad()) loadForm();
|
||||
else saveForm();
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
?>
|
||||
|
|
@ -99,6 +99,8 @@ if ($user->isAdmin()) {
|
|||
<script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/tools.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/mootools.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/slimbox.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/prototype.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/form.autosave.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
<!--
|
||||
function exit(el, path) {
|
||||
|
|
@ -196,8 +198,9 @@ if ($user->isAdmin()) {
|
|||
}
|
||||
}
|
||||
?>
|
||||
<form action="index.php" method="post" <?php echo (isset($_GET["new"]) && $_GET["new"]=="photo") ? "enctype=\"multipart/form-data\"" : ""?> name="frmAdd" class="newpost">
|
||||
<form action="index.php" method="post" <?php echo (isset($_GET["new"]) && $_GET["new"]=="photo") ? "enctype=\"multipart/form-data\"" : ""?> name="frmAdd" id="autosave" class="newpost">
|
||||
<fieldset>
|
||||
<div id="update" style="display:none;" class="exito"></div><br />
|
||||
<?php
|
||||
if ($isEdition) {
|
||||
?>
|
||||
|
|
@ -302,6 +305,13 @@ if ($user->isAdmin()) {
|
|||
</p>
|
||||
</fieldset>
|
||||
</form>
|
||||
<div id="serialize"></div>
|
||||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
//id: formulario, id: info, options
|
||||
new Form.autoSave('autosave','update',{});
|
||||
// ]]>
|
||||
</script>
|
||||
|
||||
<div class="footer-box"> </div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,97 @@
|
|||
/* Autocompleter.editor, version 1.0: http://icebeat.bitacoras.com
|
||||
* (c) 2005 Daniel Mota aka IceBeat <daniel.mota@gmail.com>
|
||||
*
|
||||
/*--------------------------------------------------------------------------*/
|
||||
Form.autoSave = Class.create();
|
||||
Form.autoSave.prototype = {
|
||||
/*
|
||||
* Inicializamos la clase y preparamos parametros
|
||||
*/
|
||||
initialize: function(element, update, options) {
|
||||
this.element = $(element);
|
||||
this.update = $(update);
|
||||
this.options = $H({
|
||||
url: 'form.autosave.php',
|
||||
frequency: 30,
|
||||
method: 'get',
|
||||
msg: {
|
||||
loading: 'Filling form',
|
||||
loaded: 'Form filled',
|
||||
sending: 'Sending form',
|
||||
update: 'Form saved at: '
|
||||
}
|
||||
}).merge(options);
|
||||
this.msg = this.options.msg;
|
||||
this.message(this.msg.loading);
|
||||
new Ajax.Request(this.options.url, { method: this.options.method, parameters:"autosave=true&autosaveid="+this.element.id, onSuccess: this.autoFill.bind(this) });
|
||||
},
|
||||
message: function(msg) {
|
||||
Element.show(this.update);
|
||||
this.update.innerHTML = msg;
|
||||
},
|
||||
send: function(element,value) {
|
||||
this.message(this.msg.sending);
|
||||
new Ajax.Request(this.options.url, { method: this.options.method, parameters:"autosaveid="+element.id+'&'+value, onSuccess: this.updateForm.bind(this) });
|
||||
},
|
||||
updateForm: function(resp) {
|
||||
if(resp.responseText) {
|
||||
this.message(this.msg.update+resp.responseText);
|
||||
}
|
||||
},
|
||||
autoFill: function(resp) {
|
||||
if(resp.responseText) {
|
||||
this.message(this.msg.loaded);
|
||||
Form.Unserialize(this.element,resp.responseText);
|
||||
} else {
|
||||
Element.hide(this.update);
|
||||
}
|
||||
new Form.Observer(this.element,this.options.frequency,this.send.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
Form.Unserialize = function(form,queryComponents) {
|
||||
var elements = Form.getElements($(form));
|
||||
var queryComponents = queryComponents.toQueryParams();
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
var name = element.name;
|
||||
if(queryComponents[name]) {
|
||||
var method = element.tagName.toLowerCase();
|
||||
var value = decodeURIComponent(queryComponents[name]);
|
||||
Form.Element.Unserializers[method](element,value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Form.Element.Unserializers = {
|
||||
input: function(element,value) {
|
||||
switch (element.type.toLowerCase()) {
|
||||
case 'submit':
|
||||
case 'hidden':
|
||||
case 'password':
|
||||
case 'text':
|
||||
return Form.Element.Unserializers.textarea(element,value);
|
||||
case 'checkbox':
|
||||
case 'radio':
|
||||
return Form.Element.Unserializers.inputSelector(element,value);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
inputSelector: function(element,value) {
|
||||
if (element.value == value)
|
||||
element.checked = 'checked';
|
||||
},
|
||||
|
||||
textarea: function(element,value) {
|
||||
element.value = value;
|
||||
},
|
||||
|
||||
select: function(element,value) {
|
||||
for (var i = 0; i < element.length; i++) {
|
||||
var opt = element.options[i];
|
||||
if(opt.value == value || opt.text == value)
|
||||
opt.selected = 'selected';
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,10 +1,11 @@
|
|||
== CREDITS==
|
||||
== CREDITS==
|
||||
Gelato developers and designers (in chronological order):
|
||||
|
||||
Pedro Santana [ http://www.pecesama.net/weblog/ ]
|
||||
Jorge Condomí [ http://www.raven.com.ar/ ]
|
||||
Víctor de la Rocha [ http://blog.mis-algoritmos.com/ ]
|
||||
Victor Bracco [ http://www.vbracco.com.ar/blog/ ]
|
||||
Matt Heitzenroder [ http://www.globaljourney.net/ ]
|
||||
|
||||
= COPYRIGHT NOTICES =
|
||||
This product includes code and libraries developed by third parties, which are governed by different licenses. These components, and their licenses, are listed below.
|
||||
|
|
@ -48,4 +49,8 @@ Textile class available under GNU General Public License.
|
|||
= PHP-gettext =
|
||||
Copyright (c) 2003 Danilo Segan, http://savannah.nongnu.org/projects/php-gettext/
|
||||
Copyright (c) 2005 Nico Kaiser
|
||||
PHP-gettext available under GNU General Public License.
|
||||
PHP-gettext available under GNU General Public License.
|
||||
|
||||
= form.autosave =
|
||||
Copyright (c) Daniel Mota Leiva, http://icebeat.bitacoras.com/app/autosave/
|
||||
form.autosave available under Creative Commons Attribution-ShareAlike License.
|
||||
Loading…
Reference in New Issue