Skip to content

Commit aeb040c

Browse files
stonebuzzbtry
authored andcommitted
feat(wizard): new tile design, optional
1 parent 3e29a46 commit aeb040c

File tree

7 files changed

+79
-8
lines changed

7 files changed

+79
-8
lines changed

css/styles.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
}
9797

9898
/* Sections */
99-
#plugin_formcreator_form.plugin_formcreator_form_design {
99+
#plugin_formcreator_form.plugin_formcreator_tile_design {
100100
ol {
101101
list-style-type: none;
102102
text-align: left;
@@ -668,6 +668,11 @@ tr[data-itemtype="PluginFormcreatorCondition"] ~ tr[data-itemtype="PluginFormcre
668668
background-color: #CCC;
669669
}
670670

671+
.plugin_formcreator_formTile.tile_design_uniform_height {
672+
height: 150px;
673+
display: inline-block;
674+
}
675+
671676
a.plugin_formcreator_formTile_title {
672677
padding: 10px 40px 15px 10px;
673678
display: block;

inc/entityconfig.class.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class PluginFormcreatorEntityconfig extends CommonDBTM {
6666
const CONFIG_SEARCH_ISSUE_HIDDEN = 0;
6767
const CONFIG_SEARCH_ISSUE_VISIBLE = 1;
6868

69+
const CONFIG_UI_FORM_MASONRY = 0;
70+
const CONFIG_UI_FORM_UNIFORM_HEIGHT = 1;
71+
72+
6973
/**
7074
* @var bool $dohistory maintain history
7175
*/
@@ -146,6 +150,14 @@ public static function getEnumSearchIssueVisibility() : array {
146150
];
147151
}
148152

153+
public static function getEnumUIForm() : array {
154+
return [
155+
self::CONFIG_PARENT => __('Inheritance of the parent entity'),
156+
self::CONFIG_UI_FORM_MASONRY => __('Variable height', 'formcreator'),
157+
self::CONFIG_UI_FORM_UNIFORM_HEIGHT => __('Uniform height', 'formcreator'),
158+
];
159+
}
160+
149161
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
150162
if ($item->getType() == 'Entity') {
151163
$config = new self();
@@ -342,6 +354,22 @@ public function showFormForEntity(Entity $entity) {
342354
}
343355
echo '</td></tr>';
344356

357+
// Tiles Design
358+
$elements = self::getEnumUIForm();
359+
if ($entityId == 0) {
360+
unset($elements[self::CONFIG_PARENT]);
361+
}
362+
echo "<tr class='tab_bg_1'>";
363+
echo "<td>".__('Tile design', 'formcreator')."</td>";
364+
echo "<td>";
365+
Dropdown::showFromArray('tile_design', $elements, ['value' => $this->fields['tile_design']]);
366+
if ($this->fields['tile_design'] == self::CONFIG_PARENT) {
367+
$tid = self::getUsedConfig('tile_design', $entityId);
368+
echo '<br>';
369+
Entity::inheritedValue($elements[$tid], true);
370+
}
371+
echo '</td></tr>';
372+
345373
// header
346374
echo "<tr class='tab_bg_1'>";
347375
echo "<td>" . _n('Header', 'Headers', 1, 'formcreator') . "</td>";

inc/form.class.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ public function showWizard() : void {
702702
public static function getFormList(int $rootCategory = 0, string $keywords = '', bool $helpdeskHome = false): array {
703703
global $DB, $TRANSLATE;
704704

705+
$display_format = PluginFormcreatorEntityconfig::getUsedConfig('tile_design', Session::getActiveEntity());
706+
705707
$table_cat = getTableForItemType(PluginFormcreatorCategory::class);
706708
$table_form = getTableForItemType(PluginFormcreatorForm::class);
707709
$table_section = getTableForItemType(PluginFormcreatorSections::class);
@@ -795,7 +797,8 @@ public static function getFormList(int $rootCategory = 0, string $keywords = '',
795797
'description' => __($form['description'], $domain),
796798
'type' => 'form',
797799
'usage_count' => $form['usage_count'],
798-
'is_default' => $form['is_default'] ? "true" : "false"
800+
'is_default' => $form['is_default'] ? "true" : "false",
801+
'tile_template' => $display_format,
799802
];
800803
}
801804

@@ -833,7 +836,8 @@ public static function getFormList(int $rootCategory = 0, string $keywords = '',
833836
'description' => '',
834837
'type' => 'faq',
835838
'usage_count' => $faq['view'],
836-
'is_default' => false
839+
'is_default' => false,
840+
'tile_template' => PluginFormcreatorEntityConfig::CONFIG_UI_FORM_MASONRY
837841
];
838842
}
839843
}
@@ -863,6 +867,7 @@ public static function getFormList(int $rootCategory = 0, string $keywords = '',
863867
'type' => 'form',
864868
'usage_count' => $form['usage_count'],
865869
'is_default' => true,
870+
'tile_template' => $display_format,
866871
];
867872
}
868873
}

