src/widgets/AnnotationsController.js
changeset 1069 2409cb4cebaf
parent 1048 13211bca0256
child 1072 ac1eacb3aa33
equal deleted inserted replaced
1068:7623f9af9272 1069:2409cb4cebaf
    11 IriSP.Widgets.AnnotationsController.prototype = new IriSP.Widgets.Widget();
    11 IriSP.Widgets.AnnotationsController.prototype = new IriSP.Widgets.Widget();
    12 
    12 
    13 IriSP.Widgets.AnnotationsController.prototype.defaults = {
    13 IriSP.Widgets.AnnotationsController.prototype.defaults = {
    14     // If true, displaying AnnotationList will hide CreateAnnotation and vice versa.
    14     // If true, displaying AnnotationList will hide CreateAnnotation and vice versa.
    15     display_or_write: false,
    15     display_or_write: false,
       
    16     toggle_widgets: false,
    16     starts_hidden: false,
    17     starts_hidden: false,
    17     hide_without_segment: false,
    18     hide_without_segment: false,
       
    19     hide_when_writing: true,
       
    20     starting_widget: false,
       
    21     always_show_widget: false,
    18     segments_annotation_type: "chap",
    22     segments_annotation_type: "chap",
       
    23     custom_write_text: false,
       
    24     custom_display_text: false,
    19 };
    25 };
    20 
    26 
    21 IriSP.Widgets.AnnotationsController.prototype.template = 
    27 IriSP.Widgets.AnnotationsController.prototype.template = 
    22     "<div class='Ldt-AnnotationsController'>"
    28     "<div class='Ldt-AnnotationsController'>"
    23     + "<div class='Ldt-AnnotationsController-ButtonsContainer'>"
    29     + "<div class='Ldt-AnnotationsController-ButtonsContainer'>"
    24     + "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowCreateAnnotationButton'>{{l10n.write}}</div>"
    30     + "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowCreateAnnotationButton'>{{#custom_write_text}}{{/custom_write_text}}{{custom_write_text}}{{^custom_write_text}}{{l10n.write}}{{/custom_write_text}}</div>"
    25     + "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowAnnotationsListButton'>{{l10n.display}}</div>"
    31     + "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowAnnotationsListButton'>{{#custom_display_text}}{{/custom_display_text}}{{custom_display_text}}{{^custom_display_text}}{{l10n.display}}{{/custom_display_text}}</div>"
    26     + "</div>"
    32     + "</div>"
    27     + "</div>"
    33     + "</div>"
    28 
    34 
    29 IriSP.Widgets.AnnotationsController.prototype.messages = {
    35 IriSP.Widgets.AnnotationsController.prototype.messages = {
    30     en : {
    36     en : {
    46     this.writeButton_$ = this.$.find(".Ldt-AnnotationsController-ShowCreateAnnotationButton");
    52     this.writeButton_$ = this.$.find(".Ldt-AnnotationsController-ShowCreateAnnotationButton");
    47     
    53     
    48     this.writeButton_$.click(function(){
    54     this.writeButton_$.click(function(){
    49         if (!_this.writeButton_$.hasClass("selected")){
    55         if (!_this.writeButton_$.hasClass("selected")){
    50             _this.player.trigger("CreateAnnotation.show")
    56             _this.player.trigger("CreateAnnotation.show")
       
    57             if (_this.display_or_write){
       
    58                 _this.player.trigger("AnnotationsList.hide");
       
    59             }
    51         }
    60         }
    52         else {
    61         else {
    53             _this.player.trigger("CreateAnnotation.hide")
    62             _this.player.trigger("CreateAnnotation.hide")
    54         }
    63             if (_this.toggle_widgets){
    55         if (_this.display_or_write){
    64                 _this.player.trigger("AnnotationsList.show")
    56             _this.player.trigger("AnnotationsList.hide");
    65             }
       
    66             else if (_this.display_or_write){
       
    67                 _this.player.trigger("AnnotationsList.hide");
       
    68             }
    57         }
    69         }
    58     });
    70     });
    59     this.displayButton_$.click(function(){
    71     this.displayButton_$.click(function(){
    60         if (!_this.displayButton_$.hasClass("selected")){
    72         if (!_this.displayButton_$.hasClass("selected")){
    61             _this.player.trigger("AnnotationsList.show")
    73             _this.player.trigger("AnnotationsList.show")
       
    74             if (_this.display_or_write){
       
    75                 _this.player.trigger("CreateAnnotation.hide");
       
    76             }
    62         }
    77         }
    63         else {
    78         else {
    64             _this.player.trigger("AnnotationsList.hide")
    79             _this.player.trigger("AnnotationsList.hide")
    65         }
    80             if (_this.toggle_widgets){
    66         if (_this.display_or_write){
    81                 _this.player.trigger("CreateAnnotation.show")
    67             _this.player.trigger("CreateAnnotation.hide");
    82             }
    68         }
    83             else if (_this.display_or_write){
       
    84                 _this.player.trigger("CreateAnnotation.hide");
       
    85             }
       
    86         }
       
    87         
    69     })
    88     })
    70     
    89     
    71     if(this.hide_without_segment){
    90     if(this.hide_without_segment){
    72         this.onMediaEvent("timeupdate", function(){
    91         this.onMediaEvent("timeupdate", function(){
    73             _this.refresh();
    92             _this.refresh();
    77         })
    96         })
    78         this.segments = this.source.getAnnotationsByTypeTitle(this.segments_annotation_type)
    97         this.segments = this.source.getAnnotationsByTypeTitle(this.segments_annotation_type)
    79         this.currentSegment = false
    98         this.currentSegment = false
    80     }
    99     }
    81     
   100     
       
   101 
       
   102     this.createAnnotationEnabled = false;
    82     this.onMdpEvent("CreateAnnotation.hide", function(){
   103     this.onMdpEvent("CreateAnnotation.hide", function(){
       
   104         if (_this.hide_when_writing){
       
   105             _this.show()
       
   106         }
       
   107         _this.createAnnotationEnabled = false;
    83         _this.writeButton_$.toggleClass("selected", false);
   108         _this.writeButton_$.toggleClass("selected", false);
    84     })
   109     })
    85     this.onMdpEvent("CreateAnnotation.show", function(){
   110     this.onMdpEvent("CreateAnnotation.show", function(){
       
   111         if (_this.hide_when_writing){
       
   112             _this.hide()
       
   113         }
       
   114         _this.createAnnotationEnabled = true;
    86         _this.writeButton_$.toggleClass("selected", true);
   115         _this.writeButton_$.toggleClass("selected", true);
    87     })
   116     })
    88     this.onMdpEvent("AnnotationsList.hide", function(){
   117     this.onMdpEvent("AnnotationsList.hide", function(){
    89         _this.displayButton_$.toggleClass("selected", false);
   118         _this.displayButton_$.toggleClass("selected", false);
    90     })
   119     })
    97         this.hide();
   126         this.hide();
    98     }
   127     }
    99     else{
   128     else{
   100         this.visible = false
   129         this.visible = false
   101         this.show();
   130         this.show();
       
   131     }
       
   132     
       
   133     if (this.starting_widget && this.visible){
       
   134         if (this.starting_widget == "AnnotationsList"){
       
   135             this.player.trigger("AnnotationsList.show")
       
   136         }
       
   137         else if (this.starting_widget == "CreateAnnotation"){
       
   138             this.player.trigger("CreateAnnotation.show")
       
   139         }
   102     }
   140     }
   103     
   141     
   104 };
   142 };
   105 
   143 
   106 IriSP.Widgets.AnnotationsController.prototype.refresh = function(_timeRange){
   144 IriSP.Widgets.AnnotationsController.prototype.refresh = function(_timeRange){
   137             else {
   175             else {
   138                 currentSegment = false;
   176                 currentSegment = false;
   139             }
   177             }
   140         }
   178         }
   141         if (!currentSegment && _currentSegments.length == 0){
   179         if (!currentSegment && _currentSegments.length == 0){
   142             if (this.visible){
   180             if (this.visible || this.hide_when_writing){
   143                 this.hide();
       
   144                 this.writeButton_$.toggleClass("selected", false);
   181                 this.writeButton_$.toggleClass("selected", false);
   145                 this.displayButton_$.toggleClass("selected", false);
   182                 this.displayButton_$.toggleClass("selected", false);
   146                 this.player.trigger("CreateAnnotation.hide");
   183                 this.player.trigger("CreateAnnotation.hide");
   147                 this.player.trigger("AnnotationsList.hide");
   184                 this.player.trigger("AnnotationsList.hide");
       
   185                 this.hide();
   148             }
   186             }
   149         }
   187         }
   150         else {
   188         else {
   151             if (!this.visible){
   189             if (!this.visible){
   152                 this.show();
   190                 if (!this.createAnnotationEnabled){
       
   191                     this.show();
       
   192                 }
   153                 this.writeButton_$.toggleClass("selected", false);
   193                 this.writeButton_$.toggleClass("selected", false);
   154                 this.displayButton_$.toggleClass("selected", false);
   194                 this.displayButton_$.toggleClass("selected", false);
   155                 this.player.trigger("CreateAnnotation.hide");
   195                 if (this.starting_widget == "AnnotationsList"){
   156                 this.player.trigger("AnnotationsList.hide");
   196                     this.player.trigger("AnnotationsList.show")
   157             }
   197                 }
       
   198                 if (this.starting_widget == "CreateAnnotation"){
       
   199                     this.player.trigger("CreateAnnotation.show")
       
   200                 }
       
   201             }
       
   202             
   158         }
   203         }
   159     }
   204     }
   160 }
   205 }
   161 
   206 
   162 IriSP.Widgets.AnnotationsController.prototype.hide = function() {
   207 IriSP.Widgets.AnnotationsController.prototype.hide = function() {
   163     if (this.visible){
   208     if (this.visible){
   164         this.visible = false;
   209         this.visible = false;
   165         this.element_$.hide()
   210         this.element_$.hide();
   166     }
   211     }
   167 }
   212 }
   168 
   213 
   169 IriSP.Widgets.AnnotationsController.prototype.show = function() {
   214 IriSP.Widgets.AnnotationsController.prototype.show = function() {
   170     if(!this.visible){
   215     if(!this.visible){
   171         this.visible = true;
   216         this.visible = true;
   172         this.element_$.show()
   217         this.element_$.show();
   173     }
   218     }
   174 }
   219 }