--- a/src/egonomy/templates/egonomy_create_fragment.html Thu Mar 14 15:04:03 2013 +0100
+++ b/src/egonomy/templates/egonomy_create_fragment.html Thu Mar 14 15:23:35 2013 +0100
@@ -20,6 +20,46 @@
{% block js_inline %}
{{block.super}}
<script type="text/javascript">
+ function init_sensitive_click(){
+ // Init senseetive api request
+ if($("#senseetive_click")){
+ $("#senseetive_click").click(function() {
+ var v = $(".fragment-path").val();
+ if(v!="" && v!="MZ" && !$("#senseetive_click").hasClass("loader")){
+ $("#senseetive_click").addClass("loader");
+ var data_obj = { "image":"{{ img.id }}", "path":$("#fragment_path").val() };
+ $.ajax({
+ url: '{% url "senseetive_api" %}',
+ data: data_obj,
+ dataType: "json",
+ success: function(data, status, request){
+ var n = data.length;
+ if(n>0){
+ s = '<span id="add_senseetive_tags">';
+ for(var i=0;i<n;i++){
+ s += '<span class="clickable addable_tag">' + data[i] + '</span>';
+ if(i<(n-1)) s += ', ';
+ }
+ s += '</span><br/><span id="senseetive_tags" class="right clickable">+ {% trans 'Add all Senseetive keywords to yours' %}</span>';
+ $("#senseetive_holder").html(s);
+ // Function to add one tag
+ $("#senseetive_holder .addable_tag").click(function() {
+ addTags([$(this).text()]);
+ });
+ // Functions to add all tags from senseetive
+ $("#senseetive_tags").click(function() {
+ addTags($("#add_senseetive_tags").text().split(', '));
+ });
+ }
+ },
+ error: function(jqXHR, textStatus, errorThrown) {
+ $("#senseetive_holder").html("<strong>ERROR</strong> : " + jqXHR.responseText);
+ }
+ });
+ }
+ });
+ }
+ }
window.onload = function() {
// Functions to add all tags from various sources
if($("#add_rmn_tags")){
@@ -44,6 +84,10 @@
}
// Check if path is not empty ("" or "MZ")
$(".fragment-path").change(function() {
+ if($("#senseetive_holder").children()[0].id!="senseetive_click"){
+ $("#senseetive_holder").html("<p id=\"senseetive_click\" class=\"add-button-grey\">{% trans 'Request keywords from Senseetive API' %}</p>");
+ init_sensitive_click();
+ }
var v = $(".fragment-path").val();
if(v!="" && v!="MZ"){
$("#senseetive_click").removeClass("add-button-grey");
@@ -67,43 +111,7 @@
});
// Init senseetive api request
- if($("#senseetive_click")){
- $("#senseetive_click").click(function() {
- var v = $(".fragment-path").val();
- if(v!="" && v!="MZ" && !$("#senseetive_click").hasClass("loader")){
- $("#senseetive_click").addClass("loader");
- var data_obj = { "image":"{{ img.id }}", "path":$("#fragment_path").val() };
- $.ajax({
- url: '{% url "senseetive_api" %}',
- data: data_obj,
- dataType: "json",
- success: function(data, status, request){
- var n = data.length;
- if(n>0){
- s = '<span id="add_senseetive_tags">';
- for(var i=0;i<n;i++){
- s += '<span class="clickable addable_tag">' + data[i] + '</span>';
- if(i<(n-1)) s += ', ';
- }
- s += '</span><br/><span id="senseetive_tags" class="right clickable">+ {% trans 'Add all Senseetive keywords to yours' %}</span>';
- $("#senseetive_holder").html(s);
- // Function to add one tag
- $("#senseetive_holder .addable_tag").click(function() {
- addTags([$(this).text()]);
- });
- // Functions to add all tags from senseetive
- $("#senseetive_tags").click(function() {
- addTags($("#add_senseetive_tags").text().split(', '));
- });
- }
- },
- error: function(jqXHR, textStatus, errorThrown) {
- $("#senseetive_holder").html("<strong>ERROR</strong> : " + jqXHR.responseText);
- }
- });
- }
- });
- }
+ init_sensitive_click();
};
function addTags(tags){
nt = tags.length;