~ubuntu-branches/ubuntu/trusty/phpmyadmin/trusty

« back to all changes in this revision

Viewing changes to js/navigation.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-10-07 20:18:01 UTC
  • mfrom: (1.2.46)
  • Revision ID: package-import@ubuntu.com-20131007201801-l5l0ril5992p8sxz
Tags: 4:4.0.8-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    $('#pma_navigation_tree a.expander').live('click', function(event) {
30
30
        event.preventDefault();
31
31
        event.stopImmediatePropagation();
32
 
        PMA_expandNavigationTree($(this));
 
32
        var $icon = $(this).find('img');
 
33
        if ($icon.is('.ic_b_plus')) {
 
34
            expandTreeNode($(this));
 
35
        } else {
 
36
            collapseTreeNode($(this));
 
37
        }
33
38
    });
34
39
 
35
40
    /**
38
43
     */
39
44
    $('#pma_navigation_reload').live('click', function (event) {
40
45
        event.preventDefault();
 
46
        $('#pma_navigation .throbber')
 
47
            .first()
 
48
            .css('visibility', 'visible');
41
49
        PMA_reloadNavigation();
42
50
    });
43
51
 
156
164
        event.preventDefault();
157
165
        PMA_createViewDialog($(this));
158
166
    });
 
167
 
 
168
    PMA_showCurrentNavigation();
159
169
});
160
170
 
161
171
/**
162
 
 * Expands/collapses the navigation tree and sets to view the expanded
163
 
 *
164
 
 * @param  object $expandElem the element that initiated the expanding
165
 
 * @return void
 
172
 * Expands a node in navigation tree.
 
173
 *
 
174
 * @param $expandElem expander
 
175
 * @param callback    callback function
 
176
 *
 
177
 * @returns void
166
178
 */
167
 
