X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b5f8d214ba00903379f8716ef563f19743a120b6..bea8d1caad32069ceb8c68feea989fc551b7917d:/redakcja/static/js/wiki/view_annotations.js diff --git a/redakcja/static/js/wiki/view_annotations.js b/redakcja/static/js/wiki/view_annotations.js index d51ce9c8..f62cd65c 100644 --- a/redakcja/static/js/wiki/view_annotations.js +++ b/redakcja/static/js/wiki/view_annotations.js @@ -7,6 +7,7 @@ var old_callback = options.callback || function() { }; this.noupdate_hash_onenter = true; + this.vsplitbar = 'PRZYPISY'; options.callback = function(){ var self = this; @@ -14,8 +15,21 @@ this.$element = $("#side-annotations"); this.$error = $('.error-message', this.$element); this.$annos = $('.annotations-list', this.$element); - $('.refresh', this.$element).click(function() { - self.refresh(self); + this.$spinner = $('.spinner', this.$element); + this.$refresh = $('.refresh', this.$element); + + this.$refresh.click(function() { + $this = $(this); + + self.$refresh.removeClass('active'); + $this.addClass('active'); + atype = $this.text(); + + self.$annos.hide(); + self.$error.hide(); + self.$spinner.show(100, function(){ + self.refresh(self, atype); + }); }); old_callback.call(this); @@ -26,7 +40,7 @@ AnnotationsPerspective.prototype = new $.wiki.Perspective(); - AnnotationsPerspective.prototype.refresh = function(self) { + AnnotationsPerspective.prototype.refresh = function(self, atype) { var xml; persp = $.wiki.activePerspective(); @@ -41,13 +55,15 @@ }, error: function(text){ self.$error.html('

Wystąpił błąd:

' + text + '
'); + self.$spinner.hide(); + self.$error.show(); } }); } else { xml = this.doc.text; } - + var parser = new DOMParser(); var serializer = new XMLSerializer(); var doc = parser.parseFromString(xml, 'text/xml'); @@ -55,36 +71,47 @@ if (error.length > 0) { self.$error.html('Błąd parsowania XML.'); + self.$spinner.hide(); self.$error.show(); - self.$annos.hide(); } else { - self.$error.hide(); - self.$annos.hide(); self.$annos.html(''); var anno_list = new Array(); - var annos = doc.getElementsByTagName('pe'); + var annos = doc.getElementsByTagName(atype); var counter = annos.length; + if (annos.length == 0) + { + self.$annos.html('Nie ma żadnych przypisów'); + self.$spinner.hide(); + self.$annos.show(); + } for (var i=0; i]*>/g, "<$1akap>"); + ann_expr = new RegExp("^<"+atype+"[^>]*>|$", "g") + xml_text = serializer.serializeToString(annos[i]).replace(ann_expr, ""); xml2html({ - xml: text, - success: function(elem){ - elem.txt = $(elem).text().trim(); - anno_list.push(elem); - counter--; - - if (!counter) { - anno_list.sort(function(a, b){return (a.txt < b.txt) ? -1 : (a.txt > b.txt ? 1 : 0)}); - self.$annos.append(anno_list); - self.$annos.show(); + xml: "" + xml_text + "", + success: function(xml_text){ + return function(elem){ + elem.sortby = $(elem).text().trim(); + $(elem).append("
"+ xml_text.replace("&", "&", "g").replace("<", "<", "g") +"
") + anno_list.push(elem); + counter--; + + if (!counter) { + anno_list.sort(function(a, b){return a.sortby.localeCompare(b.sortby);}); + self.$annos.append(anno_list); + self.$spinner.hide(); + self.$annos.show(); + } + } - }, + }(xml_text), error: function(text) { $.unblockUI(); self.$error.html(text); + self.$spinner.hide(); self.$error.show(); } }); @@ -99,9 +126,8 @@ $.wiki.Perspective.prototype.onEnter.call(this); $('.vsplitbar').not('.active').trigger('click'); - $(".vsplitbar-title").html("↓ PRZYPISY ↓"); - - this.refresh(this); + $(".vsplitbar-title").html("↓ PRZYPISY ↓"); + this.$refresh.filter('.active').trigger('click'); };