Skip to content

Commit

Permalink
Updated to AppGini 24.14
Browse files Browse the repository at this point in the history
  • Loading branch information
bigprof committed Jun 4, 2024
1 parent 7d0a182 commit 339c178
Show file tree
Hide file tree
Showing 39 changed files with 391 additions and 71 deletions.
16 changes: 8 additions & 8 deletions Northwind.axp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/admin/incFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
request_outside_admin_folder() -- returns true if currently executing script is outside admin folder, false otherwise.
breakpoint(__FILE__, __LINE__, $msg) -- if DEBUG_MODE enabled, logs a message to {app_dir}/breakpoint.csv, if $msg is array, it will be converted to str via json_encode
denyAccess($msg) -- Send a 403 Access Denied header, with an optional message then die
getUploadDir($dir) -- if dir is empty, returns upload dir configured in defaultLang.php, else returns $dir.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
########################################################################
Expand Down Expand Up @@ -3003,7 +3004,7 @@ function parseTemplate($template) {
function getUploadDir($dir = '') {
if($dir == '') $dir = config('adminConfig')['baseUploadPath'];

return rtrim($dir, '\\/') . '/';
return rtrim($dir, '\\/') . DIRECTORY_SEPARATOR;
}
#########################################################
function bgStyleToClass($html) {
Expand Down
119 changes: 96 additions & 23 deletions app/admin/pageEditGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@
$groupID = 0;
}
}

// get all groups and their permissions
$groupPermissions = [];
$res = sql("SELECT * FROM `membership_grouppermissions`", $eo);
while($row = db_fetch_assoc($res)) {
$groupPermissions[$row['groupID']][$row['tableName']] = $row;
}
?>

<?php if(Request::val('msg') == 'added'){ ?>
Expand All @@ -145,7 +152,7 @@

<div class="page-header">
<h1>
<?php echo($groupID ? str_replace('<GROUPNAME>', '<span class="text-info">' . html_attr($name) . '</span>', $Translation['edit group']) : $Translation['add new group']); ?>
<?php echo($groupID ? preg_replace('/\'?<GROUPNAME>\'?/', '<span class="text-info text-bold">' . html_attr($name) . '</span>', $Translation['edit group']) : $Translation['add new group']); ?>
<div class="pull-right">
<div class="btn-group">
<a href="pageViewGroups.php" class="btn btn-default btn-lg">
Expand Down Expand Up @@ -179,23 +186,31 @@
<?php } ?>


<div class="form-group">
<label class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label"></label>
<div class="col-sm-8 col-md-9 col-lg-6">
<div class="checkbox">
<label>
<input type="checkbox" id="showToolTips" value="1" checked>
<?php echo $Translation['show tool tips']; ?>
</label>
</div>
</div>
</div>

<form method="post" action="pageEditGroup.php" class="form-horizontal">
<?php echo csrf_token(); ?>

<input type="hidden" name="groupID" value="<?php echo $groupID; ?>">

<div class="row">
<div class=" col-lg-3 col-lg-offset-9 col-sm-4 col-sm-offset-8" >
<button type="submit" name="saveChanges" value="1" class="btn btn-primary btn-lg pull-right btn-block" style="max-width: 15em;"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['save changes']; ?></button>
</div>
</div>

<div class="form-group">
<label class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label"></label>
<div class="col-sm-8 col-md-9 col-lg-6">
<div class="checkbox">
<label>
<input type="checkbox" id="showToolTips" value="1" checked>
<?php echo $Translation['show tool tips']; ?>
</label>
</div>
</div>
</div>

<div style="height: 3em;"></div>

<div class="form-group ">
<label for="group-name" class="col-sm-4 col-md-3 col-lg-2 col-lg-offset-2 control-label"><?php echo $Translation['group name']; ?></label>
<div class="col-sm-8 col-md-9 col-lg-6 ">
Expand Down Expand Up @@ -252,12 +267,6 @@
</div>
</div>

<div class="row">
<div class=" col-lg-3 col-lg-offset-9 col-sm-4 col-sm-offset-8" >
<button type="submit" name="saveChanges" value="1" class="btn btn-primary btn-lg pull-right btn-block"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['save changes']; ?></button>
</div>
</div>

<div style="height: 3em;"></div>
<?php } ?>

Expand All @@ -268,7 +277,29 @@

