Skip to content

Commit 8ad0ed5

Browse files
committed
Added support for Dataface_Record getTableAttribute() method that wraps table-level fields.ini properties, and allows delegate class to override using attribute__ATTNAME method.
Added support for exclude and with parameters in ActionTool.getActions(). Added support for no_view_tab table attribute to specify that the given table doesn't have a view tab. If the view action will automatically forward to the first action in the record_tabs category for the record. Added support for the cover_image table attribute that will display a cover image in the record template. Improved layout of the record view so that there is more consistent record information shared between view tab and related tabs. Some improvements to both the mobile and desktop UI for record views.
1 parent 6ac3847 commit 8ad0ed5

16 files changed

+295
-38
lines changed

Dataface/ActionTool.php

+31-3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,25 @@ function getActions($params=array(), $actions=null){
169169
if ( !is_array($params) ){
170170
trigger_error("In Dataface_ActionTool::getActions(), expected parameter to be an array but received a scalar: ".$params.".".Dataface_Error::printStackTrace(), E_USER_ERROR);
171171
}
172+
if (@$params['category']) {
173+
$cats = $params['category'];
174+
if (is_string($cats)) {
175+
$pos = strpos($cats, '|');
176+
if ($pos !== false) {
177+
$cats = array_map('trim', explode('|', $cats));
178+
}
179+
180+
}
181+
if (is_array($cats)) {
182+
$out = [];
183+
foreach ($cats as $cat) {
184+
$params['category'] = $cat;
185+
$out = array_merge($out, $this->getActions($params, $actions));
186+
}
187+
return $out;
188+
}
189+
}
190+
172191
$app =& Dataface_Application::getInstance();
173192

174193
$out = array();
@@ -230,11 +249,20 @@ function getActions($params=array(), $actions=null){
230249
}
231250
else $actions = $this->actions;
232251
}
252+
$excludes = null;
253+
if (@$params['exclude']) {
254+
$excludes = $params['exclude'];
255+
if (is_string($excludes)) {
256+
$excludes = explode(' ', $excludes);
257+
}
258+
}
233259
foreach ( array_keys($actions) as $key ){
234260
if ( isset($action) ) unset($action);
235261
$action = $actions[$key];
236262
$action['atts'] = array();
237-
263+
if ($excludes and in_array($action['name'], $excludes)) {
264+
continue;
265+
}
238266
if ( @$params['name'] and @$params['name'] !== @$action['name']) continue;
239267
if ( @$params['id'] and @$params['id'] !== @$action['id']) continue;
240268
if ( @$params['withtags']) {
@@ -245,7 +273,7 @@ function getActions($params=array(), $actions=null){
245273
if (@$params['with']) {
246274
$missingKey = false;
247275
foreach (explode(' ', $params['with']) as $withKey) {
248-
if (!$action[$withKey]) {
276+
if (!@$action[$withKey]) {
249277
$missingKey = true;
250278
break;
251279
}
@@ -331,7 +359,7 @@ function getActions($params=array(), $actions=null){
331359

332360
unset($action);
333361
}
334-
362+
335363
uasort($out, array(&$this, '_compareActions'));
336364
return $out;
337365
}

Dataface/Application.php

+24-1
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,8 @@ function handleRequest($disableCache=false){
24562456
// Do whatever we need to do before the request is handled.
24572457
$applicationDelegate->beforeHandleRequest();
24582458
}
2459-
2459+
2460+
24602461

24612462

24622463
//$table->setSecurityFilter();
@@ -2556,6 +2557,28 @@ function handleRequest($disableCache=false){
25562557
//I18Nv2::autoConv();
25572558
//}
25582559

2560+
$record = $this->getRecord();
2561+
if ($record and $record->getTableAttribute('no_view_tab') and $query['-action'] == 'view') {
2562+
$relationshipActions = $record->table()->getRelationshipsAsActions();
2563+
$recordActions = $actionTool->getActions([
2564+
'record' => $record,
2565+
'category' => 'record_tabs',
2566+
'exclude' => 'edit view',
2567+
'actions' => $relationshipActions,
2568+
'with' => 'url'
2569+
]);
2570+
2571+
$recordActions = array_merge($recordActions, $relationshipActions);
2572+
if (count($recordActions) > 0) {
2573+
foreach ($recordActions as $recordAction) {
2574+
2575+
header('Location: '.$recordAction['url']);
2576+
exit;
2577+
}
2578+
}
2579+
2580+
}
2581+
25592582
$params = array(
25602583
'table'=>$query['-table'],
25612584
'name'=>$query['-action']);

Dataface/Record.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,22 @@ function display($fieldname, $index=0, $where=0, $sort=0, $urlencode=true){
27092709
}
27102710

27112711

2712+
/**
2713+
* Gets a table attribute. Table attributes are defined in the fields.ini file in the global
2714+
* scope. They can be overridden in the delegate class via the attribute__attname methods.
2715+
* @since 3.0
2716+
*/
2717+
function getTableAttribute($attname) {
2718+
$del = $this->_table->getDelegate();
2719+
$method = 'attribute__'.$attname;
2720+
if ($del and method_exists($del, $method)) {
2721+
$out = $del->$method($this);
2722+
if (isset($out)) {
2723+
return $out;
2724+
}
2725+
}
2726+
return @$this->_table->_atts[$attname];
2727+
}
27122728

27132729

27142730
/**
@@ -2745,7 +2761,10 @@ function htmlValue($fieldname, $index=0, $where=0, $sort=0,$params=array()){
27452761
$recid = $this->getId();
27462762
$uri = $recid.'#'.$fieldname;
27472763
$domid = $uri.'-'.rand();
2748-
2764+
if (is_string($params)) {
2765+
parse_str($params, $tmp);
2766+
$params = $tmp;
2767+
}
27492768

27502769

27512770
$delegate =& $this->_table->getDelegate();

Dataface/RecordView.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function __construct(&$record){
117117
}
118118
if ( $record->_table->isMetaField($field['name']) ) continue;
119119

120-
if ( !@$app->prefs['hide_record_view_logo'] ){
120+
if ( false and !@$app->prefs['hide_record_view_logo'] ){
121121
if ( ($record->isImage($field['name']) and @$field['logo'] !== '0') or @$field['logo']) {
122122
$this->showLogo = true;
123123

Dataface/SkinTool.php

+28-5
Original file line numberDiff line numberDiff line change
@@ -761,19 +761,17 @@ function actions_menu($params, &$smarty){
761761

762762
if ( isset( $params['actions'] ) ){
763763
$addon_actions = & $params['actions'];
764+
unset($params['actions']);
764765
} else {
765766
$addon_actions = null;
766767
}
767768

768-
769-
770-
771769
//$params['var'] = 'actions';
772770
//$this->actions($params, $smarty);
773771
//print_r($
774772
import( XFROOT.'Dataface/ActionTool.php');
775773
$actionTool =& Dataface_ActionTool::getInstance();
776-
$actions = $actionTool->getActions($params);
774+
$actions = count($params) > 0 ? $actionTool->getActions($params) : [];
777775
if ( $addon_actions !== null ){
778776
$p2 = $params;
779777
unset($p2['category']);
@@ -809,6 +807,28 @@ function actions_menu($params, &$smarty){
809807
//print_r($actions);
810808
$context['actions'] =& $actions;
811809
//$smarty->assign($context);
810+
if (isset($params['mincount_class'])) {
811+
$tmp = $params['mincount_class'];
812+
$pos = strpos($tmp, ' ');
813+
if ($pos !== false) {
814+
$cnt = intval(substr($tmp, 0, $pos));
815+
$cls = substr($tmp, $pos+1);
816+
if ($cnt <= count($context['actions'])) {
817+
$context['class'] = trim(@$context['class'] .' '.$cls);
818+
}
819+
}
820+
}
821+
if (isset($params['maxcount_class'])) {
822+
$tmp = $params['maxcount_class'];
823+
$pos = strpos($tmp, ' ');
824+
if ($pos !== false) {
825+
$cnt = intval(substr($tmp, 0, $pos));
826+
$cls = substr($tmp, $pos+1);
827+
if ($cnt > count($context['actions'])) {
828+
$context['class'] = trim(@$context['class'] .' '.$cls);
829+
}
830+
}
831+
}
812832
if ( isset($params['mincount']) and intval($params['mincount']) > count($context['actions']) ) return;
813833
if ( isset($params['maxcount']) and intval($params['maxcount']) < count($context['actions']) ){
814834
$more = array(
@@ -850,7 +870,9 @@ function actions_menu($params, &$smarty){
850870
}
851871
//echo print_r($context);exit;
852872

853-
873+
foreach ($context['actions'] as $actionDef) {
874+
$context['class'] .= ' with-'.$actionDef['name'];
875+
}
854876

855877
$smarty->display($context, 'Dataface_ActionsMenu.html');
856878

@@ -870,6 +892,7 @@ function record_tabs($params, &$smarty){
870892
$params2 = array();
871893

872894
$params['actions'] = $table->getRelationshipsAsActions($params2);
895+
873896
return $this->actions_menu($params, $smarty);
874897

875898
}

Dataface/Table.php

+1
Original file line numberDiff line numberDiff line change
@@ -3296,6 +3296,7 @@ function getListStyle() {
32963296
}
32973297
return 'auto';
32983298
}
3299+
32993300

33003301
/**
33013302
* Gets the name of the table used for the new record form on this

Dataface/templates/Dataface_ActionsMenu.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*}
2020
{define_slot name="actions_menu"}
2121
{if $actions|@count > 0}
22-
<ul {if $class}class="{$class|escape}"{/if} {if $id}id="{$id|escape}"{/if}>
22+
<ul {if $class}class="{$class|escape}"{/if} {if $id}id="{$id|escape}"{/if} data-actions-count="{$actions|@count}">
2323
{block name="actions_menu_head"}
2424
{foreach item=action from=$actions key=name}
2525
{if $action.subcategory and !$action.subactions}

Dataface/templates/Dataface_Main_Template.html

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@
113113
{/if}
114114

115115
<div class="mobile page-title">{define_slot name="html_title_mobile"}{$ENV.APPLICATION_OBJECT->getPageTitle('mobile')|escape}{/define_slot}</div>
116+
117+
<div class="mobile-overflow-menu">
118+
{define_slot name="mobile_overflow_menu"}
119+
120+
{/define_slot}
121+
</div>
122+
123+
116124
</div>
117125
{if $ENV.prefs.mobile_nav_style=='hamburger' and !$back_action}
118126
{*

Dataface/templates/Dataface_Record_Template.html

+59-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,22 @@
1818
*-------------------------------------------------------------------------------
1919
*}
2020
{load_record}
21+
{if $ENV.record and $ENV.record->getTableAttribute('cover_image')}
22+
{$ENV.APPLICATION_OBJECT->addBodyCSSClass('cover-image')}
23+
{/if}
2124
{use_macro file="Dataface_Main_Template.html"}
2225

26+
{fill_slot name="mobile_overflow_menu"}
27+
{actions var="menus" category="record_actions"}
28+
{if $menus|@count > 0 }
29+
<nav role="navigation" class='personal-tools-menu'>
30+
{actions_menu category="record_actions_menu"}
31+
</nav>
32+
33+
34+
{/if}
35+
{/fill_slot}
36+
2337
{fill_slot name="main_section"}
2438

2539
{if $ENV.prefs.show_result_controller}
@@ -29,23 +43,52 @@
2943
{block name="after_details_controller"}
3044
{/if}
3145
{block name="before_record_heading"}
46+
<div class='record-heading'>
3247
{define_slot name="record_heading"}
33-
48+
{if $ENV.record and $ENV.record->getTableAttribute('cover_image')}
49+
<div class='record-heading-cover-image' style='background-image:url({$ENV.record->getTableAttribute('cover_image')|escape})'>
50+
51+
</div>
52+
{/if}
53+
{if $ENV.record and $ENV.table_object->getLogoField() and $ENV.record->val($ENV.table_object->getLogoField())}
54+
<div class='record-heading-logo'>
55+
{$ENV.record->htmlValue($ENV.table_object->getLogoField(), 0, 0, 0, 'width=32')}
56+
</div>
57+
{/if}
3458
<h2 class="dataface-record-title">{if $ENV.record}<span class="dataface-current-record-prelabel"><b>{translate id="templates.Dataface_Record.LABEL_CURRENT_RECORD"}Current Record{/translate}:</b> </span>{$ENV.record->getTitle()|escape}
3559
{assign var=pkey value=$ENV.record->getPrimaryKeyValue()}
3660
{if $ENV.record->getTitle() != $pkey and is_numeric($pkey)}
3761
<span class="id-field">#{$pkey|escape}</span>
3862
{/if}
3963
{else}No Records Matched your Request{/if}</h2>
64+
{if $ENV.record}
65+
<div class='record-heading-description'>
66+
{$ENV.record->getDescription()}
67+
</div>
68+
{actions var=actions category="record_actions|mobile_edit" with="featured"}
69+
{if $actions|@count>0}
70+
<div class="mobile mobile-record-actions">
71+
72+
{actions_menu actions=$actions}
73+
</div>
74+
{/if}
75+
76+
{/if}
4077

4178
{/define_slot}
79+
</div>
4280
{block name="after_record_heading"}
4381
{block name="before_record_tabs"}
4482
{if $ENV.prefs.show_record_tabs}
45-
<div class="tabs_wrapper">
83+
<div class="tabs_wrapper desktop">
4684

4785
<nav role="navigation" class="table_tabs">
48-
{record_tabs mincount=2 id="record_tabs" id_prefix="record-tabs-" class="contentViews" selected_action=$ENV.mode}
86+
{if $ENV.record and $ENV.record->getTableAttribute('no_view_tab')}
87+
{record_tabs mincount=2 id="record_tabs" id_prefix="record-tabs-" class="contentViews" selected_action=$ENV.mode exclude="view"}
88+
{else}
89+
{record_tabs mincount=2 id="record_tabs" id_prefix="record-tabs-" class="contentViews" selected_action=$ENV.mode}
90+
91+
{/if}
4992
</nav>
5093

5194
{actions var="menus" category="record_actions"}
@@ -59,6 +102,19 @@ <h2 class="dataface-record-title">{if $ENV.record}<span class="dataface-current-
59102
<div style="height:0px;padding:0;margin:0;clear:both"></div>
60103
</div>
61104

105+
<div class="tabs_wrapper mobile">
106+
107+
<nav role="navigation" class="table_tabs">
108+
{if $ENV.record and $ENV.record->getTableAttribute('no_view_tab')}
109+
{record_tabs exclude="edit view" mincount=2 id="record_tabs" id_prefix="mobile-record-tabs-" class="contentViews" selected_action=$ENV.mode}
110+
{else}
111+
{record_tabs exclude="edit" mincount=2 id="record_tabs" id_prefix="mobile-record-tabs-" class="contentViews" selected_action=$ENV.mode}
112+
{/if}
113+
</nav>
114+
115+
116+
<div style="height:0px;padding:0;margin:0;clear:both"></div>
117+
</div>
62118

63119

64120

Dataface/templates/Dataface_View_Record.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<tr>
8383

8484
<td colspan="2" id="dataface-sections-top-column">
85-
85+
{if false}
8686
<div class="dataface-sections-top {if $ENV.prefs.hide_record_view_logo}dataface-sections-top-no-logo{/if}">
8787
<h3 class="dataface-record-view-title">{$record->getTitle()|escape}</h3>
8888
<script>{literal}
@@ -103,6 +103,7 @@ <h3 class="dataface-record-view-title">{$record->getTitle()|escape}</h3>
103103

104104

105105
</div>
106+
{/if}
106107
</td>
107108
</tr>
108109
{/if}

0 commit comments

Comments
 (0)