* Plugin jQuery.modal
authorŁukasz Rekucki <lrekucki@gmail.com>
Thu, 10 Sep 2009 14:56:48 +0000 (16:56 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Thu, 10 Sep 2009 14:56:48 +0000 (16:56 +0200)
* UI do wycinania kawalkow tekstu z edytora XML jako oddzielne utwory. refs #98.
* zmiana formularza "Merge" refs #96.

12 files changed:
apps/explorer/forms.py
apps/explorer/views.py
project/static/css/jquery.modal.css [new file with mode: 0755]
project/static/css/master.css
project/static/js/editor.js
project/static/js/editor.ui.js [new file with mode: 0755]
project/static/js/jquery.modal.js [new file with mode: 0755]
project/templates/explorer/editor.html
project/templates/explorer/panels/dceditor.html
project/templates/explorer/split.html [new file with mode: 0755]
project/templates/explorer/split_success.html [new file with mode: 0755]
project/urls.py

index e453f1f..9541cb0 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 from django import forms
 
 from lxml import etree
 from django import forms
 
 from lxml import etree
@@ -71,6 +72,11 @@ class ImageFoldersForm(forms.Form):
         super(ImageFoldersForm, self).__init__(*args, **kwargs)
         self.fields['folders'].choices = [('', '-- Wybierz folder z obrazkami --')] + [(fn, fn) for fn in models.get_image_folders()]
 
         super(ImageFoldersForm, self).__init__(*args, **kwargs)
         self.fields['folders'].choices = [('', '-- Wybierz folder z obrazkami --')] + [(fn, fn) for fn in models.get_image_folders()]
 
+class SplitForm(forms.Form):
+    partname = forms.RegexField(regex='[0-9\w-]+',  \
+        label='Part name', help_text='Example: rozdział-2')
+    autoxml = forms.BooleanField(required=False, initial=False, label=u"Generate DublinCore")
+
 class DublinCoreForm(forms.Form):
     about = forms.URLField(verify_exists=False)
     author = PersonField()
 class DublinCoreForm(forms.Form):
     about = forms.URLField(verify_exists=False)
     author = PersonField()
index 7f99b66..2930d98 100644 (file)
@@ -424,7 +424,9 @@ class panel_view(object):
             'fileid': path, 'exception_type': type(e).__name__, 'exception': e,
             'panel_name': panel.display_name})
 
             'fileid': path, 'exception_type': type(e).__name__, 'exception': e,
             'panel_name': panel.display_name})
 
-
+##
+## Editor "commands" and "dialogs"
+##
 @login_required
 @with_repo
 def print_html(request, path, repo):
 @login_required
 @with_repo
 def print_html(request, path, repo):
@@ -439,6 +441,41 @@ def print_xml(request, path, repo):
     user_branch = file_branch(path, request.user)
     return HttpResponse( repo.get_file(path, user_branch), mimetype="text/plain; charset=utf-8")
 
     user_branch = file_branch(path, request.user)
     return HttpResponse( repo.get_file(path, user_branch), mimetype="text/plain; charset=utf-8")
 
+@login_required # WARNING: we don't wont a login form inside a window
+@with_repo
+def split_text(request, path, repo):
+    user_branch = file_branch(path, request.user)
+    valid = False
+    
+    if request.method == "POST":
+        sform = forms.SplitForm(request.POST, prefix='splitform')
+        dcform = forms.SplitForm(request.POST, prefix='dcform')
+
+        print "validating sform"
+        if sform.is_valid():
+            valid = True
+            if sform.cleaned_data['autoxml']:
+                print "validating dcform"                
+                valid = dcform.is_valid()        
+
+        print "valid is ", valid
+        if valid:
+            uri = path + '$' + sform.cleaned_data['partname']
+            # do something
+            return HttpResponseRedirect( reverse('split-success',\
+                kwargs={'path': path})+'?child='+uri)
+    else:
+        sform = forms.SplitForm(prefix='splitform')
+        dcform = forms.DublinCoreForm(prefix='dcform')
+    
+    return direct_to_template(request, 'explorer/split.html', extra_context={
+        'splitform': sform, 'dcform': dcform, 'fileid': path} )
+
+def split_success(request, path):
+    return direct_to_template(request, 'explorer/split_success.html',\
+        extra_context={'fileid': path, 'cfileid': request.GET['child']} )
+
+
 # =================
 # = Utility views =
 # =================
 # =================
 # = Utility views =
 # =================
diff --git a/project/static/css/jquery.modal.css b/project/static/css/jquery.modal.css
new file mode 100755 (executable)
index 0000000..4717ad4
--- /dev/null
@@ -0,0 +1,28 @@
+/* jqModal base Styling courtesy of;\r
+       Brice Burgess <bhb@iceburg.net> */\r
+\r
+/* The Window's CSS z-index value is respected (takes priority). If none is supplied,\r
+       the Window's z-index value will be set to 3000 by default (via jqModal.js). */\r
+       \r
+.jqmWindow {\r
+    display: none;\r
+    \r
+    position: absolute;\r
+    top: 40px;\r
+    left: 25%;\r
+    bottom: auto;\r
+    height: auto;\r
+    width: auto;\r
+\r
+    max-width: 80%;\r
+    max-height: 80%;\r
+\r
+    overflow: auto;\r
+    \r
+    background-color: #EEE;\r
+    color: #333;\r
+    border: 1px solid black;\r
+    padding: 1em;\r
+}\r
+\r
+.jqmOverlay { background-color: #000; }\r
index 33a9f68..de79989 100644 (file)
@@ -190,7 +190,6 @@ label {
     height: 26px;
 }
 
     height: 26px;
 }
 
