Browse Source

remove annotations and other annotation menu options

j 6 months ago
parent
commit
b4b66f9bd5
4 changed files with 88 additions and 11 deletions
  1. 22
    10
      static/js/annotationPanel.js
  2. 48
    0
      static/js/removeAnnotations.js
  3. 17
    1
      static/js/viewer.js
  4. 1
    0
      static/json/js.json

+ 22
- 10
static/js/annotationPanel.js View File

@@ -1,6 +1,7 @@
1 1
 'use strict';
2 2
 
3
-oml.ui.annotationPanel = function() {
3
+oml.ui.annotationPanel = function(options, self) {
4
+    self = self || {};
4 5
     var ui = oml.user.ui;
5 6
 
6 7
     var ui = oml.user.ui;
@@ -29,14 +30,15 @@ oml.ui.annotationPanel = function() {
29 30
         click: function() {
30 31
             var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
31 32
             $annotation.length && $annotation.delete()
32
-            $deleteQuote.options({disabled: true})
33
+            that.updateSelection()
33 34
         }
34 35
     }).appendTo($bar);
35 36
 
36 37
     var $menuButton = Ox.MenuButton({
37 38
         items: [
38
-            {id: 'addAnnotation', title: 'Add Annotation', disabled: true},
39
-            {id: 'removeAnnotation', title: 'Remove Annotation', disabled: true},
39
+            {id: 'addAnnotation', title: 'Add Annotation', disabled: true, keyboard: 'return'},
40
+            {id: 'removeAnnotation', title: 'Remove Annotation', disabled: true, keyboard: 'delete'},
41
+            {id: 'removeAnnotations', title: 'Remove All Annotation', disabled: true},
40 42
             {},
41 43
             {id: 'show', title: Ox._('Show Annotations'), disabled: true},
42 44
             {group: 'showAnnotationUsers', min: 1, max: 1, items: [
@@ -82,6 +84,14 @@ oml.ui.annotationPanel = function() {
82 84
                 }, function(result) {
83 85
                     oml.ui.exportAnnotationsDialog(result.data).open()
84 86
                 })
87
+            } else if (id =='addAnnotation') {
88
+                oml.$ui.viewer.postMessage('addAnnotation', {})
89
+            } else if (id =='removeAnnotation') {
90
+                var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
91
+                $annotation.length && $annotation.delete()
92
+                that.updateSelection()
93
+            } else if (id =='removeAnnotations') {
94
+                oml.ui.removeAnnotationsDialog().open()
85 95
             } else {
86 96
                 console.log('click', id, data)
87 97
             }
@@ -113,16 +123,18 @@ oml.ui.annotationPanel = function() {
113 123
             }
114 124
         ],
115 125
         orientation: 'vertical'
126
+    }, self).update({
127
+        hasAnnotations: function() {
128
+            $menuButton[self.options.hasAnnotations ? 'enableItem' : 'disableItem']('removeAnnotations')
129
+        }
116 130
     });
117 131
 
118 132
     that.updateSelection = function(selection) {
119
-        $addQuote.options({
120
-            disabled: !selection
121
-        })
122 133
         var $annotation = oml.$ui.annotationFolder.find('.OMLAnnotation.selected')
123
-        $deleteQuote.options({
124
-            disabled: !$annotation.length
125
-        })
134
+        $addQuote.options({disabled: !selection})
135
+        $deleteQuote.options({disabled: !$annotation.length})
136
+        $menuButton[selection ? 'enableItem' : 'disableItem']('addAnnotation')
137
+        $menuButton[$annotation.length ? 'enableItem' : 'disableItem']('removeAnnotation')
126 138
     }
127 139
 
128 140
     return that;

+ 48
- 0
static/js/removeAnnotations.js View File

@@ -0,0 +1,48 @@
1
+'use strict';
2
+
3
+oml.ui.removeAnnotationsDialog = function() {
4
+
5
+    var ui = oml.user.ui,
6
+
7
+        annotations = oml.$ui.viewer.getAnnotations().filter(function(a) {
8
+            return a.user == oml.user.id
9
+        }),
10
+        annotationsName = Ox._(annotations.length == 1 ? 'Annotation' : 'Annotations'),
11
+        theseAnnotationsName = annotations.length == 1
12
+            ? Ox._('this annotation')
13
+            : Ox._('these {0} annotations', [Ox.formatNumber(annotations.length)]),
14
+
15
+        that = oml.ui.confirmDialog({
16
+            buttons: [
17
+                Ox.Button({
18
+                    style: 'squared',
19
+                    title: Ox._('No, Keep {0}', [annotationsName])
20
+                }),
21
+                Ox.Button({
22
+                    style: 'squared',
23
+                    title: Ox._('Yes, Delete {0}', [annotationsName])
24
+                })
25
+            ],
26
+            content: Ox._(
27
+                'Are you sure that you want to permanently delete {0}?',
28
+                [theseAnnotationsName]
29
+            ),
30
+            title: Ox._('Delete {0}', [annotationsName])
31
+        }, function() {
32
+            Ox.serialForEach(annotations, function(a, index, annotations, next) {
33
+                oml.api.removeAnnotation({
34
+                    item: ui.item,
35
+                    annotation: a.id
36
+                }, function(result) {
37
+                    next()
38
+                })
39
+            }, function() {
40
+                Ox.Request.clearCache();
41
+                oml.$ui.viewer.renderAnnotations(true);
42
+            })
43
+        });
44
+
45
+    return that;
46
+
47
+};
48
+

+ 17
- 1
static/js/viewer.js View File

@@ -111,6 +111,7 @@ oml.ui.viewer = function() {
111 111
         if (save !== false) {
112 112
             oml.api.addAnnotation(a)
113 113
         }
114
+        data.user = a.user || oml.user.id
114 115
         data.notes = data.notes || [];
115 116
         annotations.push(data);
116 117
     }
@@ -157,9 +158,13 @@ oml.ui.viewer = function() {
157 158
                             oml.$ui.annotationFolder.append($annotation);
158 159
                             $annotation.annotate();
159 160
                             oml.$ui.annotationPanel.updateSelection(false)
161
+                            oml.$ui.annotationPanel.options({hasAnnotations: true})
160 162
                         } else if (event == 'removeAnnotation') {
161 163
                             oml.$ui.annotationFolder.find('#a-' + data.id).remove()
162 164
                             data.id && removeAnnotation(data.id)
165
+                            oml.$ui.annotationPanel.options({hasAnnotations: annotations.filter(function(a) {
166
+                                return a.user == oml.user.id
167
+                            }).length > 0})
163 168
                         } else if (event == 'selectAnnotation') {
164 169
                             if (data.id) {
165 170
                                 var $annotation = oml.$ui.annotationFolder.find('#a-' + data.id)
@@ -196,7 +201,7 @@ oml.ui.viewer = function() {
196 201
     that.getAnnotations = function() {
197 202
         return annotations;
198 203
     }
199
-    that.renderAnnotations = function() {
204
+    that.renderAnnotations = function(load=false) {
200 205
         var sortKey = ui.sortAnnotations
201 206
         if (sortKey == 'date') {
202 207
             sortKey = 'created'
@@ -207,9 +212,15 @@ oml.ui.viewer = function() {
207 212
         if (sortKey == 'quote') {
208 213
             sortKey = 'text'
209 214
         }
215
+        if (load) {
216
+            loadAnnotations(function() {
217
+                that.renderAnnotations()
218
+            })
219
+        }
210 220
         annotations = Ox.sortBy(annotations, sortKey)
211 221
         oml.$ui.annotationFolder.empty();
212 222
         var visibleAnnotations = [];
223
+        var hasAnnotations = false;
213 224
         annotations.forEach(function(data) {
214 225
             //that.postMessage('removeAnnotation', {id: data.id})
215 226
             if (ui.showAnnotationUsers == 'all' || data.user == oml.user.id) {
@@ -217,7 +228,11 @@ oml.ui.viewer = function() {
217 228
                 oml.$ui.annotationFolder.append($annotation);
218 229
                 visibleAnnotations.push(data)
219 230
             }
231
+            if (data.user == oml.user.id) {
232
+                hasAnnotations = true
233
+            }
220 234
         })
235
+        oml.$ui.annotationPanel.options({hasAnnotations: hasAnnotations})
221 236
         // fixme: trigger loaded event from reader instead?
222 237
         setTimeout(function() {
223 238
             that.postMessage('addAnnotations', {
@@ -225,6 +240,7 @@ oml.ui.viewer = function() {
225 240
                 replace: true
226 241
             })
227 242
         }, 500)
243
+
228 244
     }
229 245
     return that.updateElement();
230 246
 };

+ 1
- 0
static/json/js.json View File

@@ -58,6 +58,7 @@
58 58
     "preferencesPanel.js",
59 59
     "previewButton.js",
60 60
     "previewDialog.js",
61
+    "removeAnnotations.js",
61 62
     "resetUIDialog.js",
62 63
     "rightPanel.js",
63 64
     "sectionButtons.js",