thesaurus add button enabled only when uri is correct
authorcavaliet
Fri, 20 Sep 2013 12:54:55 +0200
changeset 111 e2ecb345b58f
parent 110 7a2b612ca5e0
child 112 ba6056f58516
thesaurus add button enabled only when uri is correct
src/p4l/static/p4l/js/p4l.js
src/p4l/static/p4l/js/semantictree.js
src/p4l/static/p4l/templates/addSemanticUriForm.html
src/p4l/static/p4l/templates/simpleSemanticUriForm.html
--- a/src/p4l/static/p4l/js/p4l.js	Fri Sep 20 11:43:49 2013 +0200
+++ b/src/p4l/static/p4l/js/p4l.js	Fri Sep 20 12:54:55 2013 +0200
@@ -14,12 +14,12 @@
                 save:{
                     method:"PUT",
                     isArray:false,
-                    headers:{'X-CSRFToken':context.csrf_token} 
+                    headers:{'X-CSRFToken':context.csrf_token}
                 } 
             });
 });
 
-app.service("RecordModel", function(Api, context) {    
+app.service("RecordModel", function(Api, context) {
     this.record = Api.record.get({recordId: context.record_id});
     this.uriLabels = context.uri_labels;
 });
@@ -193,6 +193,7 @@
 	    $scope.record = RecordModel.record;
 	    $scope.uriLabels = RecordModel.uriLabels;
 	    $scope.addUriText = '';
+	    $scope.uriInDict = false;
 	    
 	    $scope.addUriToList = function() {
 	    	$scope.list.push($scope.addUriText);
@@ -208,6 +209,9 @@
 	    $scope.updateUriLabelDict = function(k,v) {
 	        $scope.uriLabels[k] = v;
 	    };
+	    $scope.$watch("addUriText", function(newValue, oldValue){
+	    	$scope.uriInDict = (($scope.dataquery!='') && ($scope.addUriText in $scope.uriLabels));
+	    });
       }
     }
 });
@@ -246,6 +250,7 @@
             $scope.record = RecordModel.record;
             $scope.uriLabels = RecordModel.uriLabels;
             $scope.addUriText = '';
+    	    $scope.uriInDict = false;
 
             $scope.updateVal = function() {
                 $scope.val = $scope.addUriText;
@@ -254,6 +259,9 @@
             $scope.updateUriLabelDict = function(k,v) {
                 $scope.uriLabels[k] = v;
             };
+            $scope.$watch("addUriText", function(newValue, oldValue){
+    	    	$scope.uriInDict = (($scope.dataquery!='') && ($scope.addUriText in $scope.uriLabels));
+    	    });
         }
     };
 });
--- a/src/p4l/static/p4l/js/semantictree.js	Fri Sep 20 11:43:49 2013 +0200
+++ b/src/p4l/static/p4l/js/semantictree.js	Fri Sep 20 12:54:55 2013 +0200
@@ -42,6 +42,7 @@
         	angular.element(this).scope().updateUriLabelDict(uri, ui.item.label);
         	// Angular does not listen to val() event so we update the model value manually:
             angular.element(this).controller('ngModel').$setViewValue(uri);
+            angular.element(this).scope().$apply();
         },
         minLength: 2
     });
@@ -200,6 +201,7 @@
 	                        	angular.element($('#id_'+input_name)[0]).scope().updateUriLabelDict(uri, label);
 	                        	// Angular does not listen to val() event so we update the model value manually:
 	                            angular.element($('#id_'+input_name)[0]).controller('ngModel').$setViewValue(uri);
+	                            angular.element($('#id_'+input_name)[0]).scope().$apply();
 	                            // And update the text field val
 	                        	$('#id_'+input_name).val(label + " (" + uri + ")");
 	                        }
--- a/src/p4l/static/p4l/templates/addSemanticUriForm.html	Fri Sep 20 11:43:49 2013 +0200
+++ b/src/p4l/static/p4l/templates/addSemanticUriForm.html	Fri Sep 20 12:54:55 2013 +0200
@@ -18,7 +18,7 @@
 	        <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()" ng-class="{disabled: dataquery==''}">{{'Add' | translate}}</button>
+	        <button type="submit" class="btn btn-primary" ng-click="addUriToList()" ng-class="{disabled: !uriInDict }">{{'Add' | translate}}</button>
 	    </div>
 	</form>
 </div>
\ No newline at end of file
--- a/src/p4l/static/p4l/templates/simpleSemanticUriForm.html	Fri Sep 20 11:43:49 2013 +0200
+++ b/src/p4l/static/p4l/templates/simpleSemanticUriForm.html	Fri Sep 20 12:54:55 2013 +0200
@@ -13,7 +13,7 @@
 	        <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="updateVal()">{{'Update' | translate}}</button>
+	        <button type="submit" class="btn btn-primary" ng-click="updateVal()" ng-class="{disabled: !uriInDict }">{{'Update' | translate}}</button>
 	    </div>
 	</form>
 </div>
\ No newline at end of file