# HG changeset patch # User ymh # Date 1372436173 -7200 # Node ID a17dd7b33e36b4287452c89c4cbfda73d3fdd70a # Parent 8890db197b37e63444cc60204b9d9b8ca0969adf Improve wikipedia dialog. Work with redirect. diff -r 8890db197b37 -r a17dd7b33e36 src/jocondelab/static/jocondelab/js/jocondelab.js --- a/src/jocondelab/static/jocondelab/js/jocondelab.js Fri Jun 28 16:12:24 2013 +0200 +++ b/src/jocondelab/static/jocondelab/js/jocondelab.js Fri Jun 28 18:16:13 2013 +0200 @@ -1,4 +1,48 @@ // -*- coding: utf-8 -*- +function fill_wp_infobox(item) { + + var wp_infobox = $("#wp-infobox"); + if(wp_infobox.length === 0) { + wp_infobox = $("
",{id: 'wp-infobox'}).addClass( "ui-widget-content ui-corner-all").appendTo('body'); + } + + var html_str = "

"+item.label+"

" + + (item.original_label !== item.label ? "

" + gettext("Redirected from: ") + item.original_label+"

":"") + + "" + + "" + + "
" + item.abstract + "
" ; + + + wp_infobox + .html(html_str) + .position({my: "left top", at:"right+5 top", of: $(".ui-autocomplete")}) + .css("z-index", $(".ui-autocomplete").css("z-index")) + .show(); +} + +function get_dp_sparql(resource_url) { + return "select distinct ?s ?t ?y ?l ?r where { " + + "<"+resource_url+"> rdfs:label ?s . " + + "OPTIONAL { <"+resource_url+"> dbpedia-owl:thumbnail ?t } . " + + "OPTIONAL { <"+resource_url+"> dbpedia-owl:abstract ?y . FILTER(langMatches(lang(?y), \"fr\")) } . "+ + "OPTIONAL { <"+resource_url+"> foaf:isPrimaryTopicOf ?l } " + + "OPTIONAL { <"+resource_url+"> dbpedia-owl:wikiPageRedirects ?r } " + + "} LIMIT 100" +} + +function get_dp_ajax(resource_url) { + return $.ajax({ + url: "http://fr.dbpedia.org/sparql", + data: { + query: get_dp_sparql(resource_url), + format: "application/sparql-results+json" + }, + dataType: "json" + }) +} + function init_term_events() { // Tag simple operations : activate/unactivate wp link, remove wp link @@ -73,39 +117,29 @@ }, focus: function(event,ui) { - var wp_infobox = $("#wp-infobox"); - if(wp_infobox.length === 0) { - wp_infobox = $("
",{id: 'wp-infobox'}).addClass( "ui-widget-content ui-corner-all").appendTo('body'); - } var page_name = ui.item.label.replace(/ /g, "_"); var resource_url = "http://fr.dbpedia.org/resource/" + page_name; - $.ajax({ - url: "http://fr.dbpedia.org/sparql", - data: { - query: "select distinct ?t ?y ?l where { OPTIONAL { <"+resource_url+"> dbpedia-owl:thumbnail ?t} . OPTIONAL { <"+resource_url+"> dbpedia-owl:abstract ?y . FILTER(langMatches(lang(?y), \"fr\")) } . OPTIONAL { <"+resource_url+"> foaf:isPrimaryTopicOf ?l } } LIMIT 100", - format: "application/sparql-results+json" - }, - dataType: "json", - success: function(data) { - res = data.results.bindings.length>0?data.results.bindings[0]:{y:"",l:"http://fr.wikipedia.org/"+page_name,t:""}; - var item = { - abstract: res.y?res.y.value:"", - url: res.l?res.l.value:"", - thumbnail: res.t?res.t.value:"" - }; - var html_str = "

"+ui.item.label+"

" + - "" + - "" + - "
" + item.abstract + "
" ; - - wp_infobox - .html(html_str) - .position({my: "left top", at:"right+5 top", of: $(".ui-autocomplete")}) - .css("z-index", $(".ui-autocomplete").css("z-index")) - .show(); - } + var request = get_dp_ajax(resource_url), + chained = request.then(function(data) { + res = data.results.bindings.length>0?data.results.bindings[0]:{y:"",l:"http://fr.wikipedia.org/"+page_name,t:"", r:""}; + if(res.r) { + return get_dp_ajax(res.r.value); + } + else { + return data; + } + }); + + chained.done(function(data) { + res = data.results.bindings.length>0?data.results.bindings[0]:{s:ui.item.label, y:"",l:"http://fr.wikipedia.org/"+page_name,t:"", r:""}; + var item = { + label : res.s?res.s.value:ui.item.label, + original_label : ui.item.label, + abstract: res.y?res.y.value:"", + url: res.l?res.l.value:"", + thumbnail: res.t?res.t.value:"" + }; + fill_wp_infobox(item); }); } }) diff -r 8890db197b37 -r a17dd7b33e36 src/jocondelab/templates/jocondelab/term_edit.html --- a/src/jocondelab/templates/jocondelab/term_edit.html Fri Jun 28 16:12:24 2013 +0200 +++ b/src/jocondelab/templates/jocondelab/term_edit.html Fri Jun 28 18:16:13 2013 +0200 @@ -160,9 +160,9 @@ {% if term.validated %} - OK + OK {% else %} - OK + OK {% endif %}