Resources/public/js/wikiTag.js
author ymh <ymh.work@gmail.com>
Fri, 25 Nov 2011 18:55:42 +0100
changeset 42 0e57c730bb18
parent 33 6c87166b819c
child 44 c114504de4a8
child 47 34718ebfb3c0
permissions -rwxr-xr-x
Documentation and add alternative wp url and label + migrations
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
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
    67
							};
2
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
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   179
                        };
2
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;
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   234
	};
31
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
	  }
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   244
	};
31
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(){
33
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 31
diff changeset
   246
		for(c in reactive_selectors){
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 31
diff changeset
   247
    		$(reactive_selectors[c]).bind("mouseup", Kolich.Selector.mouseup);
6c87166b819c First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
cavaliet
parents: 31
diff changeset
   248
    	}
31
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   249
	});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   250
	
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   251
	// 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
   252
	$("#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
   253
	    $("#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
   254
	    $("#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
   255
	    $("#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
   256
	});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   257
	
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   258
	// 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
   259
	$("#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
   260
	    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
   261
	        $.ajax({
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   262
	            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
   263
	            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
   264
	            data: {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   265
	                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
   266
	                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
   267
	                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
   268
	                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
   269
	                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
   270
	            },
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   271
	            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
   272
	                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
   273
	                    return {
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   274
	                        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
   275
	                        value: item
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   276
	                    };
31
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
	        });
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   280
	    },
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   281
	    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
   282
	        // 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
   283
	        $("#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
   284
	        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
   285
	        $("#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
   286
	    },
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   287
	    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
   288
	    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
   289
	        $( 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
   290
	    },
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   291
	    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
   292
	        $( 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
   293
	    }
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   294
	});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   295
	$('#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
   296
	    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
   297
	        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
   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
	});
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   300
}
b910b4f7485f First step of context menu to add tag by selecting a part of text in the page.
cavaliet
parents: 30
diff changeset
   301
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
function wikitag_update_tag(btn)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
    new_checked = false;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
    if ($(btn).is(".wikitag_remove_tag_from_list")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
        var url = remove_tag_from_list_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
        var id_tag = $(btn).attr('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
    else if ($(btn).is(".wikitag_reset_wp_info")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
        var url = reset_wp_info_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
        var id_tag = $(btn).html();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
        $(btn).html("<img src='"+static_url+"/images/indicator.gif'>");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
    else if ($(btn).is(".wikitag_remove_wp_link")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
        var url = remove_wp_link_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
        var id_tag = $(btn).attr('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
    
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
    // 2 cases : 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
    // - ordered tag for one datasheet : $('#wikitag_document_id') is not null
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
    // - 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
   322
    $.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
        url: url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
        type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
        data: {csrfmiddlewaretoken:global_csrf_token, 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
               wikitag_document_id:$('#wikitag_document_id').val(),
12
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   327
               num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   328
               nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   329
               sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
81cc9274c20a Update Tag alias.
cavaliet
parents: 11
diff changeset
   330
               searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined),
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
               tag_id:id_tag,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
               activated:new_checked
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
               },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
        // 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
   335
        //dataType: 'json',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
        success: function(msg, textStatus, XMLHttpRequest) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
            $('#wikitag_table_container').html(msg);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
		error: function(jqXHR, textStatus, errorThrown) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
			resp = $.parseJSON(jqXHR.responseText);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
			alert(resp.message);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
			$(btn).html(id_tag);
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
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
function wikitag_up_down(arrow)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
    if ($(arrow).is(".up")) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
        mv = "u";
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
    } else {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
        mv = "d";
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
    }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
    var url = tag_up_down_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
    var id_tag = $(arrow).attr('id');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
    // 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
   358
    var pos_tag = $(arrow).attr('pos');
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
    $.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
        url: url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
        type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
        data: {csrfmiddlewaretoken:global_csrf_token, 
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
               wikitag_document_id:$('#wikitag_document_id').val(),
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
               tag_id:id_tag,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
               move:mv,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
               tag_pos:pos_tag
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
               },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
        // 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
   369
        //dataType: 'json',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
        success: function(msg, textStatus, XMLHttpRequest) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
            $('#wikitag_table_container').html(msg);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
            wikitag_init_tags_events();
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
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
function add_tag(tag_label)
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
{
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
    $("#wikitag_ok_search").html("<img src='"+static_url+"/images/indicator.gif'>");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
    var url = add_tag_url;
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
    $.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
        url: url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
        type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
        data: {csrfmiddlewaretoken:global_csrf_token,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
               wikitag_document_id:$('#wikitag_document_id').val(),
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
               value:tag_label
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
               },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
        // 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
   389
        //dataType: 'json',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
        success: function(msg, textStatus, XMLHttpRequest) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
            $('#wikitag_table_container').html(msg);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
            // And scroll to the bottom
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
            $("html").animate({ scrollTop: $(document).height() }, 500);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
        error: function(jqXHR, textStatus, errorThrown) {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
			resp = $.parseJSON(jqXHR.responseText);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
			alert(resp.message);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
        complete: function(){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
            // We empty the input and hide the ok button
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
            $("#wikitag_wp_search").val("");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
            $("#wikitag_ok_search").html("<b>OK</b>");
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
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
function reorder_tags() {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	$('#wikitag_tags_sort').attr("disabled", "disabled");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
	var tag_sort_old_src = $("#wikitag_tags_sort").attr("src");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	$("#wikitag_tags_sort").attr("src",static_url+"images/indicator.gif");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
	$.ajax({
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
		url: reorder_tag_datasheet_url,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
		type: 'POST',
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
		data: {
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
			csrfmiddlewaretoken:global_csrf_token,
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
            wikitag_document_id:$('#wikitag_document_id').val()
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
		},
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
        success: function(msg, textStatus, XMLHttpRequest) {
30
d2fba1e3b94b correction of reorder tag (including the javascript)
ymh <ymh.work@gmail.com>
parents: 13
diff changeset
   420
            $('#wikitag_table_container').html(msg);
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
            wikitag_init_tags_events();
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
            // And scroll to the bottom
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
            $("html").animate({ scrollTop: $(document).height() }, 500);
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
        },
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
        complete: function(){
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
        	$("#wikitag_tags_sort").attr("src",tag_sort_old_src);
42
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   427
        	//TODO ; translate
0e57c730bb18 Documentation and add alternative wp url and label + migrations
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   428
        	alert("Important : le pré-classement automatique est terminé. Veuillez affiner l’ordre des tags manuellement.");
2
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
        	$('#wikitag_tags_sort').removeAttr("disabled");
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
        }
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	});
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
}
13f43f53d0ba first implementation
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
11
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   434
function getUrlVars()
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   435
{
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   436
    var vars = [], hash;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   437
    if(window.location.href.indexOf('?')>=0){
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   438
	    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
   439
	    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
   440
	    {
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   441
	        hash = hashes[i].split('=');
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   442
	        vars.push(hash[0]);
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   443
	        vars[hash[0]] = hash[1];
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   444
	    }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   445
    }
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   446
    return vars;
5f038a505cd7 Debug Category on tag list and document. Finish pagination for tag list.
cavaliet
parents: 2
diff changeset
   447
}