src/js/widgets/createAnnotationWidget.js
branchpopcorn-port
changeset 597 93feb85bb07f
parent 594 96af41097260
child 606 13675511a01a
equal deleted inserted replaced
596:a0d2c5b96bee 597:93feb85bb07f
   124   }
   124   }
   125 };
   125 };
   126 
   126 
   127 /** handle clicks on "send annotation" button */
   127 /** handle clicks on "send annotation" button */
   128 IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) {
   128 IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) {
       
   129   var _this = this;
   129   var textfield = this.selector.find(".Ldt-createAnnotation-Description");
   130   var textfield = this.selector.find(".Ldt-createAnnotation-Description");
   130   var contents = textfield.val();
   131   var contents = textfield.val();
   131 
   132 
   132   if (contents === "") {
   133   if (contents === "") {
   133   
   134   
   174     
   175     
   175     var apiJson = {annotations : [{}], meta: {}};
   176     var apiJson = {annotations : [{}], meta: {}};
   176     var annotation = apiJson["annotations"][0];
   177     var annotation = apiJson["annotations"][0];
   177     //annotation["type_title"] = "Contributions";
   178     //annotation["type_title"] = "Contributions";
   178     annotation["type_title"] = "";
   179     annotation["type_title"] = "";
   179     //annotation["media"] = this._serializer.currentMedia()["id"];
   180     annotation["media"] = this._serializer.currentMedia()["id"];
   180     annotation["media"] = "jeanpierremelville_lecerclerouge";
       
   181     annotation["begin"] = this._currentAnnotation.begin;
   181     annotation["begin"] = this._currentAnnotation.begin;
   182     annotation["end"] = this._currentAnnotation.end;
   182     annotation["end"] = this._currentAnnotation.end;
   183     annotation["type"] = "c_23934F53-A24A-0106-3407-AA3BEF56DE19";
   183     annotation["type"] = this._serializer.getContributions();
   184     annotation.content = {};
   184     annotation.content = {};
   185     annotation.content["data"] = contents;
   185     annotation.content["data"] = contents;
   186     
   186     
   187     var meta = apiJson["meta"];
   187     var meta = apiJson["meta"];
   188     meta.creator = "An User";    
   188     meta.creator = "An User";    
   197     }
   197     }
   198     
   198     
   199     var jsonString = JSON.stringify(apiJson);
   199     var jsonString = JSON.stringify(apiJson);
   200     var project_id = this._serializer._data.meta.id;
   200     var project_id = this._serializer._data.meta.id;
   201     
   201     
   202     var url = Mustache.to_html("{{platf_url}}/ldtplatform/api/ldt/projects/f005b2ec-e27e-11df-8f82-00145ea4a2be.json",
   202     var url = Mustache.to_html("{{platf_url}}/ldtplatform/api/ldt/projects/{{id}}.json",
   203                                 {platf_url: IriSP.platform_url, id: project_id}); 
   203                                 {platf_url: IriSP.platform_url, id: project_id});
       
   204     console.log(url);
   204     IriSP.jQuery.ajax({
   205     IriSP.jQuery.ajax({
   205                 url: url,
   206                 url: url,
   206                 type: 'PUT',
   207                 type: 'PUT',
   207                 contentType: 'application/json',
   208                 contentType: 'application/json',
   208                 data: jsonString,
   209                 data: jsonString,
   209                 // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
   210                 // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
   210                 //dataType: 'json',
   211                 dataType: 'json',
   211                 success: function(json, textStatus, XMLHttpRequest) {
   212                 success: function(json, textStatus, XMLHttpRequest) {
   212                     alert("success = " + json);
   213                     /* add the annotation to the annotations and tell the world */
       
   214 
       
   215                     delete annotation.tags;
       
   216                     annotation.content.description = annotation.content.data;
       
   217                     delete annotation.content.data;
       
   218                     annotation.id = json.annotations[0].id;
       
   219                     annotation.title = _this._currentAnnotation.content.title;
       
   220                     // everything is shared so there's no need to propagate the change
       
   221                     _this._serializer._data.annotations.push(annotation);
       
   222                     _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation");
   213                 },
   223                 },
   214                 error: function(jqXHR, textStatus, errorThrown) {
   224                 error: function(jqXHR, textStatus, errorThrown) {
   215                     alert("ERROR = " + jqXHR.responseText + ", " + errorThrown);
   225                     alert("ERROR = " + jqXHR.responseText + ", " + errorThrown);
   216                 }
   226                 }
   217             });
   227             });