Merge branch 'master' into view-refactor
[redakcja.git] / project / static / js / editor.ui.js
index 4d2a5d3..c8d47f6 100755 (executable)
  * UI related Editor methods\r
  */\r
 Editor.prototype.setupUI = function() {\r
  * UI related Editor methods\r
  */\r
 Editor.prototype.setupUI = function() {\r
-    // set up the UI visually and attach callbacks\r
+//     // set up the UI visually and attach callbacks\r
     var self = this;\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
-\r
-        if(old_width + delta < 12) delta = 12 - old_width;\r
-        if(old_width + delta > $(window).width()) \r
-            delta = $(window).width() - old_width;\r
-        \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
+//     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
+// \r
+//         if(old_width + delta < 12) delta = 12 - old_width;\r
+//         if(old_width + delta > $(window).width()) \r
+//             delta = $(window).width() - old_width;\r
+//         \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
     /*\r
      * Connect panel actions\r
      */\r
@@ -146,10 +146,14 @@ Editor.prototype.setupUI = function() {
      * Connect various buttons\r
      */\r
 \r
      * Connect various buttons\r
      */\r
 \r
-    $('#toolbar-button-save').click( function (event, data) {\r
+    $('#toolbar-button-quick-save').click( function (event, data) {\r
         self.saveToBranch();\r
     } );\r
 \r
         self.saveToBranch();\r
     } );\r
 \r
+    $('#toolbar-button-save').click( function (event, data) {\r
+        $('#commit-dialog').jqmShow( {callback: $.fbind(self, 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
     $('#toolbar-button-update').click( function (event, data) {\r
         if (self.updateUserBranch()) {\r
             // commit/update can be called only after proper, save\r
@@ -163,29 +167,18 @@ Editor.prototype.setupUI = function() {
     $('#commit-dialog').\r
     jqm({\r
         modal: true,\r
     $('#commit-dialog').\r
     jqm({\r
         modal: true,\r
-        onShow: $.fbind(self, self.loadRelatedIssues),\r
-        trigger: '#toolbar-button-commit'\r
+        onShow: $.fbind(self, self.loadRelatedIssues)        \r
     });\r
     });\r
+\r
+    $('#toolbar-button-commit').click( function (event, data) {\r
+        $('#commit-dialog').jqmShow( {callback: $.fbind(self, self.sendMergeRequest)} );\r
+    } );\r
     \r
     /* STATIC BINDS */\r
     $('#commit-dialog-cancel-button').click(function() {\r
         $('#commit-dialog-error-empty-message').hide();\r
         $('#commit-dialog').jqmHide();\r
     \r
     /* STATIC BINDS */\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
     \r
 \r
     /* SPLIT DIALOG */\r
     \r
 \r
     /* SPLIT DIALOG */\r
@@ -194,8 +187,6 @@ Editor.prototype.setupUI = function() {
         onShow: $.fbind(self, self.loadSplitDialog)\r
     }).\r
     jqmAddClose('button.dialog-close-button');\r
         onShow: $.fbind(self, self.loadSplitDialog)\r
     }).\r
     jqmAddClose('button.dialog-close-button');\r
-\r
-// $('#split-dialog').   \r
 }\r
 \r
 Editor.prototype.loadRelatedIssues = function(hash)\r
 }\r
 \r
 Editor.prototype.loadRelatedIssues = function(hash)\r
@@ -203,6 +194,25 @@ Editor.prototype.loadRelatedIssues = function(hash)
     var self = this;\r
     var c = $('#commit-dialog-related-issues');\r
 \r
     var self = this;\r
     var c = $('#commit-dialog-related-issues');\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
+\r
+            var message = $('#commit-dialog-message').val();\r
+            $('#commit-dialog-related-issues input:checked').\r
+                each(function() { message += ' refs #' + $(this).val(); });\r
+            $.log("COMMIT APROVED", hash.t);\r
+            hash.t.callback(message);\r
+        }\r
+\r
+        return false;\r
+    });\r
+\r
     $("div.loading-box", c).show();\r
     $("div.fatal-error-box", c).hide();\r
     $("div.container-box", c).hide();\r
     $("div.loading-box", c).show();\r
     $("div.fatal-error-box", c).hide();\r
     $("div.container-box", c).hide();\r
@@ -265,7 +275,7 @@ Editor.prototype.loadSplitDialog = function(hash)
             hash.t.success();\r
         });\r
 \r
             hash.t.success();\r
         });\r
 \r
-        if($('#id_splitform-autoxml').is(':checked'))\r
+        /* if($('#id_splitform-autoxml').is(':checked'))\r
             $('#split-form-dc-subform').show();\r
         else\r
             $('#split-form-dc-subform').hide();\r
             $('#split-form-dc-subform').show();\r
         else\r
             $('#split-form-dc-subform').hide();\r
@@ -275,7 +285,7 @@ Editor.prototype.loadSplitDialog = function(hash)
                 $('#split-form-dc-subform').show();\r
             else\r
                 $('#split-form-dc-subform').hide();\r
                 $('#split-form-dc-subform').show();\r
             else\r
                 $('#split-form-dc-subform').hide();\r
-        });\r
+        }); */\r
     };   \r
 \r
     $.ajax({\r
     };   \r
 \r
     $.ajax({\r
@@ -301,9 +311,8 @@ Editor.prototype.refreshPanels = function() {
             panel.refresh();\r
     });\r
 \r
             panel.refresh();\r
     });\r
 \r
-    $('#toolbar-button-save').attr('disabled', 'disabled');\r
-    $('#toolbar-button-commit').removeAttr('disabled');\r
-    $('#toolbar-button-update').removeAttr('disabled');\r
+    $('button.provides-save').attr('disabled', 'disabled');\r
+    $('button.requires-save').removeAttr('disabled');\r
 };\r
 \r
 /*\r
 };\r
 \r
 /*\r