Skip to content

Commit 594f8b1

Browse files
committed
Added support for filtering on mobile
1 parent 3d837c0 commit 594f8b1

20 files changed

+1325
-17
lines changed

Dataface/Application.php

+14
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,20 @@ function &conf(){
13401340
}
13411341

13421342

1343+
/**
1344+
* Returns the application version as reported in the version.txt file. This only
1345+
* returns the build version, which is the 2nd component of the version in version.txt
1346+
* Value is returned as an int.
1347+
*
1348+
* If no version is supplied, this will return 0
1349+
*
1350+
* @return int The application version number.
1351+
*/
1352+
function getApplicationVersion() {
1353+
return df_get_file_system_version();
1354+
1355+
}
1356+
13431357
/**
13441358
* @brief Get the mysql major version number of MySQL.
13451359
* returns int

Dataface/CSSTool.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public function import($path){
5151

5252

5353
public function getURL(){
54+
$app = Dataface_Application::getInstance();
5455
$this->compile();
55-
return DATAFACE_SITE_HREF.'?-action=css&--id='.$this->generateCacheKeyForScripts(array_keys($this->stylesheets));
56+
return DATAFACE_SITE_HREF.'?v='.$app->getApplicationVersion().'&-action=css&--id='.$this->generateCacheKeyForScripts(array_keys($this->stylesheets));
5657
}
5758

5859
public function getIncluded(){

Dataface/JavascriptTool.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ public function which($script){
259259
*/
260260
public function getURL(){
261261
$this->compile();
262-
return DATAFACE_SITE_HREF.'?-action=js&--id='.$this->generateCacheKeyForScripts(array_keys($this->scripts));
262+
$app = Dataface_Application::getInstance();
263+
return DATAFACE_SITE_HREF .
264+
'?v='.$app->getApplicationVersion().'&-action=js&--id=' .
265+
$this->generateCacheKeyForScripts(array_keys($this->scripts));
263266
}
264267

