Skip to content

Commit

Permalink
Merge pull request Katello#271 from thomasmckay/panelpage
Browse files Browse the repository at this point in the history
panelpage - maintain which tab of panel was last visible
  • Loading branch information
knowncitizen committed Jul 2, 2012
2 parents 3d87775 + a8cef47 commit 9c19dce
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/app/views/common/_list_item.html.haml
@@ -1,5 +1,5 @@
- initial_action ||= :edit
.block{:id => "#{name}_#{item.send(accessor)}", "data-ajax_url" => url_for(:action=>initial_action, :id => item.send(accessor))}
- initial_action ||= :edit
.block{:id => "#{name}_#{item.send(accessor)}", "data-ajax_url" => "#{url_for(:controller=>controller.controller_name)}/#{item.send(accessor)}", "data-ajax_panelpage" => initial_action}
- for col in columns
.one-line-ellipsis{:class => 'column_' + columns.length.to_s, :title => item.send(col)}
= item.send(col)
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/system_groups/_list_group.html.haml
@@ -1,4 +1,4 @@
.block.tall{:id => "#{name}_#{item.send(accessor)}", "data-ajax_url" => url_for(:action=> :systems, :id => item.send(accessor))}
.block.tall{:id => "#{name}_#{item.send(accessor)}", "data-ajax_url" => "#{url_for(:controller=>controller.controller_name)}/#{item.send(accessor)}", "data-ajax_panelpage" => :systems}
%div{:class => "column_1"}
-if item.locked
%span{:class => "lock_icon fl"}
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/systems/_list_system.html.haml
@@ -1,3 +1,3 @@
.block.tall{:id => "#{name}_#{item.send(accessor)}", "data-ajax_url" => url_for(:action=> @panel_options[:initial_action], :id => item.send(accessor))}
.block.tall{:id => "#{name}_#{item.send(accessor)}", "data-ajax_url" => "#{url_for(:controller=>controller.controller_name)}/#{item.send(accessor)}", "data-ajax_panelpage" => @panel_options[:initial_action]}
= render :partial=>"systems/list_system_show", :locals=>{:item => item}

111 changes: 92 additions & 19 deletions src/public/javascripts/panel.js
Expand Up @@ -16,6 +16,10 @@ var subpanel = null;
var subpanelSpacing = 55;
var panelLeft = null;
var count = 0;

// Saves the state of the last subpanel viewed so selecting a new item from list will keep that subpanel open.
var last_ajax_panelpage;

