Skip to content

Commit 35c3a1a

Browse files
author
Bert Oost
committed
Added icon media source and file selection + fields in separated window tab
1 parent 27e02d9 commit 35c3a1a

File tree

15 files changed

+210
-60
lines changed

15 files changed

+210
-60
lines changed

_bootstrap/index.php

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
$manager->createObjectContainer($oC);
136136
}
137137

138+
$manager->alterField('qsbButton', 'icon');
139+
$manager->addField('qsbButton', 'icon_ms', array('after' => 'icon'));
140+
$manager->addField('qsbButton', 'icon_file', array('after' => 'icon_ms'));
141+
138142
if (isset($_GET['loadIcons'])) {
139143
echo "Loading icons..\n";
140144

_build/build.schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
define('PKG_NAME', 'QuickstartButtons');
44
define('PKG_NAME_LOWER', strtolower(PKG_NAME));
55

6-
require_once dirname(__FILE__).'/build.config.php';
6+
require_once dirname(dirname(__FILE__)) . '/config.core.php';
77
include_once MODX_CORE_PATH . 'model/modx/modx.class.php';
88

99
$modx = new modX();

_build/resolvers/resolve.dbchanges.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
/** @var xPDO|modX $modx */
34
$modx =& $object->xpdo;
45

56
switch($options[xPDOTransport::PACKAGE_ACTION]) {
@@ -16,7 +17,13 @@
1617
$oldLogLevel = $modx->getLogLevel();
1718
$modx->setLogLevel(0);
1819

19-
$manager->addField('qsbButton', 'action_props', array('after' => 'action_id')); // since 1.0.1
20+
// since 1.0.1
21+
$manager->addField('qsbButton', 'action_props', array('after' => 'action_id'));
22+
23+
// since 1.1.0
24+
$manager->alterField('qsbButton', 'icon');
25+
$manager->addField('qsbButton', 'icon_ms', array('after' => 'icon'));
26+
$manager->addField('qsbButton', 'icon_file', array('after' => 'icon_ms'));
2027

2128
// set back console logging
2229
$modx->setLogLevel($oldLogLevel);

assets/components/quickstartbuttons/css/mgr.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ i.icon {
145145
display: inline-block;
146146
width: 16px;
147147
height: 16px;
148-
background-size: 31px;
148+
background-size: 100%;
149149
background-repeat: no-repeat;
150150
background-position: left center;
151151
}

assets/components/quickstartbuttons/js/mgr/widgets/buttons.grid.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ QuickstartButtons.grid.Buttons = function(config) {
88
,save_action: 'mgr/buttons/updateFromGrid'
99
,autosave: true
1010

11-
,fields: ['id','set','icon','iconcls','iconpath','text','description','ranking','action_id','action_props','handler','link','newwindow','active']
11+
,fields: ['id','set','icon','icon_ms','icon_file','iconcls','iconpath','text','description','ranking','action_id','action_props','handler','link','newwindow','active']
1212
,paging: true
1313
,pageSize: 6
1414
,remoteSort: true
@@ -119,11 +119,10 @@ Ext.extend(QuickstartButtons.grid.Buttons, MODx.grid.Grid, {
119119
var r = s.getAt(ri).data;
120120

121121
if(!Ext.isEmpty(r.iconpath)) {
122-
return '<i class="icon ' + (!Ext.isEmpty(r.iconcls) ? r.iconcls : '') + '" style="background-image: url(' + r.iconpath + ')"></i> ' + v;
122+
return '<i class="icon" style="background-image: url(' + r.iconpath + ')"></i> ' + v;
123123
}
124124

125-
var iconCls = (!Ext.isEmpty(r.iconcls) ? r.iconcls : 'fa-chevron-right');
126-
return '<i class="fa fa-larger ' + iconCls + '"></i> ' + v;
125+
return '<i class="fa fa-larger ' + r.iconcls + '"></i> ' + v;
127126
}
128127
,renderYNfield: function(v,md,rec,ri,ci,s,g) {
129128
var r = s.getAt(ri).data;

assets/components/quickstartbuttons/js/mgr/widgets/buttons.windows.js

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
QuickstartButtons.window.CreateUpdateButton = function(config) {
44
config = config || {};
55
this.ident = config.ident || Ext.id();
6-
6+
console.log(config);
77
Ext.applyIf(config,{
8-
title: _('quickstartbuttons.sets.update')
8+
title: _('quickstartbuttons.buttons.create')
99
,cls: 'quickstartbuttons-window-vtabs'
1010
,bodyCssClass: 'window-vtabs'
1111
,url: QuickstartButtons.config.connector_url
1212
,baseParams: {
1313
action: ((config.isUpdate) ? 'mgr/buttons/update' : 'mgr/buttons/create')
14-
,set: config.setId || config.record.set
14+
,set: ((config.isUpdate) ? config.record.set : config.setId)
1515
}
1616
,width: 650
1717
,resizable: false
@@ -39,33 +39,11 @@ QuickstartButtons.window.CreateUpdateButton = function(config) {
3939
title: _('quickstartbuttons.general')
4040
,layout: 'form'
4141
,items: [{
42-
layout: 'column'
43-
,border: false
44-
,defaults: { msgTarget: 'under' ,border: false }
45-
,items: [{
46-
layout: 'form'
47-
,columnWidth: .5
48-
,defaults: { msgTarget: 'under' ,border: false }
49-
,items: [{
50-
xtype: 'textfield'
51-
,fieldLabel: _('quickstartbuttons.buttons.text')
52-
,name: 'text'
53-
,anchor: '100%'
54-
,allowBlank: false
55-
}]
56-
},{
57-
layout: 'form'
58-
,columnWidth: .5
59-
,defaults: { msgTarget: 'under' ,border: false }
60-
,items: [{
61-
xtype: 'quickstartbuttons-combo-icons'
62-
,fieldLabel: _('quickstartbuttons.buttons.icon')
63-
,name: 'icon'
64-
,anchor: '100%'
65-
,allowBlank: false
66-
,selected: config.record.icon
67-
}]
68-
}]
42+
xtype: 'textfield'
43+
,fieldLabel: _('quickstartbuttons.buttons.text')
44+
,name: 'text'
45+
,anchor: '100%'
46+
,allowBlank: false
6947
},{
7048
xtype: 'textarea'
7149
,fieldLabel: _('quickstartbuttons.buttons.description')
@@ -100,6 +78,59 @@ QuickstartButtons.window.CreateUpdateButton = function(config) {
10078
}]
10179
}]
10280
}]
81+
},{
82+
title: _('quickstartbuttons.buttons.icon')
83+
,layout: 'form'
84+
,items: [/*{
85+
html: '<p>' + _('quickstartbuttons.buttons.icon_desc') + '</p><br/>'
86+
,border: false
87+
},*/{
88+
xtype: 'quickstartbuttons-combo-icons'
89+
,name: 'icon'
90+
,fieldLabel: _('quickstartbuttons.buttons.icon.preset')
91+
,anchor: '100%'
92+
,allowBlank: true
93+
,selected: config.record.icon
94+
},{
95+
html: '<br/>'
96+
,border: false
97+
},{
98+
html: '----- ' + _('quickstartbuttons.buttons.icon.or') + ' -----'
99+
,border: false
100+
,bodyStyle: 'text-align:center;'
101+
},{
102+
html: '<br/>'
103+
,border: false
104+
},{
105+
xtype: 'modx-combo-source'
106+
,id: 'quickstartbuttons-button-icon-ms-'+this.ident
107+
,name: 'icon_ms'
108+
,hiddenName: 'icon_ms'
109+
,fieldLabel: _('quickstartbuttons.buttons.icon.ms')
110+
,anchor: '100%'
111+
,allowBlank: true
112+
,listeners: {
113+
'select': { fn: function(cb,rec,idx) {
114+
var fileFld = Ext.getCmp('quickstartbuttons-button-icon-msbrowse-'+this.ident);
115+
fileFld.config.source = rec.id;
116+
fileFld.browser = null; // to make the browser load again
117+
fileFld.setValue('');
118+
fileFld.setDisabled(false);
119+
} ,scope: this }
120+
,scope: this
121+
}
122+
},{
123+
xtype: 'modx-combo-browser'
124+
,id: 'quickstartbuttons-button-icon-msbrowse-'+this.ident
125+
,name: 'icon_file'
126+
,hiddenName: 'icon_file'
127+
,fieldLabel: _('quickstartbuttons.buttons.icon.select')
128+
,anchor: '100%'
129+
,allowBlank: true
130+
,disabled: ((config.isUpdate && !Ext.isEmpty(config.record.icon_ms)) ? false : true)
131+
,hideSourceCombo: true
132+
,allowedFileTypes: 'png,jpg,jpeg,gif,bmp,tiff'
133+
}]
103134
},{
104135
title: _('quickstartbuttons.buttons.link')
105136
,layout: 'form'

core/components/quickstartbuttons/elements/chunks/dashboard/item.chunk.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<li>
22
<a href="[[+href:isempty=`#`]]" [[+handler:notempty=`onclick="[[+handler]] return false;"`]] [[+newwindow:notempty=`target="_blank"`]] title="[[+text]]">
33
<div>
4-
<i class="fa fa-3x [[+iconcls:isempty=`fa-chevron-right`]] icon" [[+iconpath:notempty=`style="background-image: url([[+iconpath]]);"`]]></i>
4+
<i class="[[+iconcls:notempty=`fa fa-3x [[+iconcls]]`]] icon" [[+iconpath:notempty=`style="background-image: url([[+iconpath]]);"`]]></i>
55
<span>
66
[[+text]]<br/>
77
<em>[[+description]]</em>

core/components/quickstartbuttons/lexicon/en/default.inc.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@
3333
$_lang['quickstartbuttons.buttons_desc'] = "Below you will find the buttons configured in this set.";
3434
$_lang['quickstartbuttons.buttons.create'] = "Add new button";
3535

36-
$_lang['quickstartbuttons.buttons.icon'] = "Button Icon";
3736
$_lang['quickstartbuttons.buttons.text'] = "Button Text";
3837
$_lang['quickstartbuttons.buttons.description'] = "Description";
3938
$_lang['quickstartbuttons.buttons.ranking'] = "Ranking";
4039
$_lang['quickstartbuttons.buttons.active'] = "Active";
4140

41+
$_lang['quickstartbuttons.buttons.icon'] = "Icon";
42+
$_lang['quickstartbuttons.buttons.icon.preset'] = "Search & choose a preset icon";
43+
$_lang['quickstartbuttons.buttons.icon.or'] = "Or select a custom icon below";
44+
$_lang['quickstartbuttons.buttons.icon.ms'] = "The Media Source to search icons for";
45+
$_lang['quickstartbuttons.buttons.icon.select'] = "Select an icon from Media Source";
46+
4247
$_lang['quickstartbuttons.buttons.link'] = "Link";
4348
$_lang['quickstartbuttons.buttons.link_desc'] = "Below you can configure the action for the button. The priority of the link to use is from top down. This means that if you set the first, the second and third will be ignored and if you leave the first empty, set the second, the third one will be ignored etc.";
4449
$_lang['quickstartbuttons.buttons.link.action'] = "Systems Action";

core/components/quickstartbuttons/model/quickstartbuttons/dashboardwidget.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function getDashboardButtons() {
6363
$idx = 1;
6464
foreach($buttons as $button) {
6565

66+
/** @var qsbButton $button */
6667
$phs = $button->toArray();
6768
$phs['idx'] = $idx;
6869
$phs['href'] = '';

core/components/quickstartbuttons/model/quickstartbuttons/mysql/qsbbutton.map.inc.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
'extends' => 'xPDOSimpleObject',
77
'fields' =>
88
array (
9-
'set' => 0,
9+
'set' => NULL,
1010
'icon' => 0,
11+
'icon_ms' => 0,
12+
'icon_file' => NULL,
1113
'text' => NULL,
1214
'description' => '',
1315
'action_id' => 0,
@@ -26,18 +28,34 @@
2628
'precision' => '11',
2729
'phptype' => 'integer',
2830
'null' => false,
29-
'default' => 0,
3031
'index' => 'index',
3132
),
3233
'icon' =>
3334
array (
3435
'dbtype' => 'int',
3536
'precision' => '11',
3637
'phptype' => 'integer',
37-
'null' => false,
38+
'null' => true,
39+
'default' => 0,
40+
'index' => 'index',
41+
),
42+
'icon_ms' =>
43+
array (
44+
'dbtype' => 'int',
45+
'precision' => '11',
46+
'phptype' => 'integer',
47+
'null' => true,
3848
'default' => 0,
3949
'index' => 'index',
4050
),
51+
'icon_file' =>
52+
array (
53+
'dbtype' => 'varchar',
54+
'precision' => '255',
55+
'phptype' => 'string',
56+
'null' => true,
57+
'default' => NULL,
58+
),
4159
'text' =>
4260
array (
4361
'dbtype' => 'varchar',
@@ -135,5 +153,13 @@
135153
'cardinality' => 'one',
136154
'owner' => 'foreign',
137155
),
156+
'MediaSource' =>
157+
array (
158+
'class' => 'modMediaSource',
159+
'local' => 'icon_ms',
160+
'foreign' => 'id',
161+
'cardinality' => 'one',
162+
'owner' => 'foreign',
163+
),
138164
),
139165
);
Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
11
<?php
2-
class qsbButton extends xPDOSimpleObject {}
2+
3+
class qsbButton extends xPDOSimpleObject {
4+
5+
/**
6+
* {inheritdoc}
7+
* @param string $keyPrefix
8+
* @param bool $rawValues
9+
* @param bool $excludeLazy
10+
* @param bool $includeRelated
11+
* @return array
12+
*/
13+
public function toArray($keyPrefix='', $rawValues=false, $excludeLazy=false, $includeRelated=false) {
14+
$arr = parent::toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated);
15+
16+
// figure out the icon
17+
$icon = $this->getIcon();
18+
if(!empty($icon) && is_array($icon)) {
19+
switch($icon['type']) {
20+
case 'custom':
21+
$arr['iconcls'] = '';
22+
$arr['iconpath'] = $icon['value'];
23+
break;
24+
case 'preset':
25+
default:
26+
$arr['iconcls'] = $icon['value'];
27+
$arr['iconpath'] = '';
28+
break;
29+
}
30+
}
31+
32+
return $arr;
33+
}
34+
35+
/**
36+
* Figures out the icon to use
37+
* @return array
38+
*/
39+
public function getIcon() {
40+
41+
$icon_ms = $this->get('icon_ms');
42+
$icon_file = $this->get('icon_file');
43+
if(!empty($icon_ms) && !empty($icon_file)) {
44+
45+
/** @var modMediaSource|modFileMediaSource $ms */
46+
$ms = $this->getOne('MediaSource');
47+
if(!empty($ms) && is_object($ms)) {
48+
$ms->initialize();
49+
50+
$iconUrl = $ms->getObjectUrl($icon_file);
51+
if(!empty($iconUrl)) {
52+
return array('type' => 'custom', 'value' => $iconUrl);
53+
}
54+
}
55+
}
56+
57+
/** @var qsbIcon $icon - Fallback */
58+
$icon = $this->getOne('Icon');
59+
if(!empty($icon) && is_object($icon)) {
60+
return array('type' => 'preset', 'value' => $icon->get('class'));
61+
}
62+
63+
return array('type' => 'preset', 'value' => 'fa-chevron-right');
64+
}
65+
}

core/components/quickstartbuttons/model/schema/quickstartbuttons.mysql.schema.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
</object>
2727

2828
<object class="qsbButton" table="quickstartbuttons_buttons" extends="xPDOSimpleObject">
29-
<field key="set" dbtype="int" precision="11" phptype="integer" null="false" default="0" index="index" />
30-
<field key="icon" dbtype="int" precision="11" phptype="integer" null="false" default="" index="index" />
29+
<field key="set" dbtype="int" precision="11" phptype="integer" null="false" index="index" />
30+
<field key="icon" dbtype="int" precision="11" phptype="integer" null="true" default="NULL" index="index" />
31+
<field key="icon_ms" dbtype="int" precision="11" phptype="integer" null="true" default="NULL" index="index" />
32+
<field key="icon_file" dbtype="varchar" precision="255" phptype="string" null="true" default="NULL" />
3133
<field key="text" dbtype="varchar" precision="255" phptype="string" null="false" index="index" />
3234
<field key="description" dbtype="text" phptype="string" null="false" default="" />
3335

@@ -43,6 +45,7 @@
4345
<aggregate alias="Set" class="qsbSet" local="profile" foreign="id" cardinality="one" owner="foreign" />
4446
<aggregate alias="Icon" class="qsbIcon" local="icon" foreign="id" cardinality="one" owner="foreign" />
4547
<aggregate alias="Action" class="modAction" local="action_id" foreign="id" cardinality="one" owner="foreign" />
48+
<aggregate alias="MediaSource" class="modMediaSource" local="icon_ms" foreign="id" cardinality="one" owner="foreign" />
4649
</object>
4750

4851
<object class="qsbIcon" table="quickstartbuttons_icons" extends="xPDOSimpleObject">

0 commit comments

Comments
 (0)