src/p4l/static/p4l/js/p4l.js
changeset 117 0a4e7d6ebe80
parent 112 ba6056f58516
child 119 ece69ca3ac24
equal deleted inserted replaced
116:0a6c7c8f8490 117:0a4e7d6ebe80
     3 
     3 
     4 var app = angular.module("recordApp", ['ngResource', 'ngRoute', 'pascalprecht.translate'])
     4 var app = angular.module("recordApp", ['ngResource', 'ngRoute', 'pascalprecht.translate'])
     5 
     5 
     6 app.service("Api", function($resource, context) {
     6 app.service("Api", function($resource, context) {
     7     this.record = $resource(context.urls.record_api,
     7     this.record = $resource(context.urls.record_api,
     8             {},
     8             {recordId: context.record_id},
     9             {
     9             {
    10                 get: {
    10                 get: {
    11                     method: "GET",
    11                     method: "GET",
    12                     isArray: false
    12                     isArray: false
    13                 },
    13                 },
    18                 } 
    18                 } 
    19             });
    19             });
    20 });
    20 });
    21 
    21 
    22 app.service("RecordModel", function(Api, context) {
    22 app.service("RecordModel", function(Api, context) {
    23     this.record = Api.record.get({recordId: context.record_id});
    23     if(context.record == null) {
       
    24         this.record = Api.record.get();
       
    25     }
       
    26     else {
       
    27         this.record = new Api.record(context.record);
       
    28     }
    24     this.uriLabels = context.uri_labels;
    29     this.uriLabels = context.uri_labels;
    25 });
    30 });
    26 
    31 
    27 
    32 
    28 app.directive('objectDisp', ['$compile', '$http', '$templateCache', 'context', function($compile, $http, $templateCache, context) {
    33 app.directive('objectDisp', ['$compile', '$http', '$templateCache', 'context', function($compile, $http, $templateCache, context) {
   172       templateUrl: function(tElement, tAttrs) {
   177       templateUrl: function(tElement, tAttrs) {
   173           return context.urls.base_static+'p4l/templates/addSemanticUriForm.html';  
   178           return context.urls.base_static+'p4l/templates/addSemanticUriForm.html';  
   174       },
   179       },
   175       link: function($scope, $element, $attrs) {
   180       link: function($scope, $element, $attrs) {
   176     	  // Get queries attributes from $scope listname and context query dict
   181     	  // Get queries attributes from $scope listname and context query dict
   177     	  var attr_dict = context.query_dicts[$scope.listname];
   182     	  var attr_dict = context.query_dicts[$scope.listname];    	  
   178     	  for (var k in attr_dict){
   183     	  for (var k in attr_dict){
   179 			  if (attr_dict.hasOwnProperty(k)) {
   184     	      $scope[k] = attr_dict[k];
   180 			      $scope[k] = attr_dict[k];
       
   181 			  }
       
   182 		  }
   185 		  }
   183 		  $scope.formVisible = false;
   186 		  $scope.formVisible = false;
   184     	  // initalize autocomplete and browse thesaurus events
   187     	  // initalize autocomplete and browse thesaurus events
   185     	  // We have to timeout because init_browse needs the real ids and not {{ $id }}
   188     	  // We have to timeout because init_browse needs the real ids and not {{ $id }}
   186     	  // NB : scope.apply generates bug
   189     	  // NB : scope.apply generates bug