ptrad
[redakcja.git] / src / redakcja / static / js / wiki / wikiapi.js
index 14b8337..5675913 100644 (file)
             this.fullUri = $("*[data-key='full-uri']", meta).text();
 
            this.text = null;
             this.fullUri = $("*[data-key='full-uri']", meta).text();
 
            this.text = null;
+            this.saving = false;
            this.has_local_changes = false;
            this.has_local_changes = false;
-            this.active = true;
+            this.active = new Date();
            this._lock = -1;
            this._context_lock = -1;
            this._lock_count = 0;
            this._lock = -1;
            this._context_lock = -1;
            this._lock_count = 0;
         checkRevision(params) {
             /* this doesn't modify anything, so no locks */
             var self = this;
         checkRevision(params) {
             /* this doesn't modify anything, so no locks */
             var self = this;
-            let active = self.active;
-            self.active = false;
+            let active = new Date() - self.active < 30 * 1000;
+            let saving = self.saving;
             $.ajax({
                 method: "GET",
                 url: reverse("ajax_document_rev", self.id),
                 data: {
                     'a': active,
             $.ajax({
                 method: "GET",
                 url: reverse("ajax_document_rev", self.id),
                 data: {
                     'a': active,
+                    'new': 1,
                 },
                 },
-                dataType: 'text',
+                dataType: 'json',
                 success: function(data) {
                     if (data == '') {
                         if (params.error)
                             params.error();
                     }
                 success: function(data) {
                     if (data == '') {
                         if (params.error)
                             params.error();
                     }
-                    else if (data != self.revision)
-                        params.outdated();
+                    else {
+                        let people = $('<div>');
+                        data.people.forEach((p) => {
+                            let item = $('<img>');
+                            item.attr('src', p.gravatar),
+                            item.attr(
+                                'title',
+                                p.name  + ' (' +
+                                    (p.active ? 'akt.' : 'nieakt.') +
+                                    ' od ' + p.since + ')')
+                            if (p.active) {
+                                item.addClass('active');
+                            }
+                            people.append(item);
+                        });
+                        $("#people").html(people);
+
+                        if (!saving && (data.rev != self.revision)) {
+                            params.outdated();
+                        }
+                   }
                 }
             });
         }
                 }
             });
         }
 
            data['textsave-text'] = self.text;
 
 
            data['textsave-text'] = self.text;
 
+            self.saving = true;
            $.ajax({
                url: reverse("ajax_document_text", self.id),
                type: "POST",
            $.ajax({
                url: reverse("ajax_document_text", self.id),
                type: "POST",
                        changed = true;
                        self.triggerDocumentChanged();
                    };
                        changed = true;
                        self.triggerDocumentChanged();
                    };
+                    self.saving = false;
 
                    params['success'](self, changed, ((changed && "Udało się zapisać :)") || "Twoja wersja i serwera jest identyczna"));
                },
                error: function(xhr) {
 
                    params['success'](self, changed, ((changed && "Udało się zapisać :)") || "Twoja wersja i serwera jest identyczna"));
                },
                error: function(xhr) {
+                    self.saving = false;
                     if ($('#header').hasClass('saving')) {
                         $('#header').removeClass('saving');
                         $.blockUI({
                     if ($('#header').hasClass('saving')) {
                         $('#header').removeClass('saving');
                         $.blockUI({
             $.xmlns["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
             $('rdf|RDF', doc).remove();
             if (params.noFootnotes) {
             $.xmlns["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
             $('rdf|RDF', doc).remove();
             if (params.noFootnotes) {
-                $('pa, pe, pr, pt', doc).remove();
+                $('pa, pe, pr, pt, ptrad', doc).remove();
             }
            if (params.noThemes) {
                $('motyw', doc).remove();
             }
            if (params.noThemes) {
                $('motyw', doc).remove();