-
 .panel-toolbar .toolbar-button-groups-container .panel-toolbar-extra button {
     /* this is uber specific */
     font-size: 12px;
 .panel-toolbar .toolbar-button-groups-container .panel-toolbar-extra button {
     /* this is uber specific */
     font-size: 12px;
@@ -323,3 +322,23 @@ div.isection p {
     background-color: yellow;
     border-color: yellow;   
 }
     background-color: yellow;
     border-color: yellow;   
 }
+
+/* Commit dialog */
+#commit-dialog-error-empty-message {
+    color: red;
+    display: none;
+    font-weight: bold;
+}
+
+text#commit-dialog-message {
+    width: 80%;
+    margin: auto;
+}
+
+#split-dialog .container-box form {
+    margin: 0.2em 1em;
+}
+
+#split-dialog .container-box fieldset {
+    margin: 0.5em;
+}
\ No newline at end of file
index ac34ac5..36dfcf2 100644 (file)
@@ -6,7 +6,6 @@ function Hotkey(code) {
     this.character = String.fromCharCode(code & 0xff)
 }
 
     this.character = String.fromCharCode(code & 0xff)
 }
 
-
 Hotkey.prototype.toString = function() {
     mods = []
     if(this.has_alt) mods.push('Alt')
 Hotkey.prototype.toString = function() {
     mods = []
     if(this.has_alt) mods.push('Alt')
@@ -22,7 +21,7 @@ function Panel(panelWrap) {
     self.wrap = panelWrap;
     self.contentDiv = $('.panel-content', panelWrap);
     self.instanceId = Math.ceil(Math.random() * 1000000000);
     self.wrap = panelWrap;
     self.contentDiv = $('.panel-content', panelWrap);
     self.instanceId = Math.ceil(Math.random() * 1000000000);
-    $.log('new panel - wrap: ', self.wrap);
+    // $.log('new panel - wrap: ', self.wrap);
        
     $(document).bind('panel:unload.' + self.instanceId,
         function(event, data) {
        
     $(document).bind('panel:unload.' + self.instanceId,
         function(event, data) {
@@ -46,7 +45,7 @@ Panel.prototype.callHook = function() {
     var noHookAction = args.splice(0,1)[0]
     var result = false;
 
     var noHookAction = args.splice(0,1)[0]
     var result = false;
 
-    $.log('calling hook: ', hookName, 'with args: ', args);
+    // $.log('calling hook: ', hookName, 'with args: ', args);
     if(this.hooks && this.hooks[hookName])
         result = this.hooks[hookName].apply(this, args);
     else if (noHookAction instanceof Function)
     if(this.hooks && this.hooks[hookName])
         result = this.hooks[hookName].apply(this, args);
     else if (noHookAction instanceof Function)
@@ -55,7 +54,7 @@ Panel.prototype.callHook = function() {
 }
 
 Panel.prototype.load = function (url) {
 }
 
 Panel.prototype.load = function (url) {
-    $.log('preparing xhr load: ', this.wrap);
+    // $.log('preparing xhr load: ', this.wrap);
     $(document).trigger('panel:unload', this);
     var self = this;
     self.current_url = url;
     $(document).trigger('panel:unload', this);
     var self = this;
     self.current_url = url;
@@ -80,10 +79,8 @@ Panel.prototype.load = function (url) {
 }
 
 Panel.prototype.unload = function(event, data) {
 }
 
 Panel.prototype.unload = function(event, data) {
-    $.log('got unload signal', this, ' target: ', data);
-
-    if( data == this ) {
-        $.log('unloading', this);
+    // $.log('got unload signal', this, ' target: ', data);
+    if( data == this ) {        
         $(this.contentDiv).html('');
 
         // disconnect the toolbar
         $(this.contentDiv).html('');
 
         // disconnect the toolbar
@@ -108,7 +105,7 @@ Panel.prototype.refresh = function(event, data) {
 } 
 
 Panel.prototype.otherPanelChanged = function(other) {
 } 
 
 Panel.prototype.otherPanelChanged = function(other) {
-    $.log('panel ', other, ' changed.');
+    $.log('Panel ', this, ' is aware that ', other, ' changed.');
     if(!this.callHook('dirty'))
         $('.change-notification', this.wrap).fadeIn();
 }      
     if(!this.callHook('dirty'))
         $('.change-notification', this.wrap).fadeIn();
 }      
@@ -138,7 +135,7 @@ Panel.prototype.connectToolbar = function()
     
     // check if there is a one
     var toolbar = $("div.toolbar", this.contentDiv);
     
     // check if there is a one
     var toolbar = $("div.toolbar", this.contentDiv);
-    $.log('Connecting toolbar', toolbar);
+    // $.log('Connecting toolbar', toolbar);
     if(toolbar.length == 0) return;
 
     // move the extra
     if(toolbar.length == 0) return;
 
     // move the extra
@@ -188,9 +185,9 @@ Panel.prototype.connectToolbar = function()
         try {
             var params = $.evalJSON(button.attr('ui:action-params'));
         } catch(object) {
         try {
             var params = $.evalJSON(button.attr('ui:action-params'));
         } catch(object) {
-           $.log('JSON exception in ', button, ': ', object);
-           button.attr('disabled', 'disabled');
-           return;
+            $.log('JSON exception in ', button, ': ', object);
+            button.attr('disabled', 'disabled');
+            return;
         }
 
         var callback = function() {
         }
 
         var callback = function() {
@@ -203,7 +200,7 @@ Panel.prototype.connectToolbar = function()
         // connect hotkey
         if(hk) {
             self.hotkeys[hk.code] = callback;
         // connect hotkey
         if(hk) {
             self.hotkeys[hk.code] = callback;
-             $.log('hotkey', hk);
+        // $.log('hotkey', hk);
         }
         
         // tooltip
         }
         
         // tooltip
@@ -263,60 +260,6 @@ function Editor()
     this.scriplets = {};
 }
 
     this.scriplets = {};
 }
 
-Editor.prototype.setupUI = function() {
-    // set up the UI visually and attach callbacks
-    var self = this;
-   
-    self.rootDiv.makeHorizPanel({}); // TODO: this probably doesn't belong into jQuery
-    // self.rootDiv.css('top', ($('#header').outerHeight() ) + 'px');
-    
-    $('#panels > *.panel-wrap').each(function() {
-        var panelWrap = $(this);
-        $.log('wrap: ', panelWrap);
-        var panel = new Panel(panelWrap);
-        panelWrap.data('ctrl', panel); // attach controllers to wraps
-        panel.load($('.panel-toolbar select', panelWrap).val());
-        
-        $('.panel-toolbar select', panelWrap).change(function() {
-            var url = $(this).val();
-            panelWrap.data('ctrl').load(url);
-            self.savePanelOptions();
-        });
-
-        $('.panel-toolbar button.refresh-button', panelWrap).click(
-            function() { 
-                panel.refresh();
-            } );
-    });
-
-    $(document).bind('panel:contentChanged', function() {
-        self.onContentChanged.apply(self, arguments)
-    });
-    
-    $('#toolbar-button-save').click( function (event, data) { 
-        self.saveToBranch();
-    } );
-
-    $('#toolbar-button-update').click( function (event, data) {
-        if (self.updateUserBranch()) {
-            // commit/update can be called only after proper, save
-            // this means all panels are clean, and will get refreshed
-             // do this only, when there are any changes to local branch
-            self.refreshPanels();
-        }
-    } );
-
-    $('#toolbar-button-commit').click( function (event, data) { 
-        self.sendPullRequest();
-        event.preventDefault();
-        event.stopPropagation();
-        return false;
-    } );
-    self.rootDiv.bind('stopResize', function() { 
-        self.savePanelOptions()
-    });
-}
-
 Editor.prototype.loadConfig = function() {
     // Load options from cookie
     var defaultOptions = {
 Editor.prototype.loadConfig = function() {
     // Load options from cookie
     var defaultOptions = {
@@ -478,20 +421,6 @@ Editor.prototype.onContentChanged = function(event, data) {
     }, 300000 );
 };
 
     }, 300000 );
 };
 
-Editor.prototype.refreshPanels = function() {
-    var self = this;
-
-    self.allPanels().each(function() {
-        var panel = $(this).data('ctrl');
-        $.log('Refreshing: ', this, panel);
-        if ( panel.changed() )
-            panel.unmarkChanged();
-        else
-            panel.refresh();
-    });
-};             
-
-
 Editor.prototype.updateUserBranch = function() {
     if( $('.panel-wrap.changed').length != 0)
         alert("There are unsaved changes - can't update.");
 Editor.prototype.updateUserBranch = function() {
     if( $('.panel-wrap.changed').length != 0)
         alert("There are unsaved changes - can't update.");
@@ -499,108 +428,81 @@ Editor.prototype.updateUserBranch = function() {
     var self = this;
     $.ajax({
         url: $('#toolbar-button-update').attr('ui:ajax-action'),
     var self = this;
     $.ajax({
         url: $('#toolbar-button-update').attr('ui:ajax-action'),
-       dataType: 'json',
-       success: function(data, textStatus) {
-                switch(data.result) {
-                    case 'done':
-                        self.showPopup('generic-yes', 'Plik uaktualniony.');
-                        self.refreshPanels()
-                        break;
-                    case 'nothing-to-do':
-                        self.showPopup('generic-info', 'Brak zmian do uaktualnienia.');
-                        break;
-                    default:
-                        self.showPopup('generic-error', data.errors && data.errors[0]);
-                }
-       },
-       error: function(rq, tstat, err) {
-               self.showPopup('generic-error', 'Błąd serwera: ' + err);
-       },
-       type: 'POST',
-       data: {}
+        dataType: 'json',
+        success: function(data, textStatus) {
+            switch(data.result) {
+                case 'done':
+                    self.showPopup('generic-yes', 'Plik uaktualniony.');
+                    self.refreshPanels()
+                    break;
+                case 'nothing-to-do':
+                    self.showPopup('generic-info', 'Brak zmian do uaktualnienia.');
+                    break;
+                default:
+                    self.showPopup('generic-error', data.errors && data.errors[0]);
+            }
+        },
+        error: function(rq, tstat, err) {
+            self.showPopup('generic-error', 'Błąd serwera: ' + err);
+        },
+        type: 'POST',
+        data: {}
     });
 }
 
     });
 }
 
-Editor.prototype.sendPullRequest = function () {
+Editor.prototype.sendMergeRequest = function (message) {
     if( $('.panel-wrap.changed').length != 0)        
         alert("There are unsaved changes - can't commit.");
 
     var self =  this;
     if( $('.panel-wrap.changed').length != 0)        
         alert("There are unsaved changes - can't commit.");
 
     var self =  this;
-
-    /* this.showPopup('not-implemented'); */
-
-    $.log('URL !: ', $('#toolbar-commit-form').attr('action'));
+    $.log('URL !: ', $('#commit-dialog form').attr('action'));
     
     $.ajax({        
     
     $.ajax({        
-        url: $('#toolbar-commit-form').attr('action'),
-       dataType: 'json',
-       success: function(data, textStatus) {
-                switch(data.result) {
-                    case 'done':
-                        self.showPopup('generic-yes', 'Łączenie zmian powiodło się.');
-
-                        if(data.localmodified)
-                            self.refreshPanels()
+        url: $('#commit-dialog form').attr('action'),
+        dataType: 'json',
+        success: function(data, textStatus) {
+            switch(data.result) {
+                case 'done':
+                    self.showPopup('generic-yes', 'Łączenie zmian powiodło się.');
+
+                    if(data.localmodified)
+                        self.refreshPanels()
                         
                         
-                        break;
-                    case 'nothing-to-do':
-                        self.showPopup('generic-info', 'Brak zmian do połaczenia.');
-                        break;
-                    default:
-                        self.showPopup('generic-error', data.errors && data.errors[0]);
-                }
-       },
-       error: function(rq, tstat, err) {
-               self.showPopup('generic-error', 'Błąd serwera: ' + err);
-       },
-       type: 'POST',
-       data: {'message': $('#toolbar-commit-message').val() }
+                    break;
+                case 'nothing-to-do':
+                    self.showPopup('generic-info', 'Brak zmian do połaczenia.');
+                    break;
+                default:
+                    self.showPopup('generic-error', data.errors && data.errors[0]);
+            }
+        },
+        error: function(rq, tstat, err) {
+            self.showPopup('generic-error', 'Błąd serwera: ' + err);
+        },
+        type: 'POST',
+        data: {
+            'message': message
+        }
     }); 
 }
 
     }); 
 }
 
-Editor.prototype.showPopup = function(name, text, timeout)
+Editor.prototype.postSplitRequest = function(s, f)
 {
 {
-    timeout = timeout || 4000;
-    var self = this;
-    self.popupQueue.push( [name, text, timeout] )
-
-    if( self.popupQueue.length > 1) 
-        return;
-
-    var box = $('#message-box > #' + name);
-    $('*.data', box).html(text || '');
-    box.fadeIn(100);
-    if(timeout > 0)
-        setTimeout( $.fbind(self, self.advancePopupQueue), timeout);
+    $.ajax({
+        url: $('#split-dialog form').attr('action'),
+        dataType: 'html',
+        success: s,
+        error: f,
+        type: 'POST',
+        data: $('#split-dialog form').serialize()
+    });
 };
 
 };
 
-Editor.prototype.advancePopupQueue = function() {
-    var self = this;
-    var elem = this.popupQueue.shift();
-    if(elem) {
-        var box = $('#message-box > #' + elem[0]);
-
-        box.fadeOut(100, function()
-        {
-            $('*.data', box).html('');
-
-            if( self.popupQueue.length > 0) {
-                var ibox = $('#message-box > #' + self.popupQueue[0][0]);
-                $('*.data', ibox).html(self.popupQueue[0][1] || '');
-                ibox.fadeIn(100);
-                if(self.popupQueue[0][2] > 0)
-                    setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]);
-            }
-        });
-    }
-};
 
 Editor.prototype.allPanels = function() {
     return $('#' + this.rootDiv.attr('id') +' > *.panel-wrap', this.rootDiv.parent());
 }
 
 
 Editor.prototype.allPanels = function() {
     return $('#' + this.rootDiv.attr('id') +' > *.panel-wrap', this.rootDiv.parent());
 }
 
-
 Editor.prototype.registerScriptlet = function(scriptlet_id, scriptlet_func)
 {
     // I briefly assume, that it's verified not to break the world on SS
 Editor.prototype.registerScriptlet = function(scriptlet_id, scriptlet_func)
 {
     // I briefly assume, that it's verified not to break the world on SS
diff --git a/project/static/js/editor.ui.js b/project/static/js/editor.ui.js
new file mode 100755 (executable)
index 0000000..b27daac
--- /dev/null
@@ -0,0 +1,297 @@
+/*\r
+ * UI related Editor methods\r
+ */\r
+Editor.prototype.setupUI = function() {\r
+    // set up the UI visually and attach callbacks\r
+    var self = this;\r
+\r
+    var resize_start = function(event, mydata) {\r
+        $(document).bind('mousemove', mydata, resize_changed).\r
+        bind('mouseup', mydata, resize_stop);\r
+\r
+        $('.panel-overlay', mydata.root).css('display', 'block');\r
+        return false;\r
+    }\r
+    var resize_changed =  function(event) {\r
+        var old_width = parseInt(event.data.overlay.css('width'));\r
+        var delta = event.pageX + event.data.hotspot_x - old_width;\r
+        event.data.overlay.css({\r
+            'width': old_width + delta\r
+        });\r
+\r
+        if(event.data.overlay.next) {\r
+            var left = parseInt(event.data.overlay.next.css('left'));\r
+            event.data.overlay.next.css('left', left+delta);\r
+        }\r
+\r
+        return false;\r
+    };\r
+\r
+    var resize_stop = function(event) {\r
+        $(document).unbind('mousemove', resize_changed).unbind('mouseup', resize_stop);\r
+        // $('.panel-content', event.data.root).css('display', 'block');\r
+        var overlays = $('.panel-content-overlay', event.data.root);\r
+        $('.panel-content-overlay', event.data.root).each(function(i) {\r
+            if( $(this).data('panel').hasClass('last-panel') )\r
+                $(this).data('panel').css({\r
+                    'left': $(this).css('left'),\r
+                    'right': $(this).css('right')\r
+                });\r
+            else\r
+                $(this).data('panel').css({\r
+                    'left': $(this).css('left'),\r
+                    'width': $(this).css('width')\r
+                });\r
+        });\r
+        $('.panel-overlay', event.data.root).css('display', 'none');\r
+        $(event.data.root).trigger('stopResize');\r
+    };\r
+\r
+    /*\r
+     * Prepare panels (overlays & stuff)\r
+     */\r
+    /* create an overlay */\r
+    var panel_root = self.rootDiv;\r
+    var overlay_root = $("<div class='panel-overlay'></div>");\r
+    panel_root.append(overlay_root);\r
+\r
+    var prev = null;\r
+\r
+    $('*.panel-wrap', panel_root).each( function()\r
+    {\r
+        var panel = $(this);\r
+        var handle = $('.panel-slider', panel);\r
+        var overlay = $("<div class='panel-content-overlay panel-wrap'>&nbsp;</div>");\r
+        overlay_root.append(overlay);\r
+        overlay.data('panel', panel);\r
+        overlay.data('next', null);\r
+\r
+        if (prev) prev.next = overlay;\r
+\r
+        if( panel.hasClass('last-panel') )\r
+        {\r
+            overlay.css({\r
+                'left': panel.css('left'),\r
+                'right': panel.css('right')\r
+            });\r
+        }\r
+        else {\r
+            overlay.css({\r
+                'left': panel.css('left'),\r
+                'width': panel.css('width')\r
+            });\r
+            // $.log('Has handle: ' + panel.attr('id'));\r
+            overlay.append(handle.clone());\r
+            /* attach the trigger */\r
+            handle.mousedown(function(event) {\r
+                var touch_data = {\r
+                    root: panel_root,\r
+                    overlay: overlay,\r
+                    hotspot_x: event.pageX - handle.position().left\r
+                };\r
+\r
+                $(this).trigger('hpanel:panel-resize-start', touch_data);\r
+                return false;\r
+            });\r
+            $('.panel-content', panel).css('right',\r
+                (handle.outerWidth() || 10) + 'px');\r
+            $('.panel-content-overlay', panel).css('right',\r
+                (handle.outerWidth() || 10) + 'px');\r
+        };\r
+\r
+        prev = overlay;\r
+    });\r
+\r
+    panel_root.bind('hpanel:panel-resize-start', resize_start);\r
+    self.rootDiv.bind('stopResize', function() {\r
+        self.savePanelOptions()\r
+    });\r
+\r
+    /*\r
+     * Connect panel actions\r
+     */\r
+    $('#panels > *.panel-wrap').each(function() {\r
+        var panelWrap = $(this);\r
+        // $.log('wrap: ', panelWrap);\r
+        var panel = new Panel(panelWrap);\r
+        panelWrap.data('ctrl', panel); // attach controllers to wraps\r
+        panel.load($('.panel-toolbar select', panelWrap).val());\r
+\r
+        $('.panel-toolbar select', panelWrap).change(function() {\r
+            var url = $(this).val();\r
+            panelWrap.data('ctrl').load(url);\r
+            self.savePanelOptions();\r
+        });\r
+\r
+        $('.panel-toolbar button.refresh-button', panelWrap).click(\r
+            function() {\r
+                panel.refresh();\r
+            } );\r
+    });\r
+\r
+    $(document).bind('panel:contentChanged', function() {\r
+        self.onContentChanged.apply(self, arguments)\r
+    });\r
+\r
+    /*\r
+     * Connect various buttons\r
+     */\r
+\r
+    $('#toolbar-button-save').click( function (event, data) {\r
+        self.saveToBranch();\r
+    } );\r
+\r
+    $('#toolbar-button-update').click( function (event, data) {\r
+        if (self.updateUserBranch()) {\r
+            // commit/update can be called only after proper, save\r
+            // this means all panels are clean, and will get refreshed\r
+            // do this only, when there are any changes to local branch\r
+            self.refreshPanels();\r
+        }\r
+    } );\r
+\r
+    /* COMMIT DIALOG */\r
+    $('#commit-dialog').\r
+    jqm({\r
+        modal: true,\r
+        trigger: '#toolbar-button-commit'\r
+    });\r
+\r
+    $('#commit-dialog-cancel-button').click(function() {\r
+        $('#commit-dialog-error-empty-message').hide();\r
+        $('#commit-dialog').jqmHide();\r
+    });\r
+\r
+    $('#commit-dialog-save-button').click( function (event, data) \r
+    {\r
+        if( $('#commit-dialog-message').val().match(/^\s*$/)) {\r
+            $('#commit-dialog-error-empty-message').fadeIn();\r
+        }\r
+        else {\r
+            $('#commit-dialog-error-empty-message').hide();\r
+            $('#commit-dialog').jqmHide();\r
+            self.sendMergeRequest($('#commit-dialog-message').val() );\r
+        }       \r
+     \r
+        return false;\r
+    });    \r
+\r
+    /* SPLIT DIALOG */\r
+    $('#split-dialog').jqm({\r
+        modal: true,\r
+        onShow: $.fbind(self, self.loadSplitDialog)\r
+    }).\r
+    jqmAddClose('button.dialog-close-button');\r
+\r
+// $('#split-dialog').   \r
+}\r
+\r
+Editor.prototype.loadSplitDialog = function(hash)\r
+{\r
+    var self = this;    \r
+    \r
+    $("div.loading-box", hash.w).show();\r
+    $("div.fatal-error-box", hash.w).hide();\r
+    $('div.container-box', hash.w).hide();\r
+    hash.w.show();\r
+\r
+    function onFailure(rq, tstat, err) {\r
+        $('div.container-box', hash.w).html('');\r
+        $("div.loading-box", hash.w).hide();\r
+        $("div.fatal-error-box", hash.w).show();\r
+        hash.t.failure();\r
+    };\r
+\r
+    function onSuccess(data, status) {\r
+        // put the form into the window\r
+        $('div.container-box', hash.w).html(data);\r
+        $("div.loading-box", hash.w).hide();\r
+        $('form input[name=splittext]', hash.w).val(hash.t.selection);\r
+        $('form input[name=fulltext]', hash.w).val(hash.t.fulltext);\r
+        $('div.container-box', hash.w).show();\r
+\r
+        // connect buttons\r
+        $('#split-dialog-button-accept').click(function() {\r
+            self.postSplitRequest(onSuccess, onFailure);\r
+            return false;\r
+        });\r
+\r
+        $('#split-dialog-button-close').click(function() {\r
+            hash.w.jqmHide();\r
+            $('div.container-box', hash.w).html('');\r
+            hash.t.failure();\r
+        });\r
+\r
+        $('#split-dialog-button-dismiss').click(function() {\r
+            hash.w.jqmHide();\r
+            $('div.container-box', hash.w).html('');\r
+        });\r
+    };   \r
+\r
+    $.ajax({\r
+        url: 'split',\r
+        dataType: 'html',\r
+        success: onSuccess,\r
+        error: onFailure,\r
+        type: 'GET',\r
+        data: {}\r
+    });\r
+}\r
+\r
+/* Refreshing routine */\r
+Editor.prototype.refreshPanels = function() {\r
+    var self = this;\r
+\r
+    self.allPanels().each(function() {\r
+        var panel = $(this).data('ctrl');\r
+        $.log('Refreshing: ', this, panel);\r
+        if ( panel.changed() )\r
+            panel.unmarkChanged();\r
+        else\r
+            panel.refresh();\r
+    });\r
+};\r
+\r
+\r
+/*\r
+ * Pop-up messages\r
+ */\r
+Editor.prototype.showPopup = function(name, text, timeout)\r
+{\r
+    timeout = timeout || 4000;\r
+    var self = this;\r
+    self.popupQueue.push( [name, text, timeout] )\r
+\r
+    if( self.popupQueue.length > 1)\r
+        return;\r
+\r
+    var box = $('#message-box > #' + name);\r
+    $('*.data', box).html(text || '');\r
+    box.fadeIn(100);\r
+\r
+    if(timeout > 0)\r
+        setTimeout( $.fbind(self, self.advancePopupQueue), timeout);\r
+};\r
+\r
+Editor.prototype.advancePopupQueue = function() {\r
+    var self = this;\r
+    var elem = this.popupQueue.shift();\r
+    if(elem) {\r
+        var box = $('#message-box > #' + elem[0]);\r
+\r
+        box.fadeOut(100, function()\r
+        {\r
+            $('*.data', box).html('');\r
+\r
+            if( self.popupQueue.length > 0) {\r
+                var ibox = $('#message-box > #' + self.popupQueue[0][0]);\r
+                $('*.data', ibox).html(self.popupQueue[0][1] || '');\r
+                ibox.fadeIn(100);\r
+                if(self.popupQueue[0][2] > 0)\r
+                    setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]);\r
+            }\r
+        });\r
+    }\r
+};\r
+\r
+\r
diff --git a/project/static/js/jquery.modal.js b/project/static/js/jquery.modal.js
new file mode 100755 (executable)
index 0000000..3aac816
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * jqModal - Minimalist Modaling with jQuery
+ *   (http://dev.iceburg.net/jquery/jqModal/)
+ *
+ * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
+ * Dual licensed under the MIT and GPL licenses:
+ *   http://www.opensource.org/licenses/mit-license.php
+ *   http://www.gnu.org/licenses/gpl.html
+ * 
+ * $Version: 03/01/2009 +r14
+ */
+(function($) {
+$.fn.jqm=function(o){
+var p={
+overlay: 50,
+overlayClass: 'jqmOverlay',
+closeClass: 'jqmClose',
+trigger: '.jqModal',
+ajax: F,
+ajaxText: '',
+target: F,
+modal: F,
+toTop: F,
+onShow: F,
+onHide: F,
+onLoad: F
+};
+return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
+H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
+if(p.trigger)$(this).jqmAddTrigger(p.trigger);
+});};
+
+$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
+$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
+$.fn.jqmShow=function(t){return this.each(function(){t=t||window.event;$.jqm.open(this._jqm,t);});};
+$.fn.jqmHide=function(t){return this.each(function(){t=t||window.event;$.jqm.close(this._jqm,t)});};
+
+$.jqm = {
+hash:{},
+open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);
+ if(c.modal) {if(!A[0])L('bind');A.push(s);}
+ else if(c.overlay > 0)h.w.jqmAddClose(o);
+ else o=F;
+
+ h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
+ if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}
+
+ if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
+  r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
+ else if(cc)h.w.jqmAddClose($(cc,h.w));
+
+ if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);        
+ (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
+},
+close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
+ if(A[0]){A.pop();if(!A[0])L('unbind');}
+ if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
+ if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
+},
+params:{}};
+var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
+i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
+e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
+f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
+L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
+m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
+hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
+ if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};
+})(jQuery);
\ No newline at end of file
index 891366b..2263f02 100644 (file)
@@ -2,15 +2,17 @@
 
 {% block extrahead %}
     <link rel="stylesheet" href="{{STATIC_URL}}css/toolbar.css" type="text/css" />
 
 {% block extrahead %}
     <link rel="stylesheet" href="{{STATIC_URL}}css/toolbar.css" type="text/css" />
+    <link rel="stylesheet" href="{{STATIC_URL}}css/jquery.modal.css" type="text/css" />
     <script src="{{STATIC_URL}}js/jquery.lazyload.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/codemirror/codemirror.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/jquery.lazyload.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/codemirror/codemirror.js" type="text/javascript" charset="utf-8"></script>
-    <script src="{{STATIC_URL}}js/jquery.autoscroll.js" type="text/javascript" charset="utf-8"></script>
+    <!--<script src="{{STATIC_URL}}js/jquery.autoscroll.js" type="text/javascript" charset="utf-8"></script>-->
     <script src="{{STATIC_URL}}js/jquery.wtooltip.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/jquery.wtooltip.js" type="text/javascript" charset="utf-8"></script>
-    <script src="{{STATIC_URL}}js/jquery.hpanel.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/jquery.json.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/jquery.json.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
-    <script src="{{STATIC_URL}}js/editor.js" type="text/javascript" charset="utf-8"></script>
+    <script src="{{STATIC_URL}}js/jquery.modal.js" type="text/javascript" charset="utf-8"></script>
 
 
+    <script src="{{STATIC_URL}}js/editor.js" type="text/javascript" charset="utf-8"></script>
+    <script src="{{STATIC_URL}}js/editor.ui.js" type="text/javascript" charset="utf-8"></script>
 {% endblock extrahead %}
 
 {% block extrabody %}
 {% endblock extrahead %}
 
 {% block extrabody %}
 
 {% block header-toolbar %}
 
 
 {% block header-toolbar %}
 
-<form action="{% url file_commit fileid %}" method="POST" style="display: inline;" id="toolbar-commit-form">
-    <input type="text" size="40" id="toolbar-commit-message" name="message" />
-    <button type="submit" class="toolbar-button" id="toolbar-button-commit">Merge</button>
-</form>
+
+<button type="button" class="toolbar-button" id="toolbar-button-commit">Merge</button>
 <button type="button" class="toolbar-button" id="toolbar-button-update"
         ui:ajax-action="{% url file_update fileid %}">Update</button>
 <button type="button" class="toolbar-button" id="toolbar-button-save" disabled="disabled">Save</button>
 <button type="button" class="toolbar-button" id="toolbar-button-update"
         ui:ajax-action="{% url file_update fileid %}">Update</button>
 <button type="button" class="toolbar-button" id="toolbar-button-save" disabled="disabled">Save</button>
             </div>
             {% endfor %}
         </div>
             </div>
             {% endfor %}
         </div>
+        <div id="commit-dialog" class="jqmWindow">
+            <form action="{% url file_commit fileid %}" method="POST">
+                <label for="message">Commit message:</label>
+                <textarea cols="60" rows="15" name="message" id="commit-dialog-message"></textarea>
+                <p id="commit-dialog-error-empty-message">Wiadomość nie może być pusta.</p>
+                <p>
+                   <input type="submit" value="Save" id="commit-dialog-save-button" />
+                   <input type="reset" value="Cancel" id="commit-dialog-cancel-button" />
+                </p>
+            </form>
+        </div>
+
+        <div id="split-dialog" class="jqmWindow">
+            <div class="container-box"> </div>
+            <div class="loading-box" style="display: none;">
+                <p>Wczytuję zawartość okna...</p>
+                <!-- <p><button type="button" class="dialog-close-button">Close</button></p> -->
+            </div>
+            <div class="fatal-error-box" style="display: none;">
+                <p>Server error, while loading dialog :(</p>
+                <p><button type="button" class="dialog-close-button">Close</button></p>
+            </div>
+        </div>
 {% endblock maincontent %}    
 {% endblock maincontent %}    
index a09f9be..fd61369 100644 (file)
@@ -1,7 +1,7 @@
 <div class="panel-dceditor">
 <div class="panel-dceditor">
-    <form action="{{ request.get_full_path }}" method="post" accept-charset="utf-8">
+    <form action="{% url file_dc fileid %}" method="post" accept-charset="utf-8">
         {{ form.as_p }}
         {{ form.as_p }}
-<!--        <p><input type="submit" value="Continue &rarr;"/></p> -->
+<!--    <p><input type="submit" value="Continue &rarr;"/></p> -->
     </form>
 </div>
 <script type="text/javascript" charset="utf-8">
     </form>
 </div>
 <script type="text/javascript" charset="utf-8">
diff --git a/project/templates/explorer/split.html b/project/templates/explorer/split.html
new file mode 100755 (executable)
index 0000000..0fb9064
--- /dev/null
@@ -0,0 +1,27 @@
+<form action="{% url explorer.views.split_text fileid %}" method="POST">\r
+    <fieldset>\r
+        <legend>Split options</legend>\r
+        {% for field in splitform %}\r
+        {{ field.errors }}\r
+        {% ifequal field.html_name 'splitform-autoxml' %}\r
+        <p><label>{{ field }} {{ field.label }}</label></p>\r
+        {% else %}\r
+        <p><label>{{ field.label }}: {{ field }}</label></p>\r
+        {% endifequal %}\r
+\r
+        {% endfor %}\r
+\r
+    </fieldset>\r
+\r
+    <fieldset id="split-form-dc-subform" style="display: none;">\r
+    <legend>Dublin Core</legend>\r
+    {{ dcform.as_p }}\r
+    </fieldset>\r
+\r
+    <input type="hidden" name="splittext" />\r
+    <input type="hidden" name="fulltext" />\r
+    <p>\r
+        <button type="submit" id="split-dialog-button-accept">Split</button>\r
+        <button type="button" id="split-dialog-button-close">Close</button>\r
+    </p>\r
+</form>
\ No newline at end of file
diff --git a/project/templates/explorer/split_success.html b/project/templates/explorer/split_success.html
new file mode 100755 (executable)
index 0000000..69c19c3
--- /dev/null
@@ -0,0 +1,3 @@
+<p>Split successful. You can edit the new part here:\r
+<a href="{% url editor_view cfileid %}">{% url editor_view cfileid %}</a></p>\r
+<p><button type="button" id="split-dialog-button-dismiss">Close</button></p>
\ No newline at end of file
index ce2f6b5..b357688 100644 (file)
@@ -23,6 +23,10 @@ urlpatterns = patterns('',
     url(r'^editor/'+PATH_SEC+'/panel/(?P<name>[a-z]+)/$', 'explorer.views.panel_view', name='panel_view'),
     url(r'^editor/'+PATH_END, 'explorer.views.display_editor', name='editor_view'),
 
     url(r'^editor/'+PATH_SEC+'/panel/(?P<name>[a-z]+)/$', 'explorer.views.panel_view', name='panel_view'),
     url(r'^editor/'+PATH_END, 'explorer.views.display_editor', name='editor_view'),
 
+    url(r'^editor/'+PATH_SEC+'/split$', 'explorer.views.split_text'),
+    url(r'^editor/'+PATH_SEC+'/split-success',
+        'explorer.views.split_success', name='split-success'),
+
     url(r'^editor/'+PATH_SEC+'/print/html$', 'explorer.views.print_html'),
     url(r'^editor/'+PATH_SEC+'/print/xml$', 'explorer.views.print_xml'),
     
     url(r'^editor/'+PATH_SEC+'/print/html$', 'explorer.views.print_html'),
     url(r'^editor/'+PATH_SEC+'/print/xml$', 'explorer.views.print_xml'),