lokalizacja menu kontekstowego
[redakcja.git] / redakcja / static / js / wiki / view_history.js
index b4a9dd8..85adca0 100644 (file)
@@ -5,16 +5,34 @@
 
                options.callback = function() {
                        var self = this;
+            if (CurrentDocument.diff) {
+                rev_from = CurrentDocument.diff[0];
+                rev_to = CurrentDocument.diff[1];
+                this.doc.fetchDiff({
+                    from: rev_from,
+                    to: rev_to,
+                    success: function(doc, data){
+                        var result = $.wiki.newTab(doc, ''+rev_from +' -> ' + rev_to, 'DiffPerspective');
+
+                        $(result.view).html(data);
+                        $.wiki.switchToTab(result.tab);
+                    }
+                });
+            }
 
                        // first time page is rendered
                $('#make-diff-button').click(function() {
                                self.makeDiff();
                        });
 
-                       $('#tag-changeset-button').click(function() {
-                               self.showTagForm();
+                       $('#pubmark-changeset-button').click(function() {
+                               self.showPubmarkForm();
                        });
 
+               $('#doc-revert-button').click(function() {
+                   self.revertDialog();
+               });
+
                        $('#open-preview-button').click(function(event) {
                                var selected = $('#changes-list .entry.selected');
 
 
                $('#changes-list .entry').live('click', function(){
                var $this = $(this);
-               if ($this.hasClass('selected'))
-                       return $this.removeClass('selected');
 
-               if ($("#changes-list .entry.selected").length < 2)
-                       return $this.addClass('selected');
+               var selected_count = $("#changes-list .entry.selected").length;
+
+               if ($this.hasClass('selected')) {
+                       $this.removeClass('selected');
+                       selected_count -= 1;
+               }
+               else {
+                   if (selected_count  < 2) {
+                       $this.addClass('selected');
+                       selected_count += 1;
+                   };
+               };
+
+               $('#history-view-editor .toolbar button').attr('disabled', 'disabled').
+                   filter('*[data-enabled-when~=' + selected_count + '], *[data-enabled-when~=*]').
+                   attr('disabled', null);
                });
 
            $('#changes-list span.tag').live('click', function(event){
                                        stub: $stub,
                                        data: this,
                                        filters: {
-                                               tag: function(value) {
-                                                       return tags.filter("*[value='"+value+"']").text();
-                                               }
+//                                             tag: function(value) {
+//                                                     return tags.filter("*[value='"+value+"']").text();
+//                                             }
+//                        description: function(value) {
+//                                                 return value.replace('\n', ');
+//                                             }
                                        }
                                });
             });
         });
     };
 
-       HistoryPerspective.prototype.showTagForm = function(){
+       HistoryPerspective.prototype.showPubmarkForm = function(){
                var selected = $('#changes-list .entry.selected');
 
                if (selected.length != 1) {
         }
 
                var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
-               $.wiki.showDialog('#add_tag_dialog', {'revision': version});
+               $.wiki.showDialog('#pubmark_dialog', {'revision': version});
        };
 
        HistoryPerspective.prototype.makeDiff = function() {
         });
     };
 
+    HistoryPerspective.prototype.revertDialog = function(){
+        var self = this;
+        var selected = $('#changes-list .entry.selected');
+
+        if (selected.length != 1) {
+            window.alert("Musisz zaznaczyć dokładnie jedną wersję.");
+            return;
+        }
+
+        var version = parseInt($("*[data-stub-value='version']", selected[0]).text());
+        $.wiki.showDialog('#revert_dialog', {revision: version});
+    };
+
     $.wiki.HistoryPerspective = HistoryPerspective;
 
 })(jQuery);