install/install.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ protected function configureExistingEntities() {
263263

264264
/** Value -2 is "inheritance from parent" @see PluginFormcreatorEntityconfig::CONFIG_PARENT */
265265
$query = "INSERT INTO glpi_plugin_formcreator_entityconfigs
266-
(entities_id, replace_helpdesk, default_form_list_mode, sort_order, is_kb_separated, is_search_visible, is_dashboard_visible, is_header_visible, is_search_issue_visible)
266+
(entities_id, replace_helpdesk, default_form_list_mode, sort_order, is_kb_separated, is_search_visible, is_dashboard_visible, is_header_visible, is_search_issue_visible, tile_design)
267267
SELECT ent.id,
268268
IF(ent.id = 0, 0, -2),
269269
IF(ent.id = 0, 0, -2),
@@ -272,7 +272,8 @@ protected function configureExistingEntities() {
272272
IF(ent.id = 0, 0, -2),
273273
IF(ent.id = 0, 1, -2),
274274
IF(ent.id = 0, 0, -2),
275-
IF(ent.id = 0, 1, -2)
275+
IF(ent.id = 0, 1, -2),
276+
IF(ent.id = 0, 0, -2)
276277
FROM glpi_entities ent
277278
LEFT JOIN glpi_plugin_formcreator_entityconfigs conf
278279
ON ent.id = conf.entities_id

install/mysql/plugin_formcreator_empty.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_entityconfigs` (
3838
`is_dashboard_visible` int(11) NOT NULL DEFAULT '-2',
3939
`is_header_visible` int(11) NOT NULL DEFAULT '-2',
4040
`is_search_issue_visible` int(11) NOT NULL DEFAULT '-2',
41+
`tile_design` int(11) NOT NULL DEFAULT '-2',
4142
`header` text,
4243
PRIMARY KEY (`id`),
4344
UNIQUE KEY `unicity` (`entities_id`)

install/upgrade_to_2.13.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public function addEntityOption() {
5959
$this->migration->addField($table, 'is_search_issue_visible', 'integer', ['after' => 'is_header_visible', 'value' => '-2']);
6060
$this->migration->addPostQuery("UPDATE `glpi_plugin_formcreator_entityconfigs` SET `is_search_issue_visible`= 1 WHERE `entities_id` = 0");
6161
}
62+
63+
if (!$DB->fieldExists($table, 'tile_design')) {
64+
$this->migration->addField($table, 'tile_design', 'integer', ['after' => 'is_search_issue_visible', 'value' => '-2']);
65+
$this->migration->addPostQuery("UPDATE `glpi_plugin_formcreator_entityconfigs` SET `tile_design`= '0' WHERE `entities_id` = 0");
66+
}
6267
}
6368

6469
public function addFormAnswerTitle() {

js/scripts.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,27 @@ function showTiles(tiles, defaultForms) {
309309
horizontalOrder: true,
310310
gutter: 10
311311
});
312+
313+
314+
$(".plugin_formcreator_formTile_description.tile_design_uniform_height").each(function( index ) {
315+
var length = 150;
316+
//decrease length if contain icon
317+
if ($(this).parent().find(".fa").length > 0) {
318+
length = length - 35;
319+
}
320+
321+
var parent_title = $(this).parent().find('.plugin_formcreator_formTile_title').text();
322+
if (parent_title.length + $(this).text().length > length) {
323+
var short = jQuery.trim($(this).text())
324+
.substring(0, length)
325+
.split(" ")
326+
.slice(0, -1)
327+
.join(" ") + " ...";
328+
$(this).html(short);
329+
}
330+
});
331+
332+
312333
}
313334

314335
function buildKbCategoryList(tree) {
@@ -372,9 +393,14 @@ function buildTiles(list) {
372393
url = rootDoc + '/front/knowbaseitem.form.php?id=' + item.id;
373394
}
374395

396+
var tiles_design = "";
397+
if (item.tile_template == "1") { // @see PluginFormcreatorEntityConfig::CONFIG_UI_FORM_UNIFORM_HEIGHT
398+
tiles_design = "tile_design_uniform_height";
399+
}
400+
375401
var description = '';
376402
if (item.description) {
377-
description = '<div class="plugin_formcreator_formTile_description">'
403+
description = '<div class="plugin_formcreator_formTile_description '+ tiles_design +'">'
378404
+item.description
379405
+'</div>';
380406
}
@@ -402,7 +428,7 @@ function buildTiles(list) {
402428

403429
if (item.type == 'form') {
404430
forms.push(
405-
'<div data-itemtype="PluginFormcreatorForm" data-id="' + item.id + '" style="background-color: ' + item.background_color + '" class="plugin_formcreator_formTile '+item.type+' '+default_class+'" title="'+item.description+'">'
431+
'<div data-itemtype="PluginFormcreatorForm" data-id="' + item.id + '" style="background-color: ' + item.background_color + '" class="plugin_formcreator_formTile '+item.type+' '+tiles_design+' '+default_class+'" title="'+item.description+'">'
406432
+ '<i class="' + item.icon + '" style="color: ' + item.icon_color+ '"></i>'
407433
+ '<a href="' + url + '" class="plugin_formcreator_formTile_title">'
408434
+ item.name
@@ -412,7 +438,7 @@ function buildTiles(list) {
412438
);
413439
} else {
414440
faqs.push(
415-
'<div style="background-color: ' + item.background_color + '" class="plugin_formcreator_formTile '+item.type+' '+default_class+'" title="'+item.description+'">'
441+
'<div style="background-color: ' + item.background_color + '" class="plugin_formcreator_formTile '+item.type+' '+tiles_design+' '+default_class+'" title="'+item.description+'">'
416442
+ '<i class="fa ' + item.icon + '" style="color: ' + item.icon_color+ '"></i>'
417443
+ '<a href="' + url + '" class="plugin_formcreator_formTile_title">'
418444
+ item.name

0 commit comments

Comments
 (0)