src/egonomy/templates/egonomy_create_fragment.html
changeset 85 4d320fbfc550
parent 84 b2fbd34b259c
child 86 5e1eb389036a
--- a/src/egonomy/templates/egonomy_create_fragment.html	Mon Mar 04 15:29:30 2013 +0100
+++ b/src/egonomy/templates/egonomy_create_fragment.html	Mon Mar 04 17:40:57 2013 +0100
@@ -42,9 +42,17 @@
                         addTags($("#pertimm_thesaurus_tags").text().split(', '));
                     });
                 }
-                // Function to add one tag
-                $(".addable_tag").click(function() {
-                    addTags([$(this).text()])
+                // Check if path is not empty ("" or "MZ")
+                $(".fragment-path").change(function() {
+                    var v = $(".fragment-path").val();
+                    if(v!="" && v!="MZ"){
+                    	$("#senseetive_click").removeClass("add-button-grey");
+                    	$("#senseetive_click").addClass("clickable add-button");
+                    }
+                    else{
+                        $("#senseetive_click").addClass("add-button-grey");
+                        $("#senseetive_click").removeClass("clickable add-button");
+                    }
                 });
                 // Init tagit autocomplete with tags from various sources
                 autocomplete_tags = $("#rmn_tags").text().split(', ');
@@ -52,6 +60,49 @@
                 autocomplete_tags = autocomplete_tags.concat($("#pertimm_description_tags").text().split(', '));
                 autocomplete_tags = autocomplete_tags.concat($("#pertimm_thesaurus_tags").text().split(', '));
                 $('#user_keywords').tagit({availableTags: autocomplete_tags, allowSpaces: true});
+                
+                // Function to add one tag
+                $(".addable_tag").click(function() {
+                    addTags([$(this).text()]);
+                });
+                
+                // Init senseetive api request
+                if($("#senseetive_click")){
+                    $("#senseetive_click").click(function() {
+                    	var v = $(".fragment-path").val();
+                    	if(v!="" && v!="MZ"){
+	                    	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);
+	                            }
+	                    	});
+                    	}
+                    });
+                }
            	};
            	function addTags(tags){
                 nt = tags.length;
@@ -140,6 +191,10 @@
 	                                    <br/><span id="add_pertimm_thesaurus" class="right clickable">+ {% trans 'Add all Pertimm thesaurus keywords to yours' %}</span></td>
 	                            </tr>
                                 {% endif %}
+                                <tr>
+                                    <th>{% trans "Senseetive keywords" %}&nbsp;:</th>
+                                    <td id="senseetive_holder"><p id="senseetive_click" class="add-button-grey">{% trans 'Request keywords from Senseetive API' %}</p></td>
+                                </tr>
                             </table>
                             <div class="fullwidth">
                                 <input class="user-submit" type="submit" value="{% trans 'Save the fragment' %}" />