Resources/public/js/wikiTag.js
author cavaliet
Wed, 09 Nov 2011 17:33:26 +0100
changeset 31 b910b4f7485f
parent 30 d2fba1e3b94b
child 33 6c87166b819c
permissions -rwxr-xr-x
First step of context menu to add tag by selecting a part of text in the page.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
// -*- coding: utf-8 -*-
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
function wikitag_init_tags_events()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
    // Tag simple operations : activate/unactivate wp link, reset wp info, remove wp link, remove tag from list
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    $(".wikitag_reset_wp_info").click(function(e){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
        if(confirm("Confirmez-vous le rétablissement du label original de ce tag ?")){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
            wikitag_update_tag(this);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    $(".wikitag_remove_wp_link").click(function(e){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
        if(confirm("Confirmez-vous le suppression du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?")){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
            wikitag_update_tag(this);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    $(".wikitag_remove_tag_from_list").click(function(){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
        if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
            wikitag_update_tag(this);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    // Wikipedia search management (autocompletion and save changes)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    $.editable.addInputType('autocomplete', {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    	element : $.editable.types.text.element,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    	plugin : function(settings, original) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    		$('input', this).autocomplete(settings.autocomplete);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    	}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    $(".wikipediatag").editable(modify_tag_url, { 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    	indicator : "<img src='"+static_url+"images/indicator.gif'>",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    	type      : "autocomplete",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    	tooltip   : "Cliquer pour éditer...",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    	onblur    : "submit",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    	submitdata: {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
            csrfmiddlewaretoken:global_csrf_token, 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
            wikitag_document_id:$('#wikitag_document_id').val(),
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
    36
            num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
    37
            nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
    38
            sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
    39
            searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined)
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    	callback  : function(value, settings) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
            $('#wikitag_table_container').html(value);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    	},
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		onerror: function(settings, original, jqXHR) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
			resp = $.parseJSON(jqXHR.responseText);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
			alert(resp.message);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
			original.reset();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		},
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    	autocomplete : {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
			source: function( request, response ) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
				$.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
					url: "http://fr.wikipedia.org/w/api.php",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
					dataType: "jsonp",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
					data: {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
						action: "opensearch",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
						limit: "20",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
						namespace: "0",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
						format: "json",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
						search: request.term
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
					},
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
					success: function( data ) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
						response( $.map( data[1], function( item ) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
							return {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
								label: item,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
								value: item
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
							}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
						}));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
					}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
				});
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
			},
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
			minLength: 2,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
			open: function() {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
				$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			},
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
			close: function() {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
				$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
    	}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
    
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
    // Update alias management
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    $(".wikitag_alias").editable(update_tag_alias_url, {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
    	indicator : "<img src='"+static_url+"images/indicator.gif'>",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
    	type      : "text",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
    	placeholder:"",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
    	tooltip   : "Cliquer pour éditer...",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    	onblur    : "submit",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
    	submitdata: {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
            csrfmiddlewaretoken:global_csrf_token, 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
            wikitag_document_id:$('#wikitag_document_id').val(),
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
    92
            num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
    93
            nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
    94
            sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
    95
            searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined)
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
    	callback  : function(value, settings) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
            $('#wikitag_table_container').html(value);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
    	}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
    
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
    // Tag categories management
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
    $(".wikitag_category").editable(update_tag_category_url, {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
    	indicator : "<img src='"+static_url+"/images/indicator.gif'>",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
    	type      : "select",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
        data      : categories_list,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
    	placeholder:"",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    	tooltip   : "Cliquer pour éditer...",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
    	onblur    : "submit",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
    	submitdata: {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
            csrfmiddlewaretoken:global_csrf_token,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
            wikitag_document_id:$('#wikitag_document_id').val(),
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   114
            num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   115
            nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   116
            sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   117
            searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined)
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
    	callback  : function(value, settings) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
            $('#wikitag_table_container').html(value);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
    	}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
    
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
    // Tag table drag and drop
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
    $("#wikitag_table").tableDnD({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
        onDragClass: "wikitag_dragged_row",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
        onDrop: function(table, row){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
            old_order = row.id;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
            $($(row).children()[1]).html("<img src='"+static_url+"/images/indicator.gif'/>");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
            rows = table.tBodies[0].rows;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
            nb_rows = rows.length;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
            for(var i=1; i<nb_rows; i++){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
                if(rows[i].id==old_order){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
                    new_order = i; // No need to +1 because rows[0] are headers
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
                    $.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
                        url: tag_up_down_url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
                        type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
                        data: {csrfmiddlewaretoken:global_csrf_token, 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
                               wikitag_document_id:$('#wikitag_document_id').val(),
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
                               new_order:new_order,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
                               old_order:old_order
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
                               },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
                        // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
                        //dataType: 'json',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
                        success: function(msg, textStatus, XMLHttpRequest) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
                            $('#wikitag_table_container').html(msg);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
                            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
                        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
                    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
                }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
            }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
        dragHandle: "wikitag_updown_td"
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
function wikitag_init_datasheet_events()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
    var select_done = false;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
    // Wikipedia search management (new tag)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
    $("#wikitag_wp_search").autocomplete({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
        source: function( request, response ) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
            $.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
                url: "http://fr.wikipedia.org/w/api.php",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
                dataType: "jsonp",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
                data: {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
                    action: "opensearch",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
                    limit: "20",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
                    namespace: "0",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
                    format: "json",
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
                    search: request.term
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
                },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
                success: function( data ) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
                    response( $.map( data[1], function( item ) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
                        return {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
                            label: item,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
                            value: item
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
                        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
                    }));
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
                }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
            });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
        select: function(event, ui) { 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
            // Since the event still did not update wp_search's val, we force it.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
            $("#wikitag_wp_search").val(ui.item.label);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
            select_done = true;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
            $("#wikitag_ok_search").click();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
        minLength: 2,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
        open: function() {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
            $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
        close: function() {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
            $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
    $('#wikitag_wp_search').keyup(function(e){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
        if((e.keyCode==13) && ($("#wikitag_wp_search").val()!="") && (select_done==false)){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
            add_tag($("#wikitag_wp_search").val());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
        select_done = false;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
    $("#wikitag_ok_search").click(function(){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
        if($("#wikitag_wp_search").val()!=""){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
            add_tag($("#wikitag_wp_search").val());
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
    $("#wikitag_tags_sort").click(function(e){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
    	 e.preventDefault();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
    	if(confirm("Confirmez-vous le tri des tags ?")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
    		reorder_tags();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
    	}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
31
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   217
function wikitag_init_search_context_events()
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   218
{
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   219
	// We implement the behaviour on text select. Kolich is just an object name, it could be anything
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   220
	if(!window.Kolich){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   221
	    Kolich = {};
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   222
	}
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   223
	Kolich.Selector = {};
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   224
	Kolich.Selector.getSelected = function(){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   225
	    var t = '';
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   226
	    if(window.getSelection){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   227
	        t = window.getSelection();
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   228
	    }else if(document.getSelection){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   229
	        t = document.getSelection();
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   230
	    }else if(document.selection){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   231
	        t = document.selection.createRange().text;
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   232
	    }
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   233
	    return t;
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   234
	}
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   235
	Kolich.Selector.mouseup = function(e){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   236
	  var st = Kolich.Selector.getSelected();
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   237
	  if(st!=''){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   238
	    // Behaviour after the text was selected
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   239
	    $("#wikitag_context_div").offset({left:e.pageX+10,top:e.pageY});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   240
	    $("#wikitag_context_div").show();
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   241
	    $("#wikitag_context_div #wikitag_wp_search_context").val(st);
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   242
	    $("#wikitag_context_div #wikitag_wp_search_context").autocomplete("search");
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   243
	  }
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   244
	}
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   245
	$(document).ready(function(){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   246
	    $(document).bind("mouseup", Kolich.Selector.mouseup);
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   247
	});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   248
	
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   249
	// Function to close the context window
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   250
	$("#wikitag_context_close").click(function(e){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   251
	    $("#wikitag_context_div #wikitag_wp_search_context").autocomplete("close");
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   252
	    $("#wikitag_context_div").offset({left:0,top:0});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   253
	    $("#wikitag_context_div").hide();
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   254
	});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   255
	
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   256
	// Wikipedia search management (new tag)
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   257
	$("#wikitag_wp_search_context").autocomplete({
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   258
	    source: function( request, response ) {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   259
	        $.ajax({
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   260
	            url: "http://fr.wikipedia.org/w/api.php",
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   261
	            dataType: "jsonp",
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   262
	            data: {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   263
	                action: "opensearch",
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   264
	                limit: "20",
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   265
	                namespace: "0",
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   266
	                format: "json",
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   267
	                search: request.term
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   268
	            },
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   269
	            success: function( data ) {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   270
	                response( $.map( data[1], function( item ) {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   271
	                    return {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   272
	                        label: item,
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   273
	                        value: item
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   274
	                    }
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   275
	                }));
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   276
	            }
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   277
	        });
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   278
	    },
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   279
	    select: function(event, ui) { 
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   280
	        // Since the event still did not update wp_search's val, we force it.
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   281
	        $("#wikitag_wp_search_context").val(ui.item.label);
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   282
	        add_tag($("#wikitag_wp_search_context").val());
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   283
	        $("#wikitag_context_close").click();
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   284
	    },
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   285
	    minLength: 2,
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   286
	    open: function() {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   287
	        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   288
	    },
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   289
	    close: function() {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   290
	        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   291
	    }
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   292
	});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   293
	$('#wikitag_wp_search_context').keyup(function(e){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   294
	    if((e.keyCode==13) && ($("#wikitag_wp_search_context").val()!="")){
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   295
	        add_tag($("#wikitag_wp_search_context").val());
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   296
	    }
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   297
	});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   298
}
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   299
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
function wikitag_update_tag(btn)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
    new_checked = false;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
    if ($(btn).is(".wikitag_remove_tag_from_list")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
        var url = remove_tag_from_list_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
        var id_tag = $(btn).attr('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
    else if ($(btn).is(".wikitag_reset_wp_info")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
        var url = reset_wp_info_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
        var id_tag = $(btn).html();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
        $(btn).html("<img src='"+static_url+"/images/indicator.gif'>");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
    else if ($(btn).is(".wikitag_remove_wp_link")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
        var url = remove_wp_link_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
        var id_tag = $(btn).attr('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
    
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
    // 2 cases : 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
    // - ordered tag for one datasheet : $('#wikitag_document_id') is not null
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
    // - all tags list : $('#wikitag_document_id') is null and $('#num_page') and $('#nb_by_page') are not null
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
    $.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
        url: url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
        type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
        data: {csrfmiddlewaretoken:global_csrf_token, 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
               wikitag_document_id:$('#wikitag_document_id').val(),
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   325
               num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   326
               nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   327
               sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   328
               searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined),
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
               tag_id:id_tag,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
               activated:new_checked
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
               },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
        // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
        //dataType: 'json',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
        success: function(msg, textStatus, XMLHttpRequest) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
            $('#wikitag_table_container').html(msg);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
		error: function(jqXHR, textStatus, errorThrown) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
			resp = $.parseJSON(jqXHR.responseText);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
			alert(resp.message);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
			$(btn).html(id_tag);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
function wikitag_up_down(arrow)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
    if ($(arrow).is(".up")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
        mv = "u";
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
    } else {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
        mv = "d";
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
    var url = tag_up_down_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
    var id_tag = $(arrow).attr('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
    // This indicates the position (from 0) of the tag in the list. NB : it is different from the TagSheet.order in the database.
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
    var pos_tag = $(arrow).attr('pos');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
    $.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
        url: url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
        type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
        data: {csrfmiddlewaretoken:global_csrf_token, 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
               wikitag_document_id:$('#wikitag_document_id').val(),
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
               tag_id:id_tag,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
               move:mv,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
               tag_pos:pos_tag
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
               },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
        // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
        //dataType: 'json',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
        success: function(msg, textStatus, XMLHttpRequest) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
            $('#wikitag_table_container').html(msg);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
function add_tag(tag_label)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
    $("#wikitag_ok_search").html("<img src='"+static_url+"/images/indicator.gif'>");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
    var url = add_tag_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
    $.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
        url: url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
        type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
        data: {csrfmiddlewaretoken:global_csrf_token,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
               wikitag_document_id:$('#wikitag_document_id').val(),
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
               value:tag_label
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
               },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
        // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
        //dataType: 'json',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
        success: function(msg, textStatus, XMLHttpRequest) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
            $('#wikitag_table_container').html(msg);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
            // And scroll to the bottom
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
            $("html").animate({ scrollTop: $(document).height() }, 500);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
        error: function(jqXHR, textStatus, errorThrown) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
			resp = $.parseJSON(jqXHR.responseText);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
			alert(resp.message);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
        complete: function(){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
            // We empty the input and hide the ok button
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
            $("#wikitag_wp_search").val("");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
            $("#wikitag_ok_search").html("<b>OK</b>");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
    });
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
function reorder_tags() {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	$('#wikitag_tags_sort').attr("disabled", "disabled");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
	var tag_sort_old_src = $("#wikitag_tags_sort").attr("src");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	$("#wikitag_tags_sort").attr("src",static_url+"images/indicator.gif");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
	$.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
		url: reorder_tag_datasheet_url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
		type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
		data: {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
			csrfmiddlewaretoken:global_csrf_token,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
            wikitag_document_id:$('#wikitag_document_id').val()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
		},
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
        success: function(msg, textStatus, XMLHttpRequest) {
30
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   418
            $('#wikitag_table_container').html(msg);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
            // And scroll to the bottom
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
            $("html").animate({ scrollTop: $(document).height() }, 500);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
        complete: function(){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
        	$("#wikitag_tags_sort").attr("src",tag_sort_old_src);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
        	$('#wikitag_tags_sort').removeAttr("disabled");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	});
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   430
function getUrlVars()
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   431
{
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   432
    var vars = [], hash;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   433
    if(window.location.href.indexOf('?')>=0){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   434
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   435
	    for(var i = 0; i < hashes.length; i++)
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   436
	    {
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   437
	        hash = hashes[i].split('=');
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   438
	        vars.push(hash[0]);
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   439
	        vars[hash[0]] = hash[1];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   440
	    }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   441
    }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   442
    return vars;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   443
}