src/widgets/AnnotationsController.js
changeset 1069 2409cb4cebaf
parent 1048 13211bca0256
child 1072 ac1eacb3aa33
--- a/src/widgets/AnnotationsController.js	Fri Oct 02 11:27:17 2015 +0200
+++ b/src/widgets/AnnotationsController.js	Mon Dec 28 15:50:04 2015 +0100
@@ -13,16 +13,22 @@
 IriSP.Widgets.AnnotationsController.prototype.defaults = {
     // If true, displaying AnnotationList will hide CreateAnnotation and vice versa.
     display_or_write: false,
+    toggle_widgets: false,
     starts_hidden: false,
     hide_without_segment: false,
+    hide_when_writing: true,
+    starting_widget: false,
+    always_show_widget: false,
     segments_annotation_type: "chap",
+    custom_write_text: false,
+    custom_display_text: false,
 };
 
 IriSP.Widgets.AnnotationsController.prototype.template = 
     "<div class='Ldt-AnnotationsController'>"
     + "<div class='Ldt-AnnotationsController-ButtonsContainer'>"
-    + "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowCreateAnnotationButton'>{{l10n.write}}</div>"
-    + "    <div class='Ldt-AnnotationsController-Button Ldt-AnnotationsController-ShowAnnotationsListButton'>{{l10n.display}}</div>"
+    + "    <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>"
+    + "    <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>"
     + "</div>"
     + "</div>"
 
@@ -48,24 +54,37 @@
     this.writeButton_$.click(function(){
         if (!_this.writeButton_$.hasClass("selected")){
             _this.player.trigger("CreateAnnotation.show")
+            if (_this.display_or_write){
+                _this.player.trigger("AnnotationsList.hide");
+            }
         }
         else {
             _this.player.trigger("CreateAnnotation.hide")
-        }
-        if (_this.display_or_write){
-            _this.player.trigger("AnnotationsList.hide");
+            if (_this.toggle_widgets){
+                _this.player.trigger("AnnotationsList.show")
+            }
+            else if (_this.display_or_write){
+                _this.player.trigger("AnnotationsList.hide");
+            }
         }
     });
     this.displayButton_$.click(function(){
         if (!_this.displayButton_$.hasClass("selected")){
             _this.player.trigger("AnnotationsList.show")
+            if (_this.display_or_write){
+                _this.player.trigger("CreateAnnotation.hide");
+            }
         }
         else {
             _this.player.trigger("AnnotationsList.hide")
+            if (_this.toggle_widgets){
+                _this.player.trigger("CreateAnnotation.show")
+            }
+            else if (_this.display_or_write){
+                _this.player.trigger("CreateAnnotation.hide");
+            }
         }
-        if (_this.display_or_write){
-            _this.player.trigger("CreateAnnotation.hide");
-        }
+        
     })
     
     if(this.hide_without_segment){
@@ -79,10 +98,20 @@
         this.currentSegment = false
     }
     
+
+    this.createAnnotationEnabled = false;
     this.onMdpEvent("CreateAnnotation.hide", function(){
+        if (_this.hide_when_writing){
+            _this.show()
+        }
+        _this.createAnnotationEnabled = false;
         _this.writeButton_$.toggleClass("selected", false);
     })
     this.onMdpEvent("CreateAnnotation.show", function(){
+        if (_this.hide_when_writing){
+            _this.hide()
+        }
+        _this.createAnnotationEnabled = true;
         _this.writeButton_$.toggleClass("selected", true);
     })
     this.onMdpEvent("AnnotationsList.hide", function(){
@@ -101,6 +130,15 @@
         this.show();
     }
     
+    if (this.starting_widget && this.visible){
+        if (this.starting_widget == "AnnotationsList"){
+            this.player.trigger("AnnotationsList.show")
+        }
+        else if (this.starting_widget == "CreateAnnotation"){
+            this.player.trigger("CreateAnnotation.show")
+        }
+    }
+    
 };
 
 IriSP.Widgets.AnnotationsController.prototype.refresh = function(_timeRange){
@@ -139,22 +177,29 @@
             }
         }
         if (!currentSegment && _currentSegments.length == 0){
-            if (this.visible){
-                this.hide();
+            if (this.visible || this.hide_when_writing){
                 this.writeButton_$.toggleClass("selected", false);
                 this.displayButton_$.toggleClass("selected", false);
                 this.player.trigger("CreateAnnotation.hide");
                 this.player.trigger("AnnotationsList.hide");
+                this.hide();
             }
         }
         else {
             if (!this.visible){
-                this.show();
+                if (!this.createAnnotationEnabled){
+                    this.show();
+                }
                 this.writeButton_$.toggleClass("selected", false);
                 this.displayButton_$.toggleClass("selected", false);
-                this.player.trigger("CreateAnnotation.hide");
-                this.player.trigger("AnnotationsList.hide");
+                if (this.starting_widget == "AnnotationsList"){
+                    this.player.trigger("AnnotationsList.show")
+                }
+                if (this.starting_widget == "CreateAnnotation"){
+                    this.player.trigger("CreateAnnotation.show")
+                }
             }
+            
         }
     }
 }
@@ -162,13 +207,13 @@
 IriSP.Widgets.AnnotationsController.prototype.hide = function() {
     if (this.visible){
         this.visible = false;
-        this.element_$.hide()
+        this.element_$.hide();
     }
 }
 
 IriSP.Widgets.AnnotationsController.prototype.show = function() {
     if(!this.visible){
         this.visible = true;
-        this.element_$.show()
+        this.element_$.show();
     }
 }