build
[semainetech_django.git] / project / media / admin_tools / js / menu.js
1 /**
2 * Save/remove bookmarks to/from the bookmark menu item and the database
3 *
4 * @param string url The current page url path (request.get_full_path)
5 * @param string title The current page title
6 * @param string prompt_msg The message to ask for prompting
7 * @return void
8 */
9 var process_bookmarks = function(url, title, prompt_msg) {
10 var $ = jQuery;
11 var new_title;
12 $('#bookmark-button').live('click', function(e) {
13 var submit_url = $("#bookmark-form").attr('action');
14 e.preventDefault();
15 if ($(this).hasClass('bookmarked')) {
16 $(this).removeClass('bookmarked');
17 $('#navigation-menu li.bookmark ul li a[href="' + url + '"]').parent().remove();
18 if (!$('#navigation-menu li.bookmark ul li').length) {
19 $('#navigation-menu li.bookmark ul').remove();
20 $('#navigation-menu li.bookmark a span').remove();
21 $('#navigation-menu li.bookmark').addClass('disabled');
22 }
23 //Drop bookmark and switch form
24 $.post(submit_url, $("#bookmark-form").serialize(), function(data) {
25 $("#bookmark-form").replaceWith(data.replace('**title**', title));
26 }, 'html');
27 } else {
28 new_title = prompt(prompt_msg, title);
29 if (!new_title) {
30 return;
31 }
32 $(this).addClass('bookmarked');
33 if (!$('#navigation-menu li.bookmark ul').length) {
34 $('#navigation-menu li.bookmark a').prepend('<span class="icon"/>');
35 $('#navigation-menu li.bookmark').append('<ul/>');
36 $('#navigation-menu li.bookmark').removeClass('disabled');
37 }
38 $('#navigation-menu li.bookmark ul').append(
39 '<li><a href="' + url + '">' + new_title + '</a></li>'
40 );
41 $('#bookmark-form input[name=title]').attr('value', new_title);
42 // Save bookmark and switch form
43 $.post(submit_url, $("#bookmark-form").serialize(), function(data) {
44 $("#bookmark-form").replaceWith(data);
45 }, 'html');
46 }
47 });
48 };