From 1b8ab1430082a145a3e4807de837dcc1568178a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Thu, 8 Apr 2010 00:44:01 +0200 Subject: [PATCH 1/1] More javascript refactoring. Added form for tagging. --- apps/wiki/helpers.py | 41 +++++++++++++++++++ apps/wiki/templates/wiki/tag_dialog.html | 5 +++ platforma/static/icons/close.png | Bin 0 -> 388 bytes platforma/static/js/jquery.elastic.js | 6 +++ platforma/static/js/wiki/diff_view.js | 27 ++++++++++++ platforma/static/js/wiki/save_dialog.js | 50 +++++++++++++++++++++++ 6 files changed, 129 insertions(+) create mode 100644 apps/wiki/helpers.py create mode 100644 apps/wiki/templates/wiki/tag_dialog.html create mode 100644 platforma/static/icons/close.png create mode 100644 platforma/static/js/jquery.elastic.js create mode 100644 platforma/static/js/wiki/diff_view.js create mode 100644 platforma/static/js/wiki/save_dialog.js diff --git a/apps/wiki/helpers.py b/apps/wiki/helpers.py new file mode 100644 index 00000000..7ed97b41 --- /dev/null +++ b/apps/wiki/helpers.py @@ -0,0 +1,41 @@ +from django import http +from django.utils import simplejson as json +from django.utils.functional import Promise +from django.template.loader import render_to_string +from datetime import datetime + +class ExtendedEncoder(json.JSONEncoder): + + def default(self, obj): + if isinstance(obj, Promise): + return unicode(obj) + + if isinstance(obj, datetime): + return datetime.ctime(obj) + " " + (datetime.tzname(obj) or 'GMT') + + return json.JSONEncoder.default(self, obj) + +# shortcut for JSON reponses +class JSONResponse(http.HttpResponse): + + def __init__(self, data = {}, **kwargs): + # get rid of mimetype + kwargs.pop('mimetype', None) + + super(JSONResponse, self).__init__( + json.dumps(data, cls=ExtendedEncoder), + mimetype = "application/json", **kwargs) + + +# return errors +class JSONFormInvalid(JSONResponse): + def __init__(self, form): + super(JSONFormInvalid, self).__init__(form.errors, status = 400) + +class JSONServerError(JSONResponse): + def __init__(self, *args, **kwargs): + kwargs['status'] = 500 + super(JSONServerError, self).__init__(*args, **kwargs) + + + \ No newline at end of file diff --git a/apps/wiki/templates/wiki/tag_dialog.html b/apps/wiki/templates/wiki/tag_dialog.html new file mode 100644 index 00000000..3cc056eb --- /dev/null +++ b/apps/wiki/templates/wiki/tag_dialog.html @@ -0,0 +1,5 @@ +
+
+ {{ forms.add_tag.as_p }} +
+
diff --git a/platforma/static/icons/close.png b/platforma/static/icons/close.png new file mode 100644 index 0000000000000000000000000000000000000000..688a979c113fc9ce70640e650bd04099ff2c96c1 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4F%}28J29*~C-V}>VN3FMcVYMs zf(!O8p9~b?EbxddW?O@pN$vk+@tt z;h@(M1BsU9w{vrxG8ApMoqT$KxuBR}+0kzO@CboK{e7M1Cw!BMO4=owym!s%MGwkl zW+bL1^qia$q$|jJ?q^w~n9gY?#Us-?oI*p}cdgs(qIorI?fgq7t>5c5U9)3oxc1A{ z>tu4zi(T&~2wbd=oW_*C=ese3hh~1=mO>f-mp13~E9c!eK4!#_(6d%D`L*`rmG6Ha ze{$z}Sa$7{pl3S{RsT<1d$(O6E<8P#H=%WZ4dV}%1{aRP>n3MEzu&U@%F5TfYB$}? zS++>y)Bj^UhXumU?M&|Z_-Na;cWbs').css({'position':'absolute','display':'none','word-wrap':'break-word'}),lineHeight=parseInt($textarea.css('line-height'),10)||parseInt($textarea.css('font-size'),'10'),minheight=parseInt($textarea.css('height'),10)||lineHeight*3,maxheight=parseInt($textarea.css('max-height'),10)||Number.MAX_VALUE,goalheight=0,i=0;if(maxheight<0){maxheight=Number.MAX_VALUE;} +$twin.appendTo($textarea.parent());var i=mimics.length;while(i--){$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()));} +function setHeightAndOverflow(height,overflow){curratedHeight=Math.floor(parseInt(height,10));if($textarea.height()!=curratedHeight){$textarea.css({'height':curratedHeight+'px','overflow':overflow});}} +function update(){var textareaContent=$textarea.val().replace(/&/g,'&').replace(/ /g,' ').replace(/<|>/g,'>').replace(/\n/g,'
');var twinContent=$twin.html();if(textareaContent+' '!=twinContent){$twin.html(textareaContent+' ');if(Math.abs($twin.height()+lineHeight-$textarea.height())>3){var goalheight=$twin.height()+lineHeight;if(goalheight>=maxheight){setHeightAndOverflow(maxheight,'auto');}else if(goalheight<=minheight){setHeightAndOverflow(minheight,'hidden');}else{setHeightAndOverflow(goalheight,'hidden');}}}} +$textarea.css({'overflow':'hidden'});$textarea.keyup(function(){update();});$textarea.live('input paste',function(e){setTimeout(update,250);});update();});}});})(jQuery); \ No newline at end of file diff --git a/platforma/static/js/wiki/diff_view.js b/platforma/static/js/wiki/diff_view.js new file mode 100644 index 00000000..3eafd135 --- /dev/null +++ b/platforma/static/js/wiki/diff_view.js @@ -0,0 +1,27 @@ +(function($){ + + function DiffPerspective(options) { + var old_callback = options.callback || function() {}; + options.callback = function(){ + old_callback.call(this); + }; + + $.wiki.Perspective.call(this, options); + }; + + DiffPerspective.prototype = new $.wiki.Perspective(); + + DiffPerspective.prototype.freezeState = function(){ + // must + }; + + DiffPerspective.prototype.onEnter = function(success, failure){ + $.wiki.Perspective.prototype.onEnter.call(this); + + console.log("Entered diff view"); + }; + + $.wiki.DiffPerspective = DiffPerspective; + +})(jQuery); + diff --git a/platforma/static/js/wiki/save_dialog.js b/platforma/static/js/wiki/save_dialog.js new file mode 100644 index 00000000..827b26b2 --- /dev/null +++ b/platforma/static/js/wiki/save_dialog.js @@ -0,0 +1,50 @@ +/* + * Dialog for saving document to the server + * + */ +(function($) { + + function SaveDialog(element) { + $.wiki.cls.GenericDialog.call(this, element); + this.ctx = $.wiki.exitContext(); + }; + + SaveDialog.prototype = new $.wiki.cls.GenericDialog(); + + SaveDialog.prototype + + SaveDialog.prototype.saveAction = function() { + var self = this; + + self.$elem.block({ + message: "Zapisywanie..." + }); + + try { + + CurrentDocument.save({ + comment: $("#komentarz").text(), + success: function(doc, changed, info){ + self.$elem.block({ + message: info, + timeout: 1000, + fadeOut: 0, + onUnblock: function() { + self.hide(); + } + }); + }, + failure: function(doc, info) { + self.reportErrors(info); + self.$elem.unblock(); + } + }); + } catch(e) { + console.log('Exception:', e) + self.$elem.unblock(); + } + }; /* end of save dialog */ + + /* make it global */ + $.wiki.cls.SaveDialog = SaveDialog; +})(jQuery); -- 2.20.1