<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<caption><h2><?php echo $Translation['group table permissions']; ?></h2></caption>
<caption>
<h2 class="pull-left"><?php echo $Translation['group table permissions']; ?></h2>
<div class="pull-right vspacer-lg">
<label class="control-label"><?php echo $Translation['Copy permissions from another group']; ?></label>
<div style="display: flex; align-items: center; gap: .5em;">
<select id="copy-permissions" class="form-control" style="flex-grow: 1;">
<option value=""><?php echo $Translation['select group']; ?></option>
<?php
$eo = ['silentErrors' => true];
$res = sql("SELECT `groupID`, `name` FROM `membership_groups` WHERE `groupID` != '{$groupID}'", $eo);
while($row = db_fetch_assoc($res)) {
echo "<option value=\"{$row['groupID']}\">{$row['name']}</option>";
}
?>
</select>
<button type="button" id="btn-revert-permissions" class="btn btn-default" title="<?php echo html_attr($Translation['revert permissions']); ?>">
<i class="glyphicon glyphicon-remove"></i>
</button>
</div>
</div>
<div class="pull-right vspacer-lg hspacer-md" style="font-size: 2em;">&#128203;</div>
<div class="clearfix"></div>
</caption>
<thead>
<tr>
<th><?php echo $Translation['table']; ?></th>
Expand Down Expand Up @@ -347,7 +378,7 @@
</div>
</th>
<td class="insert-permission">
<input onMouseOver="stm(<?php echo $tn; ?>_addTip, toolTipStyle);" onMouseOut="htm();" type="checkbox" name="<?php echo $tn; ?>_insert" value="1" <?php echo ($perm["{$tn}_insert"] ? "checked class=\"text-primary\"" : ""); ?>>
<input onMouseOver="stm(<?php echo $tn; ?>_addTip, toolTipStyle);" onMouseOut="htm();" type="checkbox" name="<?php echo $tn; ?>_insert" id="<?php echo $tn; ?>_insert" value="1" <?php echo ($perm["{$tn}_insert"] ? "checked class=\"text-primary\"" : ""); ?>>
</td>
<td class="view-permission">
<?php echo htmlRadioGroup("{$tn}_view", array_keys($arrPermText), $arrPermText, $perm["{$tn}_view"], 'text-primary'); ?>
Expand All @@ -360,14 +391,13 @@
</td>
</tr>
<?php } ?>
<tr><td colspan="5" style="height: 7em;"></td></tr>
</tbody>
</table>
</div>

<div class="row">
<div class=" col-lg-3 col-lg-offset-9 col-sm-4 col-sm-offset-8 " >
<button type="submit" name="saveChanges" value="1" class="btn btn-primary btn-lg btn-block "><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['save changes']; ?></button>
<button type="submit" name="saveChanges" value="1" class="btn btn-primary btn-lg pull-right btn-block" style="max-width: 15em;"><i class="glyphicon glyphicon-ok"></i> <?php echo $Translation['save changes']; ?></button>
</div>
</div>
</form>
Expand All @@ -376,6 +406,8 @@

