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