~ubuntu-branches/ubuntu/saucy/phpmyadmin/saucy-proposed

« back to all changes in this revision

Viewing changes to js/common.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-08-04 13:24:37 UTC
  • mfrom: (1.2.44)
  • Revision ID: package-import@ubuntu.com-20130804132437-jznw8efwy4hr1nms
Tags: 4:4.0.5-1
* New upstream release.
  - Fixes security issue PMASA-2013-10.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
$(function(){$("#pma_open_querywindow").click(function(a){a.preventDefault();PMA_querywindow.focus()})});var PMA_commonParams=(function(){var a={};return{setAll:function(d){var c=false;for(var b in d){if(a[b]!==undefined&&a[b]!==d[b]){c=true}a[b]=d[b]}if(c){PMA_querywindow.refresh()}},get:function(b){return a[b]||""},set:function(b,c){if(a[b]!==undefined&&a[b]!==c){PMA_querywindow.refresh();PMA_reloadNavigation()}a[b]=c;return this},getUrlQuery:function(){return $.sprintf("?%s&server=%s&db=%s&table=%s",this.get("common_query"),encodeURIComponent(this.get("server")),encodeURIComponent(this.get("db")),encodeURIComponent(this.get("table")))}}})();var PMA_commonActions={setDb:function(a){if(a!=PMA_commonParams.get("db")){PMA_commonParams.set("db",a);PMA_querywindow.refresh()}},openDb:function(a){PMA_commonParams.set("db",a).set("table","");PMA_querywindow.refresh();this.refreshMain(PMA_commonParams.get("opendb_url"))},refreshMain:function(a,b){if(!a){a=$("#selflink a").attr("href");a=a.substring(0,a.indexOf("?"))}a+=PMA_commonParams.getUrlQuery();$("<a />",{href:a}).appendTo("body").click().remove();AJAX._callback=b}};var PMA_querywindow=(function(d,c){var b={};var a="";return{open:function(f,g){if(!f){f="querywindow.php"+PMA_commonParams.getUrlQuery()}if(g){f+="&sql_query="+encodeURIComponent(g)}if(!b.closed&&b.location){var e=b.location.href;if(e!=f&&e!=PMA_commonParams.get("pma_absolute_uri")+f){if(PMA_commonParams.get("safari_browser")){b.location.href=targeturl}else{b.location.replace(targeturl)}b.focus()}}else{b=c.open(f+"&init=1","","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=yes,width="+PMA_commonParams.get("querywindow_width")+",height="+PMA_commonParams.get("querywindow_height"))}if(!b.opener){b.opener=c.window}if(c.focus){b.focus()}},focus:function(f){if(!b||b.closed||!b.location){a=f;this.open(false,f)}else{var e=b.document.getElementById("hiddenqueryform");if(e.querydisplay_tab!="sql"){e.querydisplay_tab.value="sql";e.sql_query.value=f;d(e).addClass("disableAjax");e.submit();b.focus()}else{b.focus()}}},refresh:function(f){if(!b.closed&&b.location){var e=d(b.document).find("#sqlqueryform");if(e.find("#checkbox_lock:checked").length==0){PMA_querywindow.open(f)}}},reload:function(f,g,i){if(!b.closed&&b.location){var e=d(b.document).find("#sqlqueryform");if(e.find("#checkbox_lock:checked").length==0){var h=d(b.document).find("#hiddenqueryform");h.find("input[name=db]").val(f);h.find("input[name=table]").val(g);if(i){h.find("input[name=sql_query]").val(i)}h.addClass("disableAjax").submit()}}}}})(jQuery,window);
 
 
b'\\ No newline at end of file'
 
1
/* vim: set expandtab sw=4 ts=4 sts=4: */
 
2
/**
 
3
 * Functionality for communicating with the querywindow
 
4
 */
 
5
$(function () {
 
6
    /**
 
7
     * Event handler for click on the open query window link
 
8
     * in the top menu of the navigation panel
 
9
     */
 
10
    $('#pma_open_querywindow').click(function (event) {
 
11
        event.preventDefault();
 
12
        PMA_querywindow.focus();
 
13
    });
 
14
});
 
15
 
 
16
/**
 
17
 * Holds common parameters such as server, db, table, etc
 
18
 *
 
19
 * The content for this is normally loaded from Header.class.php or
 
20
 * Response.class.php and executed by ajax.js
 
21
 */
 