$(document).ready(function () {
$('.left').resize(function () {
var apanel = $('.panel');
Expand Down Expand Up @@ -45,14 +49,29 @@ $(document).ready(function () {
var activeBlock = null;
var activeBlockId = null;
var ajax_url = null;
var panel_selected;

$('.block').live('click', function (event) {
var subpanel_href,
subpanel_name,
ajax_panelpage;

if (event.target.nodeName === "A" && event.target.className.match('content_add_remove')) {
return false;
} else {
activeBlock = $(this);
ajax_url = activeBlock.attr("data-ajax_url");
activeBlockId = activeBlock.attr('id');
ajax_panelpage = activeBlock.attr("data-ajax_panelpage");

// If the panel is currently open, get the currently open tab
if (thisPanel.hasClass('opened')) {
subpanel_href = $('.panel_link.selected > a').attr('href');
if (subpanel_href) {
last_ajax_panelpage = subpanel_href.substr(subpanel_href.lastIndexOf('/') + 1);
}
}

if(event.ctrlKey && !thisPanel.hasClass('opened') && !(event.target.id == "new") && !activeBlock.hasClass('active')) {
if (activeBlock.hasClass('active')) {
activeBlock.removeClass('active');
Expand All @@ -66,9 +85,19 @@ $(document).ready(function () {
if(activeBlock.hasClass('active') && thisPanel.hasClass('opened')){
KT.panel.closePanel(thisPanel);
} else {
$.bbq.pushState({
panel: activeBlockId
});
if (ajax_panelpage && !last_ajax_panelpage) {
last_ajax_panelpage = ajax_panelpage;
}
if (last_ajax_panelpage) {
$.bbq.pushState({
panel: activeBlockId,
panelpage: last_ajax_panelpage
});
} else {
$.bbq.pushState({
panel: activeBlockId
});
}
activeBlock.find('.arrow-right').show();
}
}
Expand Down Expand Up @@ -109,16 +138,35 @@ $(document).ready(function () {
url: $(this).attr('href'),
dataType: 'html',
success: function (data) {
var callbacks = KT.panel.get_expand_cb(),
cb = function(){};
var callbacks = KT.panel.get_expand_cb(),
cb = function(){};

thisPanel.find(".panel-content").html(data);
KT.common.jscroll_init($('.scroll-pane'));
KT.common.jscroll_resize($('.jspPane'));
KT.common.jscroll_resize($('.jspPane'));
KT.panel.panelResize($('#panel_main'), false);


// Update the bbq
var activeBlock = $('#' + KT.common.escapeId(activeBlockId)),
ajax_url = activeBlock.attr("data-ajax_url"),
ajax_panelpage = activeBlock.attr("data-ajax_panelpage");

if (ajax_panelpage) {
// Replace old ajax_panelpage with new
ajax_panelpage = this.url.substr(this.url.lastIndexOf('/') + 1);
var bbq_panel = $.bbq.getState("panel");
$.bbq.removeState("panel");
$.bbq.removeState("panelpage");
$.bbq.pushState({
panel: bbq_panel,
panelpage: ajax_panelpage
});
// Set the new default panelpage
last_ajax_panelpage = ajax_panelpage;
}

for( cb in callbacks ){
callbacks[cb]();
callbacks[cb]();
}
}
});
Expand Down Expand Up @@ -206,7 +254,20 @@ KT.panel = (function ($) {
select_item = function (activeBlockId) {
var activeBlock = $('#' + KT.common.escapeId(activeBlockId)),
ajax_url = activeBlock.attr("data-ajax_url"),
ajax_panelpage = activeBlock.attr("data-ajax_panelpage"),
full_ajax_url,
previousBlockId = null;

if (ajax_panelpage) {
// Initialize the default panelpage
if (!last_ajax_panelpage) {
last_ajax_panelpage = ajax_panelpage;
}
full_ajax_url = ajax_url + '/' + last_ajax_panelpage;
} else {
full_ajax_url = ajax_url;
}

thisPanel = $("#panel");
subpanel = $('#subpanel');
if (activeBlock.length) {
Expand All @@ -232,7 +293,7 @@ KT.panel = (function ($) {
}).removeClass('closed').addClass('opened').attr('data-id', activeBlockId);
activeBlock.addClass('active');
previousBlockId = activeBlockId;
panelAjax(activeBlockId, ajax_url, thisPanel, false);
panelAjax(activeBlockId, full_ajax_url, thisPanel, false);
}
else if (thisPanel.hasClass('opened') && thisPanel.attr("data-id") !== activeBlockId) {
switch_content_cb();
Expand All @@ -251,7 +312,7 @@ KT.panel = (function ($) {
activeBlock.addClass('active');
previousBlockId = activeBlockId;
thisPanel.removeClass('closed');
panelAjax(activeBlockId, ajax_url, thisPanel, false);
panelAjax(activeBlockId, full_ajax_url, thisPanel, false);
}
}
},
Expand All @@ -271,16 +332,16 @@ KT.panel = (function ($) {
pc.fadeIn(function () {
$(".panel-content :input:visible:enabled:first").focus();
});

KT.common.jscroll_init($('.scroll-pane'));
KT.common.jscroll_resize($('.jspPane'));

if (isSubpanel) {
panelResize($('#subpanel_main'), isSubpanel);
} else {
panelResize($('#panel_main'), isSubpanel);
}

for( callback in expand_cb ){
expand_cb[callback](name);
}
Expand Down Expand Up @@ -333,9 +394,9 @@ KT.panel = (function ($) {
subpanelnav = ($('#subpanel').find('nav').length > 0) ? $('#subpanel').find('nav').height() + 10 : 0;
height = height - subpanelSpacing * 2 - subpanelnav + subnav_spacing;
}

paneljQ.height(height);

if (paneljQ.length > 0) {
paneljQ.data('jsp').reinitialise();
}
Expand All @@ -357,6 +418,7 @@ KT.panel = (function ($) {
content.html('');
position = KT.common.scrollTop();
$.bbq.removeState("panel");
$.bbq.removeState("panelpage");
$(window).scrollTop(position);
updateResult();
contract_cb(name);
Expand Down Expand Up @@ -472,6 +534,9 @@ KT.panel = (function ($) {
},
search_started = function (event, promise) {
var refresh = $.bbq.getState("panel");
if (!last_ajax_panelpage) {
last_ajax_panelpage = $.bbq.getState("panelpage");
}

if (refresh) {
if (promise) {
Expand Down Expand Up @@ -843,9 +908,17 @@ KT.panel.list = (function () {
prepend(data);
KT.panel.closePanel($('#panel'));
id = first_child().attr("id");
$.bbq.pushState({
panel: id
});

if (last_ajax_panelpage) {
$.bbq.pushState({
panel: id,
panelpage: last_ajax_panelpage
});
} else {
$.bbq.pushState({
panel: id
});
}
KT.panel.select_item(id);
notices.checkNotices();
update_counts(1, 1, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/vendor/converge-ui
Submodule converge-ui updated from fedf3e to b74d79

0 comments on commit 9c19dce

Please sign in to comment.