Welcome to mirror list, hosted at ThFree Co, Russian Federation.

common.js « src « js - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c79d7802586eec7a0faf50aa3cb748022c2f4f28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
 * Holds common parameters such as server, db, table, etc
 *
 * The content for this is normally loaded from Header.php or
 * Response.php and executed by ajax.js
 *
 * @test-module CommonParams
 */
window.CommonParams = (function () {
    /**
     * @var {Object} params An associative array of key value pairs
     * @access private
     */
    var params = {};
    // The returned object is the public part of the module
    return {
        /**
         * Saves all the key value pair that
         * are provided in the input array
         *
         * @param obj hash The input array
         *
         * @return {void}
         */
        setAll: function (obj) {
            var updateNavigation = false;
            for (var i in obj) {
                if (params[i] !== undefined && params[i] !== obj[i]) {
                    if (i === 'db' || i === 'table') {
                        updateNavigation = true;
                    }
                }
                params[i] = obj[i];
            }
            if (updateNavigation &&
                    $('#pma_navigation_tree').hasClass('synced')
            ) {
                Navigation.showCurrent();
            }
        },
        /**
         * Retrieves a value given its key
         * Returns empty string for undefined values
         *
         * @param {string} name The key
         *
         * @return {string}
         */
        get: function (name) {
            return params[name];
        },
        /**
         * Saves a single key value pair
         *
         * @param {string} name  The key
         * @param {string} value The value
         *
         * @return {CommonParams} For chainability
         */
        set: function (name, value) {
            var updateNavigation = false;
            if (name === 'db' || name === 'table' &&
                params[name] !== value
            ) {
                updateNavigation = true;
            }
            params[name] = value;
            if (updateNavigation &&
                    $('#pma_navigation_tree').hasClass('synced')
            ) {
                Navigation.showCurrent();
            }
            return this;
        },
        /**
         * Returns the url query string using the saved parameters
         *
         * @param {string} separator New separator
         *
         * @return {string}
         */
        getUrlQuery: function (separator) {
            var sep = (typeof separator !== 'undefined') ? separator : '?';
            var common = this.get('common_query');
            var argsep = window.CommonParams.get('arg_separator');
            if (typeof common === 'string' && common.length > 0) {
                // If the last char is the separator, do not add it
                // Else add it
                common = common.endsWith(argsep) ? common : common + argsep;
            }

            return Functions.sprintf(
                '%s%sserver=%s' + argsep + 'db=%s' + argsep + 'table=%s',
                sep,
                common,
                encodeURIComponent(this.get('server')),
                encodeURIComponent(this.get('db')),
                encodeURIComponent(this.get('table'))
            );
        }
    };
}());

/**
 * Holds common parameters such as server, db, table, etc
 *
 * The content for this is normally loaded from Header.php or
 * Response.php and executed by ajax.js
 */
window.CommonActions = {
    /**
     * Saves the database name when it's changed
     * and reloads the query window, if necessary
     *
     * @param {string} newDb new_db The name of the new database
     *
     * @return {void}
     */
    setDb: function (newDb) {
        if (newDb !== window.CommonParams.get('db')) {
            window.CommonParams.setAll({ 'db': newDb, 'table': '' });
        }
    },
    /**
     * Opens a database in the main part of the page
     *
     * @param {string} newDb The name of the new database
     *
     * @return {void}
     */
    openDb: function (newDb) {
        window.CommonParams
            .set('db', newDb)
            .set('table', '');
        this.refreshMain(
            window.CommonParams.get('opendb_url')
        );
    },
    /**
     * Refreshes the main frame
     *
     * @param {any} url Undefined to refresh to the same page
     *                  String to go to a different page, e.g: 'index.php'
     * @param {function | undefined} callback
     *
     * @return {void}
     */
    refreshMain: function (url, callback = undefined) {
        var newUrl = url;
        if (! newUrl) {
            newUrl = $('#selflink').find('a').attr('href') || window.location.pathname;
            newUrl = newUrl.substring(0, newUrl.indexOf('?'));
        }
        if (newUrl.indexOf('?') !== -1) {
            newUrl += window.CommonParams.getUrlQuery(window.CommonParams.get('arg_separator'));
        } else {
            newUrl += window.CommonParams.getUrlQuery('?');
        }
        $('<a></a>', { href: newUrl })
            .appendTo('body')
            .trigger('click')
            .remove();
        if (typeof callback !== 'undefined') {
            window.AJAX.callback = callback;
        }
    }
};