22
var PMA_commonParams = (function () {
 
23
    /**
 
24
     * @var hash params An associative array of key value pairs
 
25
     * @access private
 
26
     */
 
27
    var params = {};
 
28
    // The returned object is the public part of the module
 
29
    return {
 
30
        /**
 
31
         * Saves all the key value pair that
 
32
         * are provided in the input array
 
33
         *
 
34
         * @param hash obj The input array
 
35
         *
 
36
         * @return void
 
37
         */
 
38
        setAll: function (obj) {
 
39
            var reload = false;
 
40
            for (var i in obj) {
 
41
                if (params[i] !== undefined && params[i] !== obj[i]) {
 
42
                    reload = true;
 
43
                }
 
44
                params[i] = obj[i];
 
45
            }
 
46
            if (reload) {
 
47
                PMA_querywindow.refresh();
 
48
            }
 
49
        },
 
50
        /**
 
51
         * Retrieves a value given its key
 
52
         * Returns empty string for undefined values
 
53
         *
 
54
         * @param string name The key
 
55
         *
 
56
         * @return string
 
57
         */
 
58
        get: function (name) {
 
59
            return params[name] || '';
 
60
        },
 
61
        /**
 
62
         * Saves a single key value pair
 
63
         *
 
64
         * @param string name  The key
 
65
         * @param string value The value
 
66
         *
 
67
         * @return self For chainability
 
68
         */
 
69
        set: function (name, value) {
 
70
            if (params[name] !== undefined && params[name] !== value) {
 
71
                PMA_querywindow.refresh();
 
72
                PMA_reloadNavigation();
 
73
            }
 
74
            params[name] = value;
 
75
            return this;
 
76
        },
 
77
        /**
 
78
         * Returns the url query string using the saved parameters
 
79
         *
 
80
         * @return string
 
81
         */
 
82
        getUrlQuery: function () {
 
83
            return $.sprintf(
 
84
                '?%s&server=%s&db=%s&table=%s',
 
85
                this.get('common_query'),
 
86
                encodeURIComponent(this.get('server')),
 
87
                encodeURIComponent(this.get('db')),
 
88
                encodeURIComponent(this.get('table'))
 
89
            );
 
90
        }
 
91
    };
 
92
})();
 
93
 
 
94
/**
 
95
 * Holds common parameters such as server, db, table, etc
 
96
 *
 
97
 * The content for this is normally loaded from Header.class.php or
 
98
 * Response.class.php and executed by ajax.js
 
99
 */
 
100
var PMA_commonActions = {
 
101
    /**
 
102
     * Saves the database name when it's changed
 
103
     * and reloads the query window, if necessary
 
104
     *
 
105
     * @param string new_db The name of the new database
 
106
     *
 
107
     * @return void
 
108
     */
 
109
    setDb: function (new_db) {
 
110
        if (new_db != PMA_commonParams.get('db')) {
 
111
            PMA_commonParams.set('db', new_db);
 
112
            PMA_querywindow.refresh();
 
113
        }
 
114
    },
 
115
    /**
 
116
     * Opens a database in the main part of the page
 
117
     *
 
118
     * @param string new_db The name of the new database
 
119
     *
 
120
     * @return void
 
121
     */
 
122
    openDb: function (new_db) {
 
123
        PMA_commonParams
 
124
            .set('db', new_db)
 
125
            .set('table', '');
 
126
        PMA_querywindow.refresh();
 
127
        this.refreshMain(
 
128
            PMA_commonParams.get('opendb_url')
 
129
        );
 
130
    },
 
131
    /**
 
132
     * Refreshes the main frame
 
133
     *
 
134
     * @param mixed url Undefined to refresh to the same page
 
135
     *                  String to go to a different page, e.g: 'index.php'
 
136
     *
 
137
     * @return void
 
138
     */
 
139
    refreshMain: function (url, callback) {
 
140
        if (! url) {
 
141
            url = $('#selflink a').attr('href');
 
142
            url = url.substring(0, url.indexOf('?'));
 
143
        }
 
144
        url += PMA_commonParams.getUrlQuery();
 
145
        $('<a />', {href: url})
 
146
            .appendTo('body')
 
147
            .click()
 
148
            .remove();
 
149
        AJAX._callback = callback;
 
150
    }
 
151
};
 
152
 
 
153
/**
 
154
 * Common functions used for communicating with the querywindow
 
155
 */
 
