[Kimchi-devel] [PATCH] [Kimchi] Save last view for templates - fix for issue# 799
Socorro Stoppler
socorro at linux.vnet.ibm.com
Wed Jun 29 18:07:32 UTC 2016
This patch addresses github issue# 799. The last view of the Templates tab
is not being remembered either after switching tabs or exiting Kimchi. When
switching view from List to Gallery (or vice versa), the next time the
user goes back to the Templates tab, whatever view it was last on should
be what is shown when going back to the Templates tab. Thanks to samhenri
in helping resolve the last issue.
Signed-off-by: Socorro Stoppler <socorro at linux.vnet.ibm.com>
---
ui/js/src/kimchi.template_main.js | 63 +++++++++++++++++++++++++++++++++++----
1 file changed, 57 insertions(+), 6 deletions(-)
diff --git a/ui/js/src/kimchi.template_main.js b/ui/js/src/kimchi.template_main.js
index 22a3509..ed49246 100644
--- a/ui/js/src/kimchi.template_main.js
+++ b/ui/js/src/kimchi.template_main.js
@@ -30,7 +30,7 @@ kimchi.doListTemplates = function() {
}
listHtml += wok.substitute(templateHtml, value);
});
- $('.wok-vm-list').removeClass('hidden');
+ $('ul#templates-grid').removeClass('hidden');
$('#templates-container').removeClass('hidden');
$('#templateList').html(listHtml);
kimchi.templateBindClick();
@@ -39,7 +39,7 @@ kimchi.doListTemplates = function() {
} else {
$('#templateList').html('');
$('#noTemplates').show();
- $('.wok-vm-list').addClass('hidden');
+ $('ul#templates-grid').addClass('hidden');
$('#templates-container').addClass('hidden');
$('.wok-mask').fadeOut(300, function() {});
}
@@ -58,10 +58,47 @@ kimchi.doListTemplates = function() {
};
kimchi.toggleTemplatesGallery = function() {
- $(".wok-vm-list, .wok-vm-gallery").toggleClass("wok-vm-list wok-vm-gallery");
- $(".wok-list, .wok-gallery").toggleClass("wok-list wok-gallery");
- var text = $('#gallery-table-button span.text').text();
- $('#gallery-table-button span.text').text(text == i18n['KCHTMPL6005M'] ? i18n['KCHTMPL6004M'] : i18n['KCHTMPL6005M']);
+ $(".wok-vm-list, .wok-vm-gallery").toggleClass("wok-vm-list wok-vm-gallery");
+ $(".wok-list, .wok-gallery").toggleClass("wok-list wok-gallery");
+ var text = $('#gallery-table-button span.text').text();
+ $('#gallery-table-button span.text').text(text == i18n['KCHTMPL6005M'] ? i18n['KCHTMPL6004M'] : i18n['KCHTMPL6005M']);
+ var buttonText = $('#gallery-table-button span.text').text();
+ if (buttonText.indexOf("Gallery") !== -1) {
+ // Currently in list view
+ kimchi.setTemplateView("templateView", "list");
+ } else {
+ // Currently in gallery
+ kimchi.setTemplateView("templateView", "gallery");
+ }
+};
+
+kimchi.setTemplateView = function(name, value) {
+ window.localStorage.setItem(name, value);
+};
+
+kimchi.readTemplateView = function(name) {
+ var viewName = window.localStorage.getItem(name);
+ if (viewName !== "") {
+ return viewName;
+ } else {
+ return null;
+ }
+};
+
+kimchi.showTemplateGallery = function() {
+ $(".wok-vm-list").addClass("wok-vm-gallery");
+ $(".wok-list").addClass("wok-gallery");
+ $(".wok-vm-gallery").removeClass("wok-vm-list");
+ $(".wok-gallery").removeClass("wok-list");
+ $('#gallery-table-button span.text').text(i18n['KCHTMPL6004M']);
+};
+
+kimchi.showTemplateList = function() {
+ $(".wok-vm-gallery").addClass("wok-vm-list");
+ $(".wok-gallery").addClass("wok-list");
+ $(".wok-vm-list").removeClass("wok-vm-gallery");
+ $(".wok-list").removeClass("wok-gallery");
+ $('#gallery-table-button span.text').text(i18n['KCHTMPL6005M']);
};
kimchi.templateBindClick = function() {
@@ -117,6 +154,20 @@ kimchi.hideTitle = function() {
kimchi.template_main = function() {
$('body').addClass('wok-list');
+ var viewFound = kimchi.readTemplateView("templateView");
+ if (viewFound) {
+ if(viewFound === "gallery") {
+ // should be showing gallery
+ kimchi.showTemplateGallery();
+ } else {
+ // Should be showing list
+ kimchi.showTemplateList();
+ }
+ } else {
+ // Default to showing list
+ kimchi.showTemplateList();
+ }
+
if (wok.tabMode['templates'] === 'admin') {
$('.tools').attr('style', 'display');
$("#template-add").on("click", function(event) {
--
2.5.0
More information about the Kimchi-devel
mailing list