]> git.joonet.de Git - adminer.git/commitdiff
Save select data by AJAX
authorJakub Vrana <jakub@vrana.cz>
Sun, 17 Oct 2010 05:50:40 +0000 (07:50 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 17 Oct 2010 05:50:40 +0000 (07:50 +0200)
adminer/include/functions.inc.php
adminer/select.inc.php
adminer/static/functions.js

index ea81a1c914e08a70d50419631e6f37d52237939a..d3489447ea6986b1303ff3f0fa08a393acce50ad 100644 (file)
@@ -345,7 +345,7 @@ function redirect($location, $message = null) {
                restart_session();
                $_SESSION["messages"][] = $message;
        }
-       if (isset($location)) {
+       if (isset($location) && $_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
                header("Location: " . ($location != "" ? $location : "."));
                exit;
        }
index 8d118bcd53ad1c25f877321180f56bc1755293fa..441681e621bc1e0cbee5e92609be224a30715bb8 100644 (file)
@@ -333,7 +333,7 @@ if (!$columns) {
                                                        }
                                                }
                                                $id = h("val[$unique_idf][" . bracket_escape($key) . "]");
-                                               $value = $_POST["val"][$unique_idf][bracket_escape($key)];
+                                               $value = ($error ? $_POST["val"][$unique_idf][bracket_escape($key)] : null);
                                                $h_value = h(isset($value) ? $value : $row[$key]);
                                                $long = strpos($val, "<i>...</i>");
                                                $editable = is_utf8($val) && !$long && $rows[$n][$key] == $row[$key] && !$functions[$key];
@@ -380,7 +380,7 @@ if (!$columns) {
                        if (!information_schema(DB)) {
                                ?>
 <fieldset><legend><?php echo lang('Edit'); ?></legend><div>
-<input type="submit" value="<?php echo lang('Save'); ?>" title="<?php echo lang('Double click on a value to modify it.'); ?>">
+<input type="submit" value="<?php echo lang('Save'); ?>" title="<?php echo lang('Double click on a value to modify it.'); ?>" onclick='return !ajaxForm(this.form);'>
 <input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
 <input type="submit" name="clone" value="<?php echo lang('Clone'); ?>">
 <input type="submit" name="delete" value="<?php echo lang('Delete'); ?>" onclick="return confirm('<?php echo lang('Are you sure?'); ?> (' + (this.form['all'].checked ? <?php echo $found_rows; ?> : formChecked(this, /check/)) + ')');">
index c1d25c5ead825c63136adb8469b671d0cef37a96..f554758ae17ad6d27e7d216f4fab48531c78a688 100644 (file)
@@ -136,17 +136,22 @@ var ajaxTimeout;
 
 /** Create AJAX request
 * @param string
+* @param string
 * @return XMLHttpRequest or false in case of an error
 */
-function ajax(url) {
+function ajax(url, data) {
        var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false));
        if (xmlhttp) {
                var currentState = ++ajaxState;
                clearTimeout(ajaxTimeout);
                ajaxTimeout = setTimeout(function () {
                        setHtml('main', '<img src="../adminer/static/loader.gif" alt="">');
-               }, 1000); // defer displaying loader
-               xmlhttp.open('GET', url);
+               }, 500); // defer displaying loader
+               var method = (data === undefined ? 'GET' : 'POST');
+               xmlhttp.open(method, url);
+               if (method == 'POST') {
+                       xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+               }
                xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
                xmlhttp.onreadystatechange = function () {
                        if (xmlhttp.readyState == 4 && currentState == ajaxState) {
@@ -154,10 +159,11 @@ function ajax(url) {
                                setHtml('main', xmlhttp.responseText);
                                if (window.jush) {
                                        jush.highlight_tag('code');
+                                       jush.highlight_tag('pre', 0);
                                }
                        }
                };
-               xmlhttp.send('');
+               xmlhttp.send(data);
        }
        return xmlhttp;
 }
@@ -170,11 +176,15 @@ function ajaxForm(form) {
        var params = [ ];
        for (var i=0; i < form.elements.length; i++) {
                var el = form.elements[i];
-               if (el.name && (!/checkbox|radio/i.test(el.type) || el.checked)) {
-                       params.push(el.name + '=' + encodeURIComponent(/select/i.test(el.tagName) ? selectValue(el) : el.value));
+               if (el.name && (!/checkbox|radio|submit|file/i.test(el.type) || el.checked)) {
+                       params.push(encodeURIComponent(el.name) + '=' + encodeURIComponent(/select/i.test(el.tagName) ? selectValue(el) : el.value));
                }
        }
-       return ajax((form.action || location.pathname) + '?' + params.join('&'));
+       if (form.method == 'post') {
+               return ajax(form.action || location.href, params.join('&'));
+       } else {
+               return ajax((form.action || location.pathname) + '?' + params.join('&'));
+       }
 }