156
var PMA_querywindow = (function ($, window) {
 
157
    /**
 
158
     * @var Object querywindow Reference to the window
 
159
     *                         object of the querywindow
 
160
     * @access private
 
161
     */
 
162
    var querywindow = {};
 
163
    /**
 
164
     * @var string queryToLoad Stores the SQL query that is to be displayed
 
165
     *                         in the querywindow when it is ready
 
166
     * @access private
 
167
     */
 
168
    var queryToLoad = '';
 
169
    // The returned object is the public part of the module
 
170
    return {
 
171
        /**
 
172
         * Opens the query window
 
173
         *
 
174
         * @param mixed url Undefined to open the default page
 
175
         *                  String to go to a different
 
176
         *
 
177
         * @return void
 
178
         */
 
179
        open: function (url, sql_query) {
 
180
            if (! url) {
 
181
                url = 'querywindow.php' + PMA_commonParams.getUrlQuery();
 
182
            }
 
183
            if (sql_query) {
 
184
                url += '&sql_query=' + encodeURIComponent(sql_query);
 
185
            }
 
186
 
 
187
            if (! querywindow.closed && querywindow.location) {
 
188
                var href = querywindow.location.href;
 
189
                if (href != url
 
190
                    && href != PMA_commonParams.get('pma_absolute_uri') + url
 
191
                ) {
 
192
                    if (PMA_commonParams.get('safari_browser')) {
 
193
                        querywindow.location.href = targeturl;
 
194
                    } else {
 
195
                        querywindow.location.replace(targeturl);
 
196
                    }
 
197
                    querywindow.focus();
 
198
                }
 
199
            } else {
 
200
                querywindow = window.open(
 
201
                    url + '&init=1',
 
202
                    '',
 
203
                    'toolbar=0,location=0,directories=0,status=1,'
 
204
                    + 'menubar=0,scrollbars=yes,resizable=yes,'
 
205
                    + 'width=' + PMA_commonParams.get('querywindow_width') + ','
 
206
                    + 'height=' + PMA_commonParams.get('querywindow_height')
 
207
                );
 
208
            }
 
209
            if (! querywindow.opener) {
 
210
               querywindow.opener = window.window;
 
211
            }
 
212
            if (window.focus) {
 
213
                querywindow.focus();
 
214
            }
 
215
        },
 
216
        /**
 
217
         * Opens, if necessary, focuses the query window
 
218
         * and displays an SQL query.
 
219
         *
 
220
         * @param string sql_query The SQL query to display in
 
221
         *                         the query window
 
222
         *
 
223
         * @return void
 
224
         */
 
225
        focus: function (sql_query) {
 
226
            if (! querywindow || querywindow.closed || ! querywindow.location) {
 
227
                // we need first to open the window and cannot pass the query with it
 
228
                // as we dont know if the query exceeds max url length
 
229
                queryToLoad = sql_query;
 
230
                this.open(false, sql_query);
 
231
            } else {
 
232
                //var querywindow = querywindow;
 
233
                var hiddenqueryform = querywindow
 
234
                    .document
 
235
                    .getElementById('hiddenqueryform');
 
236
                if (hiddenqueryform.querydisplay_tab != 'sql' ) {
 
237
                    hiddenqueryform.querydisplay_tab.value = "sql";
 
238
                    hiddenqueryform.sql_query.value = sql_query;
 
239
                    $(hiddenqueryform).addClass('disableAjax');
 
240
                    hiddenqueryform.submit();
 
241
                    querywindow.focus();
 
242
                } else {
 
243
                    querywindow.focus();
 
244
                }
 
245
            }
 
246
        },
 
247
        /**
 
248
         * Refreshes the query window given a url
 
249
         *
 
250
         * @param string url Where to go to
 
251
         *
 
252
         * @return void
 
253
         */
 
254
        refresh: function (url) {
 
255
            if (! querywindow.closed && querywindow.location) {
 
256
                var $form = $(querywindow.document).find('#sqlqueryform');
 
257
                if ($form.find('#checkbox_lock:checked').length == 0) {
 
258
                    PMA_querywindow.open(url);
 
259
                }
 
260
            }
 
261
        },
 
262
        /**
 
263
         * Reloads the query window given the details
 
264
         * of a db, a table and an sql_query
 
265
         *
 
266
         * @param string db        The name of the database
 
267
         * @param string table     The name of the table
 
268
         * @param string sql_query The SQL query to be displayed
 
269
         *
 
270
         * @return void
 
271
         */
 
272
        reload: function (db, table, sql_query) {
 
273
            if (! querywindow.closed && querywindow.location) {
 
274
                var $form = $(querywindow.document).find('#sqlqueryform');
 
275
                if ($form.find('#checkbox_lock:checked').length == 0) {
 
276
                    var $hiddenform = $(querywindow.document)
 
277
                        .find('#hiddenqueryform');
 
278
                    $hiddenform.find('input[name=db]').val(db);
 
279
                    $hiddenform.find('input[name=table]').val(table);
 
280
                    if (sql_query) {
 
281
                        $hiddenform.find('input[name=sql_query]').val(sql_query);
 
282
                    }
 
283
                    $hiddenform.addClass('disableAjax').submit();
 
284
                }
 
285
            }
 
286
        }
 
287
    };
 
288
})(jQuery, window);