Editor fix
[redakcja.git] / redakcja / static / js / wiki / view_summary.js
index 811096d..099a0e8 100644 (file)
@@ -1,40 +1,56 @@
 (function($){
 
        function SummaryPerspective(options) {
-               var old_callback = options.callback;
-               var self = this;
-
-        options.callback = function(){
-                       $('#publish_button').click(function() {
-                               $.blockUI({message: "Oczekiwanie na odpowiedź serwera..."});
-                               self.doc.publish({
-                                       success: function(doc, data) {
-                                               $.blockUI({message: "Udało się.", timeout: 2000});
-                                       },
-                                       failure: function(doc, message) {
-                                               $.blockUI({
-                                                       message: message,
-                                                       timeout: 5000
-                                               });
-                                       }
-
-                               });
+               var old_callback = options.callback || function() {};
+
+               options.callback = function() {
+                       var self = this;
+
+                       // first time page is rendered
+               $('#summary-cover-refresh').click(function() {
+                               self.refreshCover();
                        });
 
-                       old_callback.call(this);
-               };
+               old_callback.call(this);
+               }
 
                $.wiki.Perspective.call(this, options);
     };
 
     SummaryPerspective.prototype = new $.wiki.Perspective();
 
+       SummaryPerspective.prototype.refreshCover = function() {
+               $('#summary-cover-refresh').attr('disabled', 'disabled');
+               this.doc.refreshCover({
+                       success: function(text) {
+                               $('#summary-cover').attr('src', text);
+                       $('#summary-cover-refresh').removeAttr('disabled');
+                       }
+               });
+       };
+
+    SummaryPerspective.prototype.showCharCount = function() {
+        var cc;
+        try {
+            cc = this.doc.getLength();
+            $('#charcount_untagged').hide();
+        }
+        catch (e) {
+            $('#charcount_untagged').show();
+            cc = this.doc.text.replace(/\s{2,}/g, ' ').length;
+        }
+        $('#charcount').html(cc);
+        $('#charcount_pages').html((Math.round(cc/18)/100).toLocaleString());
+    }
+
     SummaryPerspective.prototype.freezeState = function(){
         // must
     };
 
        SummaryPerspective.prototype.onEnter = function(success, failure){
                $.wiki.Perspective.prototype.onEnter.call(this);
+               
+               this.showCharCount();
 
                console.log("Entered summery view");
        };