1 function Panel(panelWrap) {
4 self.contentDiv = $('.panel-content', panelWrap);
5 self.instanceId = Math.ceil(Math.random() * 1000000000);
6 $.log('new panel - wrap: ', self.wrap);
9 $(document).bind('panel:unload.' + self.instanceId,
10 function(event, data) { self.unload(event, data); });
12 $(document).bind('panel:contentChanged', function(event, data) {
13 $.log(self, ' got changed event from: ', data);
15 self.otherPanelChanged(event.target);
24 Panel.prototype.callHook = function(hookName) {
25 if(this.hooks && this.hooks[hookName])
28 $.log('calling hook: ', hookName, 'with args: ', arguments);
29 this.hooks[hookName].apply(this, arguments);
33 Panel.prototype.load = function (url) {
34 $.log('preparing xhr load: ', this.wrap);
35 $(document).trigger('panel:unload', this);
41 success: function(data, tstat) {
43 $(self.contentDiv).html(data);
44 self.hooks = panel_hooks;
46 self.callHook('load');
48 error: function(request, textStatus, errorThrown) {
49 $.log('ajax', url, this.target, 'error:', textStatus, errorThrown);
54 Panel.prototype.unload = function(event, data) {
55 $.log('got unload signal', this, ' target: ', data);
58 $.log('unloading', this);
59 $(document).unbind('panel:unload.' + this.instanceId);
60 $(this.contentDiv).html('');
61 this.callHook('unload');
62 this.hooks = null; // flush the hooks
67 Panel.prototype.otherPanelChanged = function(other) {
68 $.log('panel ', other, ' changed.');
69 $('.change-notification', this.wrap).fadeIn();
70 this.callHook('dirty');
73 Panel.prototype.changed = function () {
74 this.wrap.addClass('changed');
77 Panel.prototype.saveInfo = function() {
79 this.callHook('saveInfo', saveInfo);
85 // editor initialization
86 // this is probably a good place to set config
89 Editor.prototype.setupUI = function() {
90 // set up the UI visually and attach callbacks
92 var panelRoot = $('#panels');
94 panelRoot.makeHorizPanel({}); // TODO: this probably doesn't belong into jQuery
95 panelRoot.css('top', ($('#header').outerHeight() ) + 'px');
97 $('#panels > *.panel-wrap').each(function() {
98 var panelWrap = $(this);
99 $.log('wrap: ', panelWrap);
100 panelWrap.data('ctrl', new Panel(panelWrap)); // attach controllers to wraps
102 $('.panel-toolbar select', panelWrap).change(function() {
103 panelWrap.data('ctrl').load( $(this).val() );
107 $('#toolbar-button-save').click( function (event, data) { self.saveToBranch(); } );
112 Editor.prototype.loadConfig = function() {
113 // load options from cookie
116 Editor.prototype.saveToBranch = function() {
117 var changed_panel = $('.panel-wrap.changed');
118 $.log('Saving to local branch - panel:', changed_panel);
120 if( changed_panel.length == 0) {
121 $.log('Nothing to save.');
122 return; /* no changes */
125 if( changed_panel.length > 1) {
126 alert('Błąd: więcej niż jeden panel został zmodyfikowany. Nie można zapisać.');
130 saveInfo = changed_panel.data('ctrl').saveInfo();
133 url: location.href + (saveInfo.part || ''),
134 dataType: (saveInfo.dataType || 'text'),
135 success: function(data, textStatus) {
136 $.log('Success:', data);
138 error: function(rq, tstat, err) {
139 $.log('save error', rq, tstat, err);
142 data: (saveInfo.content || '')
147 editor = new Editor();