Merge with cae920b543068c169d5d09fdbb2fd7c4eac7e147 and enhance add sem directive
authorcavaliet
Tue, 10 Sep 2013 10:57:45 +0200
changeset 59 a0ef3043b1d2
parent 58 32591d23cb4b (diff)
parent 56 cae920b54306 (current diff)
child 60 da37c87abbfb
Merge with cae920b543068c169d5d09fdbb2fd7c4eac7e147 and enhance add sem directive
src/p4l/static/p4l/css/semantictree.css
src/p4l/static/p4l/js/p4l.js
src/p4l/static/p4l/templates/addSemanticUriForm.html
src/p4l/templates/p4l/record_update_form.html
--- a/src/p4l/static/p4l/css/semantictree.css	Tue Sep 10 10:26:18 2013 +0200
+++ b/src/p4l/static/p4l/css/semantictree.css	Tue Sep 10 10:57:45 2013 +0200
@@ -1,7 +1,7 @@
-.ng-scope {
+/*.ng-scope {
     border: 1px dashed red;
 }
-/*@charset "UTF-8";
+@charset "UTF-8";
 
 .large_25 {
     width: 25px;
--- a/src/p4l/static/p4l/js/p4l.js	Tue Sep 10 10:26:18 2013 +0200
+++ b/src/p4l/static/p4l/js/p4l.js	Tue Sep 10 10:57:45 2013 +0200
@@ -121,15 +121,15 @@
       replace: true,
       transclude: true,
       scope: {
-    	  localid:"@",
-    	  listname:"@"
+    	  listname:"@",
+    	  list:"=",
       },
       templateUrl: function(tElement, tAttrs) {
           return context.urls.base_static+'p4l/templates/addSemanticUriForm.html';  
       },
       link: function($scope, $element, $attrs) {
     	  // Get queries attributes from $scope listname and context query dict
-    	  attr_dict = context[$scope.listname + "_query_dict"];
+    	  attr_dict = context.query_dicts[$scope.listname];
     	  for (var k in attr_dict){
 			  if (attr_dict.hasOwnProperty(k)) {
 			      $scope[k] = attr_dict[k];
@@ -137,7 +137,7 @@
 		  }
     	  // initalize autocomplete and browse thesaurus events
     	  init_autocomplete();
-    	  // We have to apply because init_browse needs the real ids and not {{ localid }}
+    	  // We have to apply because init_browse needs the real ids and not {{ $id }}
     	  $scope.$apply();
     	  init_browse();
       },
@@ -147,7 +147,7 @@
 	    $scope.addUriText = '';
 	    
 	    $scope.addUriToList = function() {
-	    	$scope.record[$scope.listname].push($scope.addUriText);
+	    	$scope.list.push($scope.addUriText);
 	        $scope.addUriText = '';
 	    };
 	    
@@ -158,6 +158,7 @@
     }
 });
 
+
 app.controller("RecordCtrl", function($scope, RecordModel, context){
     
     $scope.record = RecordModel.record;
--- a/src/p4l/static/p4l/js/semantictree.js	Tue Sep 10 10:26:18 2013 +0200
+++ b/src/p4l/static/p4l/js/semantictree.js	Tue Sep 10 10:57:45 2013 +0200
@@ -125,7 +125,7 @@
 			                            			"title" : b[i]["label"]["value"] + " (" + nb + ") "
 			                            		},
 			                            		"state" : "closed",
-			                            		"metadata" : {uri: "<" + uri + ">", label:b[i]["label"]["value"]}
+			                            		"metadata" : {uri: "<"+uri+">", label:b[i]["label"]["value"]}
 			                            		//"language" : "en"
 			                            	});
 	                            		}
@@ -134,7 +134,7 @@
 			                            		"data" : { 
 			                            			"title" : b[i]["label"]["value"]
 			                            		},
-			                            		"metadata" : {uri: "<" + uri + ">", label:b[i]["label"]["value"]}
+			                            		"metadata" : {uri: "<"+uri+">", label:b[i]["label"]["value"]}
 			                            	});
 	                            		}
 	                            	}
@@ -147,10 +147,6 @@
 	                        },
 	                        progressive_render: true
 	                    },
-	                    ui : {
-	                        select_limit: 1,
-	                        initially_select: $('#thesaurus_tree').val()?['node-term-'+$('#thesaurus_tree').val()]:[]
-	                    },
 	                    plugins : [ "themes", "json_data", "ui"]
 	                });
 	        },
@@ -177,6 +173,8 @@
 	                        else{
 	                        	// First we update the uri/label dict
 	                        	uri = selected_node.data('uri');
+	                        	// We remove the <> from the uri
+	                        	uri = uri.slice(1,-1);
 	                        	label = selected_node.data('label');
 	                        	angular.element($('#id_'+input_name)[0]).scope().updateUriLabelDict(uri, label);
 	                        	// Angular does not listen to val() event so we update the model value manually:
--- a/src/p4l/static/p4l/templates/addSemanticUriForm.html	Tue Sep 10 10:26:18 2013 +0200
+++ b/src/p4l/static/p4l/templates/addSemanticUriForm.html	Tue Sep 10 10:57:45 2013 +0200
@@ -1,15 +1,20 @@
-<form class="form-inline" role="form" > 
-    <div class="form-group col-md-8">
-        <input id="id_{{localid}}" ng-model="addUriText" class="semantic-tree form-control col-md-10" type="text" placeholder="{{'Add a new theme' | translate}}"
-               data-url="{{ dataurl }}" data-query="{{ dataquery }}" data-root-query="{{ datarootquery }}" 
-               data-childs-query="{{ datachildsquery }}" data-child-count-query="{{ datachildcountquery }}" /> 
-        {{ 'or' | translate}}
-        <span id="dialog-link-container-{{localid}}" class="dialog-link-container ui-state-default ui-corner-all"> 
-            <a href="#" id="dialog-link-{{localid}}" class="btn dialog-link" title="Browse">{{'Browse' | translate}}</a> 
-        </span>
-        <span id="dialog-{{localid}}" class="dialog" title="Select term"><span id="term-tree-{{localid}}"></span></span>
-    </div>
-    <div class="form-group">
-        <button type="submit" class="btn btn-primary" ng-click="addUriToList()">{{'Add' | translate}}</button>
-    </div>
-</form>
\ No newline at end of file
+<div>
+    <ul>
+        <li ng-repeat="item in list">{{uriLabels[item]}} <small class="text-muted">({{item}})</small> <a ng-click='removeFromList(item, list)' class="btn btn-default btn-xs"><i class="glyphicon glyphicon-trash"></i></a></li>
+    </ul>
+	<form class="form-inline" role="form">
+	    <div class="form-group col-md-8">
+	        <input id="id_{{ $id }}" ng-model="addUriText" class="semantic-tree form-control col-md-10" type="text" placeholder="{{'Add a new theme' | translate}}"
+	               data-url="{{ dataurl }}" data-query="{{ dataquery }}" data-root-query="{{ datarootquery }}"
+	               data-childs-query="{{ datachildsquery }}" data-child-count-query="{{ datachildcountquery }}" />
+	        {{ 'or' | translate}}
+	        <span id="dialog-link-container-{{ $id }}" class="dialog-link-container ui-state-default ui-corner-all">
+	            <a href="#" id="dialog-link-{{ $id }}" class="btn dialog-link" title="Browse">{{'Browse' | translate}}</a>
+	        </span>
+	        <span id="dialog-{{ $id }}" class="dialog" title="Select term"><span id="term-tree-{{ $id }}"></span></span>
+	    </div>
+	    <div class="form-group">
+	        <button type="submit" class="btn btn-primary" ng-click="addUriToList()">{{'Add' | translate}}</button>
+	    </div>
+	</form>
+</div>
\ No newline at end of file
--- a/src/p4l/templates/p4l/record_update_form.html	Tue Sep 10 10:26:18 2013 +0200
+++ b/src/p4l/templates/p4l/record_update_form.html	Tue Sep 10 10:57:45 2013 +0200
@@ -30,8 +30,7 @@
                 base_static: "{% get_static_prefix %}",
                 record_api: "{% url 'record-detail' identifier=':recordId' %}".replace("\%3A",":"),                
             },
-            themes_query_dict: angular.fromJson('{{ themes_query_dict | safe | addslashes}}'),
-            subjects_query_dict: angular.fromJson('{{ subjects_query_dict | safe | addslashes}}')
+            query_dicts: angular.fromJson('{{ query_dicts | safe | addslashes}}'),
         })
         .config(['$translateProvider', function($translateProvider) {
             $translateProvider.translations(catalog); //catalog is declared in django.views.i18n.javascript_catalog
@@ -59,19 +58,13 @@
     <tr>
       <td>{{'subjects' | translate}}</td>
       <td>
-          <ul>
-              <li ng-repeat="subject in record.subjects">{{uriLabels[subject]}} <small class="text-muted">({{subject}})</small> <a ng-click='removeFromList(subject, record.subjects)' class="btn btn-default btn-xs"><i class="glyphicon glyphicon-trash"></i></a></li>
-          </ul>
-          <add-sem-uri localid="addSubjectText" listname="subjects"></add-sem-uri>
+          <add-sem-uri list="record.subjects" listname="subjects"></add-sem-uri>
       </td>
     </tr>
     <tr>
       <td>{{'themes' | translate}}</td>
       <td>
-          <ul ng-repeat="theme in record.themes">
-              <li>{{ uriLabels[theme] }} <small class="text-muted">({{theme}})</small> <a ng-click='removeFromList(theme, record.themes)' class="btn btn-default btn-xs"><i class="glyphicon glyphicon-trash"></i></a></li>
-          </ul>
-          <add-sem-uri localid="addThemeText" listname="themes"></add-sem-uri>
+          <add-sem-uri list="record.themes" listname="themes"></add-sem-uri>
       </td>
     </tr>
     <tr>
--- a/src/p4l/views.py	Tue Sep 10 10:26:18 2013 +0200
+++ b/src/p4l/views.py	Tue Sep 10 10:57:45 2013 +0200
@@ -125,20 +125,23 @@
         uri_labels.update(get_labels_for_uris([self.object.recordType] if self.object.recordType else [], "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False))
         context['uri_labels'] = json.dumps(uri_labels)
         
-        context['subjects_query_dict'] = json.dumps({
-                            'dataurl': settings.SPARQL_QUERY_ENDPOINT,
-                            'dataquery': settings.SPARQL_SUBJECT_QUERIES["filter"],
-                            'datarootquery': settings.SPARQL_SUBJECT_QUERIES["root"],
-                            'datachildsquery': settings.SPARQL_SUBJECT_QUERIES["childs"],
-                            'datachildcountquery': settings.SPARQL_SUBJECT_QUERIES["child-count"]
-                            })
-        context['themes_query_dict'] = json.dumps({
-                            'dataurl': settings.SPARQL_QUERY_ENDPOINT,
-                            'dataquery': settings.SPARQL_THEME_QUERIES["filter"],
-                            'datarootquery': settings.SPARQL_THEME_QUERIES["root"],
-                            'datachildsquery': settings.SPARQL_THEME_QUERIES["childs"],
-                            'datachildcountquery': settings.SPARQL_THEME_QUERIES["child-count"]
-                            })
+        query_dicts = {
+            'subjects': {
+                'dataurl': settings.SPARQL_QUERY_ENDPOINT,
+                'dataquery': settings.SPARQL_SUBJECT_QUERIES["filter"],
+                'datarootquery': settings.SPARQL_SUBJECT_QUERIES["root"],
+                'datachildsquery': settings.SPARQL_SUBJECT_QUERIES["childs"],
+                'datachildcountquery': settings.SPARQL_SUBJECT_QUERIES["child-count"]
+            },
+            'themes' : {
+                'dataurl': settings.SPARQL_QUERY_ENDPOINT,
+                'dataquery': settings.SPARQL_THEME_QUERIES["filter"],
+                'datarootquery': settings.SPARQL_THEME_QUERIES["root"],
+                'datachildsquery': settings.SPARQL_THEME_QUERIES["childs"],
+                'datachildcountquery': settings.SPARQL_THEME_QUERIES["child-count"]
+            }
+        }
+        context['query_dicts'] = json.dumps(query_dicts)
         
         return context