265268
/**

Dataface/ResultList.php

+31-6
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ function __construct( $tablename, $db='', $columns=array(), $query=array()){
113113
$this->_resultSet =& Dataface_QueryTool::loadResult($tablename, $db, $query);
114114

115115
}
116-
function Dataface_ResultList($tablename, $db='', $columns=array(), $query=array()) { self::__construct($tablename, $db, $columns, $query); }
116+
function Dataface_ResultList($tablename, $db='', $columns=array(), $query=array()) {
117+
self::__construct($tablename, $db, $columns, $query);
118+
}
117119

118120
function renderCell(&$record, $fieldname){
119121
$del =& $record->_table->getDelegate();
@@ -139,7 +141,10 @@ function renderCell(&$record, $fieldname){
139141
if ( $fulltext ){
140142
$fulltext = 'data-fulltext="'.df_escape($fulltext).'"';
141143
}
142-
if ( !@$field['noEditInListView'] and @$field['noLinkFromListView'] and $record->checkPermission('edit', array('field'=>$fieldname) ) ){
144+
if ( !@$field['noEditInListView'] and
145+
@$field['noLinkFromListView'] and
146+
$record->checkPermission('edit', array('field'=>$fieldname) ) ) {
147+
143148
$recid = $record->getId();
144149

145150
$out = '<span df:showlink="1" df:id="'.$recid.'#'.$fieldname.'" class="df__editable" '.$fulltext.'>'.df_escape($out).'</span>';
@@ -163,7 +168,7 @@ function renderRowHeader($tablename=null){
163168
return null;
164169
}
165170

166-
function getTfootContent(){
171+
function getTfootContent(){
167172
if ( !isset($tablename) ) $tablename = $this->_table->tablename;
168173
$del =& $this->_table->getDelegate();
169174
if ( isset($del) and method_exists($del, 'renderRowFooterTemplate') ){
@@ -175,7 +180,7 @@ function getTfootContent(){
175180
return $appdel->renderRowFooterTemplate($tablename);
176181
}
177182
return '';
178-
}
183+
}
179184

180185
function renderRow(&$record, $mode = 'desktop'){
181186
$del =& $record->_table->getDelegate();
@@ -202,6 +207,8 @@ function renderRow(&$record, $mode = 'desktop'){
202207
}
203208

204209
}
210+
211+
205212

206213
function &getResults(){
207214
if ( !isset($this->_results) ){
@@ -252,18 +259,36 @@ private function print_actions($actions) {
252259
}
253260

254261
function toHtml($mode = 'all'){
262+
xf_script('xataface/actions/list.js');
255263
import(XFROOT.'Dataface/ActionTool.php');
256264
$mobile = $mode == 'mobile';
257265
$desktop = $mode == 'desktop';
258266
$all = $mode == 'all';
259267
if ($all) {
260-
$this->toHtml('mobile');
261-
return $this->toHtml('desktop') . $this->toHtml('mobile');
268+
//$this->toHtml('mobile');
269+
return $this->toHtml('desktop').$this->toHtml('mobile');
262270
}
263271

272+
273+
264274
$app =& Dataface_Application::getInstance();
265275
$at =& Dataface_ActionTool::getInstance();
266276
$query =& $app->getQuery();
277+
278+
if ($mobile) {
279+
280+
$actions = $at->getActions(['category'=>'mobile_list_settings']);
281+
echo '<div class="mobile-list-settings-wrapper">';
282+
283+
if ( count($actions)>0){
284+
echo ' <div class="mobile-list-settings">';
285+
$this->print_actions($actions);
286+
echo '</div>';
287+
}
288+
289+
echo '</div>';
290+
}
291+
267292
if ( isset( $query['-sort']) ){
268293
$sortcols = explode(',', trim($query['-sort']));
269294
$sort_columns = array();

Dataface/SkinTool.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ function __construct() {
170170
'mode'=>&$app->_query['-mode'],
171171
'language'=>$app->_conf['lang'],
172172
'prefs'=>&$app->prefs,
173-
'search'=>@$_REQUEST['-search']
173+
'search'=>@$_REQUEST['-search'],
174+
'APPLICATION_VERSION' => $app->getApplicationVersion()
174175

175176
);
176177

Dataface/templates/Dataface_Main_Template.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
3434
<title>{define_slot name="html_title"}{$ENV.APPLICATION_OBJECT->getPageTitle()|escape}{/define_slot}</title>
3535
<meta name="viewport" content="width=device-width, initial-scale=1.0">
36-
{define_slot name="dataface_stylesheets"}<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/plone.css"/>
37-
<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/css/xataface/sidemenu.css"/>
38-
<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/css/xataface/fab.css"/>{/define_slot}
36+
{define_slot name="dataface_stylesheets"}<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/plone.css?v={$ENV.APPLICATION_VERSION}"/>
37+
<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/css/xataface/sidemenu.css?v={$ENV.APPLICATION_VERSION}"/>
38+
<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/css/xataface/fab.css?v={$ENV.APPLICATION_VERSION}"/>{/define_slot}
3939
{define_slot name="dataface_rss_links"}
4040
<link rel="alternate" href="{$ENV.APPLICATION_OBJECT->url('-action=feed&--format=RSS2.0')|escape}"
4141
title="RSS 2.0" type="application/rss+xml" />
@@ -55,11 +55,11 @@
5555
//--></script>
5656

5757
<script type="text/javascript"
58-
src="{$ENV.DATAFACE_URL|escape}/plone_javascripts.js">
58+
src="{$ENV.DATAFACE_URL|escape}/plone_javascripts.js?v={$ENV.APPLICATION_VERSION}">
5959
</script>
6060
{if $ENV.APPLICATION.usage_mode == 'edit'}
6161
<script type="text/javascript"
62-
src="{$ENV.DATAFACE_URL|escape}/js/editable.js">
62+
src="{$ENV.DATAFACE_URL|escape}/js/editable.js?v={$ENV.APPLICATION_VERSION}">
6363
</script>
6464
{/if}
6565

@@ -390,7 +390,7 @@ <h5>{translate id="scripts.GLOBAL.HEADING_ERRORS"}Errors{/translate}</h5>
390390

391391
{if $menus|@count>0}
392392

393-
<script type="text/javascript" src="{$ENV.DATAFACE_URL|escape}/js/xataface/fab.js"></script>
393+
<script type="text/javascript" src="{$ENV.DATAFACE_URL|escape}/js/xataface/fab.js?v={$ENV.APPLICATION_VERSION}"></script>
394394
<div class="zoom">
395395
{if $menus|@count < 2}
396396

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/plone.css?v={$ENV.APPLICATION_VERSION}"/>
6+
<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/css/xataface/actions/mobile_filter_dialog.css?v={$ENV.APPLICATION_VERSION}"/>
7+
</head>
8+
<body class='mobile-sort-dialog'>
9+
10+
<h1>Filter</h1>
11+
<ul class='xf-filter-form'>
12+
{foreach from=$searchFields item=field}
13+
<li class='xf-filter-field xf-filter-type-{$field.type|escape}'>
14+
15+
16+
{if $field.type == 'filter'}
17+
<a href='javascript:void(0)' onclick='showOptions(this)'>
18+
<i class='material-icons'>arrow_forward_ios</i>
19+
<span class='xf-filter-label'>{$field.label|escape}</span>
20+
{if $field.value}<span class='xf-filter-value'>: {$field.value|escape}</span>{/if}
21+
22+
</a>
23+
<div class='xf-filter-options' data-field='{$field.fieldDef.name}'>
24+
<div class='dialog-content'>
25+
<h1><span>{$field.label|escape}</span></h1>
26+
<ul class='xf-filter-options-list'>
27+
{foreach from=$field.options item=option}
28+
<li>
29+
30+
<input
31+
onclick='updateFilters(this);'
32+
data-key='{$option.key|escape}'
33+
type='checkbox'
34+
id='{$field.name|escape}-option-{$option.key|escape}'
35+
{if $option.selected}checked{/if}/>
36+
<label for='{$field.name|escape}-option-{$option.key|escape}'>
37+
<span class='xf-filter-option-value'>{$option.value|escape}</span>
38+
{if $option.count}<span class='xf-filter-option-count'>({$option.count|escape})</span>{/if}
39+
</labeL>
40+
</li>
41+
{/foreach}
42+
</ul>
43+
</div>
44+
</div>
45+
{elseif $field.type == 'date-range'}
46+
47+
{elseif $field.type == 'contains'}
48+
49+
{elseif $field.type == 'checkbox'}
50+
51+
{elseif $field.type == 'range'}
52+
53+
{elseif $field.type == 'min'}
54+
55+
{elseif $field.type == 'max'}
56+
57+
{elseif $field.type == 'checkbox'}
58+
59+
{else}
60+
61+
62+
{/if}
63+
64+
</li>
65+
{/foreach}
66+
</ul>
67+
68+
<div class='xf-buttons'>
69+
<button class='xf-apply-btn' onclick='applyFilters()'>Show <span class='num-results'>x</span> Results</button>
70+
</div>
71+
72+
<script>{literal}
73+
74+
var win = window.parent;
75+
var filterSearch = win.location.search;
76+
77+
function showOptions(targetEl) {
78+
var $ = win.jQuery;
79+
var options = $('>.xf-filter-options', $(targetEl).parent());
80+
81+
$(options).addClass('slidein');
82+
win.activeSheet.pushState({
83+
back : function() {
84+
$(options).removeClass('slidein');
85+
},
86+
el : options.get(0)
87+
});
88+
89+
}
90+
91+
function applyFilters() {
92+
if (win.activeSheet) {
93+
win.activeSheet.close();
94+
}
95+
win.jQuery('<div class="spin fillscreen"></div>').appendTo(win.document.body);
96+
win.location.search=filterSearch;
97+
return false;
98+
}
99+
100+
function updateFilters(srcEl) {
101+
var $ = win.jQuery;
102+
var wrapper = $(srcEl).parents('[data-field]').first();
103+
var field = $(wrapper).attr('data-field');
104+
var selectedKeys = [];
105+
var selectedString = '';
106+
$('input[data-key]', wrapper).each(function() {
107+
if (!this.checked) {
108+
return;
109+
}
110+
selectedKeys.push(this.getAttribute('data-key'));
111+
});
112+
if (selectedKeys.length == 0) {
113+
if (filterSearch.indexOf('&'+field+'=') >= 0) {
114+
var re = new RegExp('&'+field+'=[^&]*');
115+
116+
filterSearch = filterSearch.replace(re, '');
117+
updateCounts();
118+
return;
119+
}
120+
}
121+
var selectedString = '=' + selectedKeys.join(' OR =');
122+
if (filterSearch.indexOf('&'+field+'=') >= 0) {
123+
var re = new RegExp('&'+field+'=[^&]*');
124+
125+
filterSearch = filterSearch.replace(re, '');
126+
}
127+
filterSearch += '&'+field+'='+encodeURIComponent(selectedString);
128+
updateCounts();
129+
130+
}
131+
132+
function updateCounts() {
133+
var search = filterSearch;
134+
var $ = win.jQuery;
135+
if (!$ || !$.get) return;
136+
137+
if (search.indexOf('-action=') >= 0) {
138+
search = search.replace(/-action=[^&]*/, '-action=ajax_count_results');
139+
} else {
140+
search += '&-action=ajax_count_results';
141+
}
142+
$.get(search, function(res) {
143+
console.log(res);
144+
if (res && res.found) {
145+
document.querySelector('button.xf-apply-btn > .num-results').innerHTML = ''+res.found;
146+
147+
}
148+
})
149+
}
150+
updateCounts();
151+
{/literal}</script>
152+
</body>
153+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/plone.css"/>
6+
<link rel="stylesheet" type="text/css" href="{$ENV.DATAFACE_URL|escape}/css/xataface/actions/mobile_sort_dialog.css"/>
7+
</head>
8+
<body class='mobile-sort-dialog'>
9+
<h1>Sort</h1>
10+
11+
12+
<ul class='sort-actions'>
13+
{foreach from=$sort_actions item=action}
14+
<li>
15+
<input
16+
name="sort"
17+
type="radio"
18+
id="{$action.name|escape}"
19+
{if $action.selected}checked{/if}
20+
onclick="{$action.onclick|escape}"
21+
22+
/>
23+
<label for="{$action.name|escape}"><span>{$action.label|escape}</span>
24+
{if $action.materialIcon}<i class='material-icons'>{$action.materialIcon|escape}</i>{/if}
25+
</label>
26+
</li>
27+
{/foreach}
28+
</ul>
29+
<script>{literal}
30+
31+
var win = window.parent;
32+
var search = win.location.search;
33+
34+
function setSort(sortVal) {
35+
if (win.activeSheet) {
36+
win.activeSheet.close();
37+
}
38+
search = search.replace(/&-sort=[^&]*/, '');
39+
search = search.replace(/\?-sort=[^&]*/, '?');
40+
search += '&-sort='+encodeURIComponent(sortVal);
41+
42+
win.jQuery('<div class="spin fillscreen"></div>').appendTo(win.document.body);
43+
win.location.search=search;
44+
45+
46+
}
47+
48+
function sortAscending(fieldName) {
49+
setSort(fieldName+' asc');
50+
}
51+
52+
function sortDescending(fieldName) {
53+
setSort(fieldName+" desc");
54+
}
55+
{/literal}</script>
56+
57+
</body>
58+
</html>

0 commit comments

Comments
 (0)