<script>
$j(function() {
const groupPermissions = <?php echo json_encode($groupPermissions); ?>;

var highlight_selections = function() {
$j('input[type=radio]:checked').parent().parent().addClass('bg-warning text-primary text-bold');
$j('input[type=radio]:not(:checked)').parent().parent().removeClass('bg-warning text-primary text-bold');
Expand Down Expand Up @@ -443,6 +475,47 @@
$j('input[type=radio]').parent().mouseout(function() {
htm();
});

// copy permissions from another group
$j('#copy-permissions').on('change', function() {
const groupID = $j('#copy-permissions').val();

if(groupID && groupPermissions[groupID]) {
const perms = groupPermissions[groupID];
for(const tn in perms) {
const p = perms[tn];
console.log(tn, p);
$j(`#${tn}_insert`).prop('checked', p.allowInsert == 1);
$j(`#${tn}_view${p.allowView}`).prop('checked', true);
$j(`#${tn}_edit${p.allowEdit}`).prop('checked', true);
$j(`#${tn}_delete${p.allowDelete}`).prop('checked', true);
}
}
});

// revert permissions
$j('#btn-revert-permissions').on('click', function() {
const groupID = <?php echo json_encode($groupID ?? null); ?>;

if(groupID && groupPermissions[groupID]) {
const perms = groupPermissions[groupID];
for(const tn in perms) {
const p = perms[tn];
console.log(tn, p);
$j(`#${tn}_insert`).prop('checked', p.allowInsert == 1);
$j(`#${tn}_view${p.allowView}`).prop('checked', true);
$j(`#${tn}_edit${p.allowEdit}`).prop('checked', true);
$j(`#${tn}_delete${p.allowDelete}`).prop('checked', true);
}
} else {
setPermissionTo('insert', 'no');
setPermissionTo('view', 'no');
setPermissionTo('edit', 'no');
setPermissionTo('delete', 'no');
}

$j('#copy-permissions').val('');
})
});
</script>

Expand Down
4 changes: 2 additions & 2 deletions app/admin/pageServerStatus.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$appgini_version = '24.13.1629';
$generated_ts = '22/05/2024 13:25:12';
$appgini_version = '24.14.1665';
$generated_ts = '04/06/2024 18:27:33';

require(__DIR__ . '/incCommon.php');

Expand Down
2 changes: 1 addition & 1 deletion app/categories_dml.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class="btn btn-default"
$pt_perm = getTablePermissions($ptfc[0]);

// process foreign key links
if($pt_perm['view'] || $pt_perm['edit']) {
if(($pt_perm['view'] && isDetailViewEnabled($ptfc[0])) || $pt_perm['edit']) {
$templateCode = str_replace("<%%PLINK({$luf})%%>", '<button type="button" class="btn btn-default view_parent" id="' . $ptfc[0] . '_view_parent" title="' . html_attr($Translation['View'] . ' ' . $ptfc[1]) . '"><i class="glyphicon glyphicon-eye-open"></i></button>', $templateCode);
}

Expand Down
136 changes: 133 additions & 3 deletions app/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var AppGini = AppGini || {};

AppGini.version = 24.13;
AppGini.version = 24.14;

/* initials and fixes */
jQuery(function() {
Expand Down Expand Up @@ -317,6 +317,31 @@ jQuery(function() {
$j(this).siblings('.sql-query-copier').click();
})

// in TVP, disable lightbox for images
if($j('#current_view').val() == 'TVP') {
const links = document.querySelectorAll('a[data-lightbox]');
links.forEach(function(link) {
const img = link.innerHTML; // Get the inner HTML of the <a> tag, which should be an <img> element
link.parentNode.replaceChild(link.firstChild, link); // Replace the <a> tag with its child <img>
});
}

// render the DV layout toolbar
AppGini.renderDVLayoutToolbar();

// handle click on layout toolbar buttons
$j('.detail_view-layout').on('click', 'a', function(e) {
e.preventDefault();

if($j(this).hasClass('switch-to-single-column-layout')) {
AppGini.applySingleColumnLayout();
} else if($j(this).hasClass('switch-to-double-column-layout')) {
AppGini.applyDoubleColumnLayout();
} else if($j(this).hasClass('switch-to-triple-column-layout')) {
AppGini.applyTripleColumnLayout();
}
});

});

/* show/hide TV action buttons based on whether records are selected or not */
Expand Down Expand Up @@ -917,7 +942,7 @@ function mass_change_owner(t, ids) {
}

function add_more_actions_link() {
window.open('https://bigprof.com/appgini/help/advanced-topics/hooks/multiple-record-batch-actions?r=appgini-action-menu');
window.open('https://bigprof.com/appgini/help/advanced-topics/hooks/multiple-record-batch-actions/?r=appgini-action-menu');
}

/* detect current screen size (xs, sm, md or lg) */
Expand Down Expand Up @@ -2275,7 +2300,7 @@ AppGini.showKeyboardShortcuts = (e) => {
*/
if(typeof(_noShortcutsReference) == 'undefined')
$j(
'<a href="https://bigprof.com/appgini/help/working-with-generated-web-database-application/shortcut-keys" target="_blank">' +
'<a href="https://bigprof.com/appgini/help/working-with-generated-web-database-application/shortcut-keys/" target="_blank">' +
AppGini.Translate._map['keyboard shorcuts reference'] +
'</a>'
).appendTo('#' + modalId + ' .modal-footer');
Expand Down Expand Up @@ -2594,3 +2619,108 @@ AppGini.localeFormat = (num, isInt, locale) => {
// return the number formatted in the locale
return new Intl.NumberFormat(locale).format(parseFloat(num.replace(decimalSeparator, '.')));
}
AppGini.storedLayout = (val) => {
const view = $j('[name="current_view"]').val();

if(val !== undefined) {
localStorage.setItem(`Northwind.${AppGini.currentTableName()}.${view}.layout`, val);
}
return localStorage.getItem(`Northwind.${AppGini.currentTableName()}.${view}.layout`);
}

AppGini.renderDVLayoutToolbar = () => {
// already rendered? return
if($j('.detail_view-layout').length) return;

// if not in detail view, return
if(!$j('.detail_view').length) return;

// if we have less than 3 divs in the first fieldset, return
if($j('fieldset.form-horizontal').first().children('div').length < 3) return;

// create the layout toolbar above 1st fieldset
$j('fieldset.form-horizontal').first().before(`
<div class="detail_view-layout hidden-print">
<a href="#" class="switch-to-single-column-layout"><img src="${AppGini.config.url}resources/images/single-column-layout.png"></a>
<a href="#" class="switch-to-double-column-layout"><img src="${AppGini.config.url}resources/images/double-column-layout.png"></a>
<a href="#" class="switch-to-triple-column-layout"><img src="${AppGini.config.url}resources/images/triple-column-layout.png"></a>
</div>
`);

// retrieve user preference from local storage
const dvLayout = AppGini.storedLayout();

// apply user preference if found
const windowWidth = $j(window).width();
if(dvLayout == 'double-column-layout' && windowWidth >= 1200) {
AppGini.applyDoubleColumnLayout();
} else if(dvLayout == 'triple-column-layout' && windowWidth >= 1700) {
AppGini.applyTripleColumnLayout();
}
}

AppGini.applySingleColumnLayout = () => {
// move all divs inside second and third fieldsets to the first fieldset
$j('fieldset.form-horizontal').slice(1).children('div').appendTo($j('fieldset.form-horizontal').first());

// remove second and third fieldsets
$j('fieldset.form-horizontal').slice(1).remove();

// remove .double-column-layout and .triple-column-layout classes from all fieldsets
$j('fieldset.form-horizontal').removeClass('double-column-layout triple-column-layout');

// store preference in local storage
AppGini.storedLayout('single-column-layout');
}

AppGini.applyDoubleColumnLayout = () => {
// if already in double-column layout, return
if($j('fieldset.form-horizontal').first().hasClass('double-column-layout')) return;

// if already in triple-column layout, switch to double-column layout
if($j('fieldset.form-horizontal').first().hasClass('triple-column-layout')) {
AppGini.applySingleColumnLayout();
}

// create a new fieldset for the third column
$j('fieldset.form-horizontal').first().after('<fieldset></fieldset>');

// add .double-column-layout class to all fieldsets
$j('fieldset').addClass('form-horizontal double-column-layout');

// move half of the divs from the first fieldset to the second fieldset
const half = Math.ceil($j('fieldset.form-horizontal').first().children('div').length / 2);
$j('fieldset.form-horizontal').first().children('div').slice(half).appendTo($j('fieldset.form-horizontal').first().next());

// store preference in local storage
AppGini.storedLayout('double-column-layout');
}

AppGini.applyTripleColumnLayout = () => {
// if already in triple-column layout, return
if($j('fieldset.form-horizontal').first().hasClass('triple-column-layout')) return;

// if already in double-column layout, switch to triple-column layout
if($j('fieldset.form-horizontal').first().hasClass('double-column-layout')) {
AppGini.applySingleColumnLayout();
}

// create a new fieldset for the second column
$j('fieldset.form-horizontal').first().after('<fieldset></fieldset>');

// create a new fieldset for the third column
$j('fieldset.form-horizontal').first().after('<fieldset></fieldset>');

// add .triple-column-layout class to all fieldsets
$j('fieldset').addClass('form-horizontal triple-column-layout');

// move 1/3 of the divs from the first fieldset to the second fieldset
const third = Math.ceil($j('fieldset.form-horizontal').first().children('div').length / 3);
$j('fieldset.form-horizontal').first().children('div').slice(third * 2).appendTo($j('fieldset.form-horizontal').first().next().next());
$j('fieldset.form-horizontal').first().children('div').slice(third).appendTo($j('fieldset.form-horizontal').first().next());

// store preference in local storage
AppGini.storedLayout('triple-column-layout');
}


Loading

0 comments on commit 339c178

Please sign in to comment.