this.character = String.fromCharCode(code & 0xff)
}
-
Hotkey.prototype.toString = function() {
mods = []
if(this.has_alt) mods.push('Alt')
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) {
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)
}
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;
}
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
}
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();
}
// 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
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() {
// connect hotkey
if(hk) {
self.hotkeys[hk.code] = callback;
- $.log('hotkey', hk);
+ // $.log('hotkey', hk);
}
// tooltip
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.rootcDiv.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();
- self.savePanelOptions();
- panelWrap.data('ctrl').load(url);
- });
-
- $('.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 = {
totalWidth += panelWidth;
}
$.log('panel:', this, $(this).css('left'));
- $('.panel-toolbar select', this).val(
- $('.panel-toolbar option[name=' + self.options.panels[index].name + ']', this).attr('value')
- )
+ $('.panel-toolbar option', this).each(function() {
+ if ($(this).attr('p:panel-name') == self.options.panels[index].name) {
+ $(this).parent('select').val($(this).attr('value'));
+ }
+ });
});
}
var panels = [];
$('.panel-wrap', self.rootDiv).not('.panel-content-overlay').each(function() {
panels.push({
- name: $('.panel-toolbar option:selected', this).attr('name'),
+ name: $('.panel-toolbar option:selected', this).attr('p:panel-name'),
ratio: $(this).width() / self.rootDiv.width()
})
});
}, 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.");
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;
-
- /* this.showPopup('not-implemented'); */
-
- $.log('URL !: ', $('#toolbar-commit-form').attr('action'));
+ $.log('URL !: ', $('#commit-dialog form').attr('action'));
$.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.registerScriptlet = function(scriptlet_id, scriptlet_func)
{
// I briefly assume, that it's verified not to break the world on SS
--- /dev/null
- \r
+/*\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'> </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
{% 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.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.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/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 %}
{% 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>
<p><label>{{n|capfirst}} panel:
<select name="select-{{n}}-panel" id="panel-{{n}}-select">
{% for panel_type in availble_panels %}
- <option value="{% url panel_view path=fileid,name=panel_type.id %}">{{panel_type.display_name}}</option>
+ <option value="{% url panel_view path=fileid,name=panel_type.id %}" p:panel-name="{{ panel_type.id }}">{{panel_type.display_name}}</option>
{% endfor %}
</select>
</label>
</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 %}