X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/f31bb368a2cad9a61e4fc652fa4b40c4114a128c..07539e8aca073150d034525fb67183a57a388286:/project/static/js/editor.ui.js?ds=sidebyside diff --git a/project/static/js/editor.ui.js b/project/static/js/editor.ui.js index 59c3f754..c8d47f66 100755 --- a/project/static/js/editor.ui.js +++ b/project/static/js/editor.ui.js @@ -2,111 +2,116 @@ * UI related Editor methods */ Editor.prototype.setupUI = function() { - // set up the UI visually and attach callbacks +// // set up the UI visually and attach callbacks var self = this; - - var resize_start = function(event, mydata) { - $(document).bind('mousemove', mydata, resize_changed). - bind('mouseup', mydata, resize_stop); - - $('.panel-overlay', mydata.root).css('display', 'block'); - return false; - } - var resize_changed = function(event) { - var old_width = parseInt(event.data.overlay.css('width')); - var delta = event.pageX + event.data.hotspot_x - old_width; - event.data.overlay.css({ - 'width': old_width + delta - }); - - if(event.data.overlay.next) { - var left = parseInt(event.data.overlay.next.css('left')); - event.data.overlay.next.css('left', left+delta); - } - - return false; - }; - - var resize_stop = function(event) { - $(document).unbind('mousemove', resize_changed).unbind('mouseup', resize_stop); - // $('.panel-content', event.data.root).css('display', 'block'); - var overlays = $('.panel-content-overlay', event.data.root); - $('.panel-content-overlay', event.data.root).each(function(i) { - if( $(this).data('panel').hasClass('last-panel') ) - $(this).data('panel').css({ - 'left': $(this).css('left'), - 'right': $(this).css('right') - }); - else - $(this).data('panel').css({ - 'left': $(this).css('left'), - 'width': $(this).css('width') - }); - }); - $('.panel-overlay', event.data.root).css('display', 'none'); - $(event.data.root).trigger('stopResize'); - }; - - /* - * Prepare panels (overlays & stuff) - */ - /* create an overlay */ - var panel_root = self.rootDiv; - var overlay_root = $("
"); - panel_root.append(overlay_root); - - var prev = null; - - $('*.panel-wrap', panel_root).each( function() - { - var panel = $(this); - var handle = $('.panel-slider', panel); - var overlay = $("
 
"); - overlay_root.append(overlay); - overlay.data('panel', panel); - overlay.data('next', null); - - if (prev) prev.next = overlay; - - if( panel.hasClass('last-panel') ) - { - overlay.css({ - 'left': panel.css('left'), - 'right': panel.css('right') - }); - } - else { - overlay.css({ - 'left': panel.css('left'), - 'width': panel.css('width') - }); - // $.log('Has handle: ' + panel.attr('id')); - overlay.append(handle.clone()); - /* attach the trigger */ - handle.mousedown(function(event) { - var touch_data = { - root: panel_root, - overlay: overlay, - hotspot_x: event.pageX - handle.position().left - }; - - $(this).trigger('hpanel:panel-resize-start', touch_data); - return false; - }); - $('.panel-content', panel).css('right', - (handle.outerWidth() || 10) + 'px'); - $('.panel-content-overlay', panel).css('right', - (handle.outerWidth() || 10) + 'px'); - }; - - prev = overlay; - }); - - panel_root.bind('hpanel:panel-resize-start', resize_start); - self.rootDiv.bind('stopResize', function() { - self.savePanelOptions() - }); - +// +// var resize_start = function(event, mydata) { +// $(document).bind('mousemove', mydata, resize_changed). +// bind('mouseup', mydata, resize_stop); +// +// $('.panel-overlay', mydata.root).css('display', 'block'); +// return false; +// } +// var resize_changed = function(event) { +// var old_width = parseInt(event.data.overlay.css('width')); +// var delta = event.pageX + event.data.hotspot_x - old_width; +// +// if(old_width + delta < 12) delta = 12 - old_width; +// if(old_width + delta > $(window).width()) +// delta = $(window).width() - old_width; +// +// event.data.overlay.css({ +// 'width': old_width + delta +// }); +// +// if(event.data.overlay.next) { +// var left = parseInt(event.data.overlay.next.css('left')); +// event.data.overlay.next.css('left', left+delta); +// } +// +// return false; +// }; +// +// var resize_stop = function(event) { +// $(document).unbind('mousemove', resize_changed).unbind('mouseup', resize_stop); +// // $('.panel-content', event.data.root).css('display', 'block'); +// var overlays = $('.panel-content-overlay', event.data.root); +// $('.panel-content-overlay', event.data.root).each(function(i) { +// if( $(this).data('panel').hasClass('last-panel') ) +// $(this).data('panel').css({ +// 'left': $(this).css('left'), +// 'right': $(this).css('right') +// }); +// else +// $(this).data('panel').css({ +// 'left': $(this).css('left'), +// 'width': $(this).css('width') +// }); +// }); +// $('.panel-overlay', event.data.root).css('display', 'none'); +// $(event.data.root).trigger('stopResize'); +// }; +// +// /* +// * Prepare panels (overlays & stuff) +// */ +// /* create an overlay */ +// var panel_root = self.rootDiv; +// var overlay_root = $("
"); +// panel_root.append(overlay_root); +// +// var prev = null; +// +// $('*.panel-wrap', panel_root).each( function() +// { +// var panel = $(this); +// var handle = $('.panel-slider', panel); +// var overlay = $("
 
"); +// overlay_root.append(overlay); +// overlay.data('panel', panel); +// overlay.data('next', null); +// +// if (prev) prev.next = overlay; +// +// if( panel.hasClass('last-panel') ) +// { +// overlay.css({ +// 'left': panel.css('left'), +// 'right': panel.css('right') +// }); +// } +// else { +// overlay.css({ +// 'left': panel.css('left'), +// 'width': panel.css('width') +// }); +// // $.log('Has handle: ' + panel.attr('id')); +// overlay.append(handle.clone()); +// /* attach the trigger */ +// handle.mousedown(function(event) { +// var touch_data = { +// root: panel_root, +// overlay: overlay, +// hotspot_x: event.pageX - handle.position().left +// }; +// +// $(this).trigger('hpanel:panel-resize-start', touch_data); +// return false; +// }); +// $('.panel-content', panel).css('right', +// (handle.outerWidth() || 10) + 'px'); +// $('.panel-content-overlay', panel).css('right', +// (handle.outerWidth() || 10) + 'px'); +// }; +// +// prev = overlay; +// }); +// +// panel_root.bind('hpanel:panel-resize-start', resize_start); +// self.rootDiv.bind('stopResize', function() { +// self.savePanelOptions(); +// }); +// /* * Connect panel actions */ @@ -127,20 +132,28 @@ Editor.prototype.setupUI = function() { function() { panel.refresh(); } ); + + self.rootDiv.bind('stopResize', function() { + panel.callHook('toolbarResized'); + }); }); $(document).bind('panel:contentChanged', function() { self.onContentChanged.apply(self, arguments) - }); + }); /* * Connect various buttons */ - $('#toolbar-button-save').click( function (event, data) { + $('#toolbar-button-quick-save').click( function (event, data) { self.saveToBranch(); } ); + $('#toolbar-button-save').click( function (event, data) { + $('#commit-dialog').jqmShow( {callback: $.fbind(self, self.saveToBranch)} ); + } ); + $('#toolbar-button-update').click( function (event, data) { if (self.updateUserBranch()) { // commit/update can be called only after proper, save @@ -154,15 +167,34 @@ Editor.prototype.setupUI = function() { $('#commit-dialog'). jqm({ modal: true, - trigger: '#toolbar-button-commit' + onShow: $.fbind(self, self.loadRelatedIssues) }); + $('#toolbar-button-commit').click( function (event, data) { + $('#commit-dialog').jqmShow( {callback: $.fbind(self, self.sendMergeRequest)} ); + } ); + + /* STATIC BINDS */ $('#commit-dialog-cancel-button').click(function() { $('#commit-dialog-error-empty-message').hide(); $('#commit-dialog').jqmHide(); - }); + }); + + + /* SPLIT DIALOG */ + $('#split-dialog').jqm({ + modal: true, + onShow: $.fbind(self, self.loadSplitDialog) + }). + jqmAddClose('button.dialog-close-button'); +} + +Editor.prototype.loadRelatedIssues = function(hash) +{ + var self = this; + var c = $('#commit-dialog-related-issues'); - $('#commit-dialog-save-button').click( function (event, data) + $('#commit-dialog-save-button').click( function (event, data) { if( $('#commit-dialog-message').val().match(/^\s*$/)) { $('#commit-dialog-error-empty-message').fadeIn(); @@ -170,20 +202,35 @@ Editor.prototype.setupUI = function() { else { $('#commit-dialog-error-empty-message').hide(); $('#commit-dialog').jqmHide(); - self.sendMergeRequest($('#commit-dialog-message').val() ); - } - - return false; - }); - /* SPLIT DIALOG */ - $('#split-dialog').jqm({ - modal: true, - onShow: $.fbind(self, self.loadSplitDialog) - }). - jqmAddClose('button.dialog-close-button'); + var message = $('#commit-dialog-message').val(); + $('#commit-dialog-related-issues input:checked'). + each(function() { message += ' refs #' + $(this).val(); }); + $.log("COMMIT APROVED", hash.t); + hash.t.callback(message); + } -// $('#split-dialog'). + return false; + }); + + $("div.loading-box", c).show(); + $("div.fatal-error-box", c).hide(); + $("div.container-box", c).hide(); + + $.getJSON( c.attr('ui:ajax-src') + '?callback=?', + function(data, status) + { + var fmt = ''; + $(data).each( function() { + fmt += '\n' + }); + $("div.container-box", c).html(fmt); + $("div.loading-box", c).hide(); + $("div.container-box", c).show(); + }); + + hash.w.show(); } Editor.prototype.loadSplitDialog = function(hash) @@ -206,8 +253,8 @@ Editor.prototype.loadSplitDialog = function(hash) // put the form into the window $('div.container-box', hash.w).html(data); $("div.loading-box", hash.w).hide(); - $('form input[name=splittext]', hash.w).val(hash.t.selection); - $('form input[name=fulltext]', hash.w).val(hash.t.fulltext); + $('form input[name=splitform-splittext]', hash.w).val(hash.t.selection); + $('form input[name=splitform-fulltext]', hash.w).val(hash.t.fulltext); $('div.container-box', hash.w).show(); // connect buttons @@ -225,7 +272,20 @@ Editor.prototype.loadSplitDialog = function(hash) $('#split-dialog-button-dismiss').click(function() { hash.w.jqmHide(); $('div.container-box', hash.w).html(''); + hash.t.success(); }); + + /* if($('#id_splitform-autoxml').is(':checked')) + $('#split-form-dc-subform').show(); + else + $('#split-form-dc-subform').hide(); + + $('#id_splitform-autoxml').change(function() { + if( $(this).is(':checked') ) + $('#split-form-dc-subform').show(); + else + $('#split-form-dc-subform').hide(); + }); */ }; $.ajax({ @@ -250,8 +310,10 @@ Editor.prototype.refreshPanels = function() { else panel.refresh(); }); -}; + $('button.provides-save').attr('disabled', 'disabled'); + $('button.requires-save').removeAttr('disabled'); +}; /* * Pop-up messages