Skip to content

Commit

Permalink
feat(wizard): do not show forms or FAQ on page load
Browse files Browse the repository at this point in the history
wait the user types a search or browes in a category
  • Loading branch information
btry committed Jan 13, 2022
1 parent 93f94d9 commit dcbcdf9
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

var modalWindow;
var rootDoc = CFG_GLPI['root_doc'];
var currentCategory = "0";
var tiles = [];
var slinkyCategories;
var timers = [];
Expand Down Expand Up @@ -81,23 +80,19 @@ $(function() {

} else if ($('#plugin_formcreator_wizard_categories').length > 0) {
updateCategoriesView();
updateWizardFormsView(0);
$("#wizard_seeall").parent().addClass('category_active');

$('#plugin_formcreator_wizard_categories #wizard_seeall').on('click', function () {
$('#plugin_formcreator_wizard_categories #wizard_seeall').on('click', function (event) {
slinkyCategories.home();
updateWizardFormsView(0);
plugin_formcreator.updateWizardFormsView(event.target);
$('#plugin_formcreator_wizard_categories .category_active').removeClass('category_active');
$(this).addClass('category_active');
});
} else if ($('#plugin_formcreator_kb_categories').length > 0) {
updateKbCategoriesView();
updateKbitemsView(0);
$("#kb_seeall").parent().addClass('category_active');

$('#plugin_formcreator_kb_categories #kb_seeall').on('click', function () {
$('#plugin_formcreator_kb_categories #kb_seeall').on('click', function (event) {
slinkyCategories.home();
updateKbitemsView(0);
plugin_formcreator.updateKbitemsView(event.target);
$('#plugin_formcreator_kb_categories .category_active').removeClass('category_active');
$(this).addClass('category_active');
});
Expand All @@ -108,23 +103,20 @@ $(function() {
if (searchInput.length == 1) {
// Dynamically update forms and faq items while the user types in the search bar
var timer = getTimer(searchInput);
var callbackFunc;
if ($('#plugin_formcreator_kb_categories .category_active').length > 0) {
var callback = function() {
updateKbitemsView(currentCategory);
}
callbackFunc = plugin_formcreator.updateKbitemsView.bind(plugin_formcreator);
} else {
var callback = function() {
updateWizardFormsView(currentCategory);
}
callbackFunc = plugin_formcreator.updateWizardFormsView.bind(plugin_formcreator);
}
timer(300, callback);
timer(300, callbackFunc);
timers.push(timer);

// Clear the search bar if it gains focus
$('#plugin_formcreator_searchBar input').focus(function(event) {
if (searchInput.val().length > 0) {
searchInput.val('');
updateWizardFormsView(currentCategory);
plugin_formcreator.updateWizardFormsView(null);
$.when(getFormAndFaqItems(0)).then(
function (response) {
tiles = response;
Expand Down Expand Up @@ -179,7 +171,7 @@ function updateCategoriesView() {
function(event) {
var parentItem = $(event.target).parentsUntil('#plugin_formcreator_wizard_categories .slinky-menu > ul', 'li')[1];
var parentAnchor = $(parentItem).children('a')[0];
updateWizardFormsView(parentAnchor.getAttribute('data-parent-category-id'));
plugin_formcreator.updateWizardFormsView(parentAnchor);
}
);

Expand Down Expand Up @@ -310,54 +302,12 @@ function showTiles(tiles, defaultForms) {
});
}

function updateWizardFormsView(categoryId) {
$.when(getFormAndFaqItems(categoryId)).done(
function (response) {
tiles = response.forms;
showTiles(tiles, response.default);
}
).fail(
function () {
var html = '<p>' + i18n.textdomain('formcreator').__('An error occured while querying forms', 'formcreator') + '</p>'
$('#plugin_formcreator_wizard_forms').empty();
$('#plugin_formcreator_wizard_forms').prepend(html);
$('#plugin_formcreator_formlist').masonry({
horizontalOrder: true
});
$('#plugin_formcreator_faqlist').masonry({
horizontalOrder: true
});
}
);
}

function updateKbitemsView(categoryId) {
$.when(getFaqItems(categoryId)).done(
function (response) {
tiles = response.forms;
showTiles(tiles, false);
}
).fail(
function () {
html = '<p>' + i18n.textdomain('formcreator').__('An error occured while querying forms', 'formcreator') + '</p>'
$('#plugin_formcreator_wizard_forms').empty();
$('#plugin_formcreator_wizard_forms').prepend(html);
$('#plugin_formcreator_formlist').masonry({
horizontalOrder: true
});
$('#plugin_formcreator_faqlist').masonry({
horizontalOrder: true
});
}
);
}

function buildKbCategoryList(tree) {
var html = '';
if (tree.id != 0) {
html += '<a href="#" data-parent-category-id="' + tree.parent +'"'
+ ' data-category-id="' + tree.id + '"'
+ ' onclick="updateKbitemsView(' + tree.id + ')">'
+ ' onclick="plugin_formcreator.updateWizardFormsView(this)">'
+ tree.name
+ '</a>';
}
Expand All @@ -377,7 +327,7 @@ function buildCategoryList(tree) {
if (tree.id != 0) {
html = '<a href="#" data-parent-category-id="' + tree.parent +'"'
+ ' data-category-id="' + tree.id + '"'
+ ' onclick="updateWizardFormsView(' + tree.id + ')">'
+ ' onclick="plugin_formcreator.updateWizardFormsView(this)">'
+ tree.name
+ '</a>';
}
Expand Down Expand Up @@ -480,6 +430,8 @@ var plugin_formcreator = new function() {

this.questionColumns = 4;

this.activeCategory = 0;

this.modalSetings = {
autoOpen: false,
height: 'auto',
Expand Down Expand Up @@ -1169,6 +1121,54 @@ var plugin_formcreator = new function() {
location.reload();
});
}

this.updateWizardFormsView = function (item) {
if (item) {
this.activeCategory = item.getAttribute('data-category-id');
}
$.when(getFormAndFaqItems(this.activeCategory)).done(
function (response) {
tiles = response.forms;
showTiles(tiles, response.default);
}
).fail(
function () {
var html = '<p>' + i18n.textdomain('formcreator').__('An error occured while querying forms', 'formcreator') + '</p>'
$('#plugin_formcreator_wizard_forms').empty();
$('#plugin_formcreator_wizard_forms').prepend(html);
$('#plugin_formcreator_formlist').masonry({
horizontalOrder: true
});
$('#plugin_formcreator_faqlist').masonry({
horizontalOrder: true
});
}
);
}

this.updateKbitemsView = function (item) {
if (item) {
this.activeCategory = item.getAttribute('data-category-id');
}
$.when(getFaqItems(this.activeCategory)).done(
function (response) {
tiles = response.forms;
showTiles(tiles, false);
}
).fail(
function () {
html = '<p>' + i18n.textdomain('formcreator').__('An error occured while querying forms', 'formcreator') + '</p>'
$('#plugin_formcreator_wizard_forms').empty();
$('#plugin_formcreator_wizard_forms').prepend(html);
$('#plugin_formcreator_formlist').masonry({
horizontalOrder: true
});
$('#plugin_formcreator_faqlist').masonry({
horizontalOrder: true
});
}
);
}
}

// === TARGETS ===
Expand Down

0 comments on commit dcbcdf9

Please sign in to comment.