function PMA_expandNavigationTree($expandElem) {
 
179
function expandTreeNode($expandElem, callback)
 
180
{
168
181
    var $children = $expandElem.closest('li').children('div.list_container');
169
182
    var $icon = $expandElem.find('img');
170
183
    if ($expandElem.hasClass('loaded')) {
171
184
        if ($icon.is('.ic_b_plus')) {
172
185
            $icon.removeClass('ic_b_plus').addClass('ic_b_minus');
173
186
            $children.show('fast');
174
 
        } else {
175
 
            $icon.removeClass('ic_b_minus').addClass('ic_b_plus');
176
 
            $children.hide('fast');
 
187
        }
 
188
        if (callback && typeof callback == 'function') {
 
189
            callback.call();
177
190
        }
178
191
    } else {
179
 
        var $destination = $expandElem.closest('li');
180
 
        if($icon.siblings('.throbber').length <= 0) {
181
 
            var $throbber = $('#pma_navigation .throbber')
182
 
                .first()
183
 
                .clone()
184
 
                .css('visibility', 'visible');
185
 
            $icon.hide();
186
 
            $throbber.insertBefore($icon);
187
 
        }
188
 
 
189
 
        var searchClause = PMA_fastFilter.getSearchClause();
190
 
        var searchClause2 = PMA_fastFilter.getSearchClause2($expandElem);
191
 
 
192
 
        var params = {
193
 
            aPath: $expandElem.find('span.aPath').text(),
194
 
            vPath: $expandElem.find('span.vPath').text(),
195
 
            pos: $expandElem.find('span.pos').text(),
196
 
            pos2_name: $expandElem.find('span.pos2_name').text(),
197
 
            pos2_value: $expandElem.find('span.pos2_value').text(),
198
 
            searchClause: searchClause,
199
 
            searchClause2: searchClause2
200
 
        };
201
 
        var url = $('#pma_navigation').find('a.navigation_url').attr('href');
202
 
        $.get(url, params, function (data) {
 
192
        var $throbber = $('#pma_navigation .throbber')
 
193
            .first()
 
194
            .clone()
 
195
            .css('visibility', 'visible')
 
196
            .click(false);
 
197
        $icon.hide();
 
198
        $throbber.insertBefore($icon);
 
199
 
 
200
        loadChildNodes($expandElem, function(data) {
203
201
            if (data.success === true) {
204
 
                $expandElem.addClass('loaded');
205
 
                $destination.find('div.list_container').remove(); // FIXME: Hack, there shouldn't be a list container there
206
 
                $destination.append(data.message);
 
202
                var $destination = $expandElem.closest('li');
207
203
                $icon.removeClass('ic_b_plus').addClass('ic_b_minus');
208
204
                $destination
209
205
                    .children('div.list_container')
213
209
                        .find('a.expander.container')
214
210
                        .click();
215
211
                }
 
212
                if (callback && typeof callback == 'function') {
 
213
                   callback.call();
 
214
                }
216
215
            } else {
217
216
                PMA_ajaxShowMessage(data.error, false);
218
217
            }
219
218
            $icon.show();
220
 
            if($icon.siblings('.throbber').length)
221
 
                $icon.siblings('.throbber').remove();
 
219
            $throbber.remove();
222
220
        });
223
221
    }
224
222
    $expandElem.blur();
225
223
}
226
224
 
227
 
/*
 
225
/**
228
226
 * Auto-scrolls the newly chosen database
229
227
 *
230
228
 * @param  object   $element    The element to set to view
242
240
    }
243
241
}
244
242
 
245
 
/*
246
 
 * Auto-expands the newly chosen database
247
 
 *
248
 
 * @param  string   $oldDb  The previous database
249
 
 * @param  string   $newDb  The newly chosen database
250
 
 *
251
 
 */
252
 
function PMA_autoExpandDatabaseInUse($oldDb, $newDb) {
253
 
    var $expandElem, $icon;
254
 
    //Collapse the previous database
255
 
    if($oldDb !== '' && $oldDb !== $newDb) {
256
 
        $expandElem = $('#pma_navigation_tree a.dbLink:contains("' + $oldDb + '")')
257
 
            .parent().find('a.expander').eq(0);
258
 
        $icon = $expandElem.find('img');
259
 
        if ($icon.is('.ic_b_minus'))
260
 
            PMA_expandNavigationTree($expandElem);
261
 
    }
262
 
    //expand the newly chosen database
263
 
    $expandElem = $('#pma_navigation_tree a.dbLink:contains("' + $newDb + '")')
264
 
        .parent().find('a.expander').eq(0);
265
 
    $icon = $expandElem.find('img');
266
 
    if ($icon.is('.ic_b_plus')) {
267
 
        PMA_expandNavigationTree($expandElem);
268
 
    }
269
 
    //scroll to new database
270
 
    if ($oldDb !== $newDb) {
271
 
        setTimeout(function() {
272
 
            scrollToView($expandElem.closest('li'), $('#pma_navigation_tree_content'));
273
 
        }, 200);
274
 
    }
 
243
/**
 
244
 * Collapses a node in navigation tree.
 
245
 *
 
246
 * @param $expandElem expander
 
247
 *
 
248
 * @returns void
 
249
 */
 
250
function collapseTreeNode($expandElem) {
 
251
    var $children = $expandElem.closest('li').children('div.list_container');
 
252
    var $icon = $expandElem.find('img');
 
253
    if ($expandElem.hasClass('loaded')) {
 
254
        if ($icon.is('.ic_b_minus')) {
 
255
            $icon.removeClass('ic_b_minus').addClass('ic_b_plus');
 
256
            $children.hide('fast');
 
257
        }
 
258
    }
 
259
    $expandElem.blur();
 
260
}
 
261
 
 
262
/**
 
263
 * Loads child items of a node and executes a given callback
 
264
 *
 
265
 * @param $expandElem expander
 
266
 * @param callback    callback function
 
267
 *
 
268
 * @returns void
 
269
 */
 
270
function loadChildNodes($expandElem, callback) {
 
271
    var $destination = $expandElem.closest('li');
 
272
 
 
273
    var searchClause = PMA_fastFilter.getSearchClause();
 
274
    var searchClause2 = PMA_fastFilter.getSearchClause2($expandElem);
 
275
 
 
276
    var params = {
 
277
        aPath: $expandElem.find('span.aPath').text(),
 
278
        vPath: $expandElem.find('span.vPath').text(),
 
279
        pos: $expandElem.find('span.pos').text(),
 
280
        pos2_name: $expandElem.find('span.pos2_name').text(),
 
281
        pos2_value: $expandElem.find('span.pos2_value').text(),
 
282
        searchClause: searchClause,
 
283
        searchClause2: searchClause2
 
284
    };
 
285
 
 
286
    var url = $('#pma_navigation').find('a.navigation_url').attr('href');
 
287
    $.get(url, params, function (data) {
 
288
        if (data.success === true) {
 
289
            $expandElem.addClass('loaded');
 
290
            $destination.find('div.list_container').remove(); // FIXME: Hack, there shouldn't be a list container there
 
291
            $destination.append(data.message);
 
292
            if (callback && typeof callback == 'function') {
 
293
               callback(data);
 
294
            }
 
295
        }
 
296
    });
 
297
}
 
298
 
 
299
/**
 
300
 * Expand the navigation and highlight the current database or table/view
 
301
 *
 
302
 * @returns void
 
303
 */
 
304
function PMA_showCurrentNavigation()
 
305
{
 
306
   var db = PMA_commonParams.get('db');
 
307
   var table = PMA_commonParams.get('table');
 
308
   $('#pma_navigation_tree')
 
309
       .find('li.selected')
 
310
       .removeClass('selected');
 
311
   if (db && table) { // if we are at the table/view level
 
312
       // open the database in the tree
 
313
       var $dbItem = highlightLoadedItem(
 
314
           $('#pma_navigation_tree > div'), db, 'database', false, false
 
315
       );
 
316
       if ($dbItem) {
 
317
           // open the table in the tree and select it
 
318
           var $expander = $dbItem.children('div:first').children('a.expander');
 
319
           // if not loaded or loaded but collapsed
 
320
           if (! $expander.hasClass('loaded')
 
321
               || $expander.find('img').is('.ic_b_plus')
 
322
           ) {
 
323
               expandTreeNode($expander, function() {
 
324
                   loadAndHighlightTableOrView($dbItem, table);
 
325
               });
 
326
           } else {
 
327
               loadAndHighlightTableOrView($dbItem, table);
 
328
           }
 
329
       }
 
330
   } else if (db) { // if we are at the database level
 
331
       // open in the tree and select the database
 
332
       highlightLoadedItem(
 
333
           $('#pma_navigation_tree > div'), db, 'database', true, true
 
334
       );
 
335
   }
 
336
 
 
337
   function highlightLoadedItem($container, name, clazz, doSelect, doOpen) {
 
338
       var ret = false;
 
339
       $container.children('ul').children('li').each(function() {
 
340
           var $li = $(this);
 
341
           // this is a navigation group, recurse
 
342
           if ($li.is('.navGroup')) {
 
343
               var $container = $li.children('div.list_container');
 
344
               var $childRet = highlightLoadedItem(
 
345
                   $container, name, clazz, doSelect, doOpen
 
346
               );
 
347
               if ($childRet) {
 
348
                   ret = $childRet;
 
349
                   return false;
 
350
               }
 
351
           } else { // this is a real navigation item
 
352
               // name and class matches
 
353
               if ($li.is('.' + clazz) && $li.children('a').text() == name) {
 
354
                   if (doSelect) {
 
355
                       $li.addClass('selected');
 
356
                       if (! doOpen) { // if the node will be opened no point scrolling now
 
357
                           scrollToView($li, $('#pma_navigation_tree_content'));
 
358
                       }
 
359
                   }
 
360
                   if (doOpen) {
 
361
                       var $expander = $li.find('div:first').children('a.expander');
 
362
                       if ($expander.length > 0) {
 
363
                           expandTreeNode($expander, function() {
 
364
                               scrollToView($li, $('#pma_navigation_tree_content'));
 
365
                           });
 
366
                       }
 
367
                   }
 
368
                   // taverse up and expand and parent navigation groups
 
369
                   $li.parents('.navGroup').each(function() {
 
370
                       $cont = $(this).children('div.list_container');
 
371
                       if (! $cont.is(':visible')) {
 
372
                           $(this)
 
373
                               .children('div:first')
 
374
                               .children('a.expander')
 
375
                               .click();
 
376
                       }
 
377
                   });
 
378
                   ret = $li;
 
379
                   return false;
 
380
               }
 
381
           }
 
382
       });
 
383
       return ret;
 
384
   }
 
385
 
 
386
   function loadAndHighlightTableOrView($dbItem, table) {
 
387
       var $container = $dbItem.children('div.list_container');
 
388
       var $tableContainer = $container
 
389
           .children('ul')
 
390
           .children('li.tableContainer');
 
391
       var $viewContainer = $container
 
392
           .children('ul')
 
393
           .children('li.viewContainer');
 
394
 
 
395
       if ($tableContainer.length > 0) {
 
396
           var $expander = $tableContainer
 
397
               .children('div:first')
 
398
               .children('a.expander');
 
399
 
 
400
           if (! $expander.hasClass('loaded') ) {
 
401
               loadChildNodes($expander, function(data) {
 
402
                   highlightTableOrView($tableContainer, $viewContainer, table);
 
403
               });
 
404
           } else {
 
405
               highlightTableOrView($tableContainer, $viewContainer, table);
 
406
           }
 
407
       } else if ($viewContainer.length > 0) {
 
408
           highlightView($viewContainer, table);
 
409
       } else {
 
410
           // no containers, highlight the item
 
411
           highlightLoadedItem($container, table, 'table', true, false);
 
412
       }
 
413
   }
 
414
 
 
415
   function highlightTableOrView($tableContainer, $viewContainer, table)
 
416
   {
 
417
       if (isItemInContainer($tableContainer, table, 'table')) {
 
418
           var $expander = $tableContainer
 
419
               .children('div:first')
 
420
               .children('a.expander');
 
421
           if ($expander.find('img').is('.ic_b_plus')) {
 
422
               expandTreeNode($expander);
 
423
           }
 
424
           highlightLoadedItem(
 
425
               $tableContainer.children('div.list_container'),
 
426
               table, 'table', true, false
 
427
           );
 
428
       } else if ($viewContainer.length > 0) {
 
429
           highlightView($viewContainer, table);
 
430
       }
 
431
   }
 
432
 
 
433
   function isItemInContainer($container, name, clazz)
 
434
   {
 
435
       $items = $container.find('li.' + clazz);
 
436
       var found = false;
 
437
       $items.each(function() {
 
438
           if ($(this).children('a').text() == name) {
 
439
               found = true;
 
440
               return false;
 
441
           }
 
442
       });
 
443
       return found;
 
444
   }
 
445
 
 
446
   function highlightView($viewContainer, view) {
 
447
       var $expander = $viewContainer
 
448
           .children('div:first')
 
449
           .children('a.expander');
 
450
       if (! $expander.hasClass('loaded')
 
451
           || $expander.find('img').is('.ic_b_plus')
 
452
       ) {
 
453
           expandTreeNode($expander, function() {
 
454
               highlightLoadedItem(
 
455
                   $viewContainer.children('div.list_container'),
 
456
                   view, 'view', true, false
 
457
               );
 
458
           });
 
459
       } else {
 
460
           highlightLoadedItem(
 
461
               $viewContainer.children('div.list_container'),
 
462
               view, 'view', true, false
 
463
           );
 
464
       }
 
465
   }
275
466
}
276
467
 
277
468
/**
323
514
    });
324
515
    var url = $('#pma_navigation').find('a.navigation_url').attr('href');
325
516
    $.post(url, params, function (data) {
 
517
        // Hide throbber if it's visible
 
518
        $('#pma_navigation .throbber')
 
519
            .first()
 
520
            .css('visibility', 'hidden');
326
521
        if (data.success) {
327
522
            $('#pma_navigation_tree').html(data.message).children('div').show();
 
523
            PMA_showCurrentNavigation();
328
524
            // Fire the callback, if any
329
525
            if (typeof callback === 'function') {
330
526
                callback.call();
331
527
            }
332
 
            PMA_autoExpandDatabaseInUse('', PMA_commonParams.get('db'));
333
528
        } else {
334
529
            PMA_ajaxShowMessage(data.error);
335
530
        }