Skip to content

Commit

Permalink
Added icon media source and file selection + fields in separated wind…
Browse files Browse the repository at this point in the history
…ow tab
  • Loading branch information
Bert Oost committed May 6, 2014
1 parent 27e02d9 commit 35c3a1a
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 60 deletions.
4 changes: 4 additions & 0 deletions _bootstrap/index.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
$manager->createObjectContainer($oC);
}

$manager->alterField('qsbButton', 'icon');
$manager->addField('qsbButton', 'icon_ms', array('after' => 'icon'));
$manager->addField('qsbButton', 'icon_file', array('after' => 'icon_ms'));

if (isset($_GET['loadIcons'])) {
echo "Loading icons..\n";

Expand Down
2 changes: 1 addition & 1 deletion _build/build.schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
define('PKG_NAME', 'QuickstartButtons');
define('PKG_NAME_LOWER', strtolower(PKG_NAME));

require_once dirname(__FILE__).'/build.config.php';
require_once dirname(dirname(__FILE__)) . '/config.core.php';
include_once MODX_CORE_PATH . 'model/modx/modx.class.php';

$modx = new modX();
Expand Down
9 changes: 8 additions & 1 deletion _build/resolvers/resolve.dbchanges.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

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

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

$manager->addField('qsbButton', 'action_props', array('after' => 'action_id')); // since 1.0.1
// since 1.0.1
$manager->addField('qsbButton', 'action_props', array('after' => 'action_id'));

// since 1.1.0
$manager->alterField('qsbButton', 'icon');
$manager->addField('qsbButton', 'icon_ms', array('after' => 'icon'));
$manager->addField('qsbButton', 'icon_file', array('after' => 'icon_ms'));

// set back console logging
$modx->setLogLevel($oldLogLevel);
Expand Down
2 changes: 1 addition & 1 deletion assets/components/quickstartbuttons/css/mgr.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ i.icon {
display: inline-block;
width: 16px;
height: 16px;
background-size: 31px;
background-size: 100%;
background-repeat: no-repeat;
background-position: left center;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ QuickstartButtons.grid.Buttons = function(config) {
,save_action: 'mgr/buttons/updateFromGrid'
,autosave: true

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

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

var iconCls = (!Ext.isEmpty(r.iconcls) ? r.iconcls : 'fa-chevron-right');
return '<i class="fa fa-larger ' + iconCls + '"></i> ' + v;
return '<i class="fa fa-larger ' + r.iconcls + '"></i> ' + v;
}
,renderYNfield: function(v,md,rec,ri,ci,s,g) {
var r = s.getAt(ri).data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
QuickstartButtons.window.CreateUpdateButton = function(config) {
config = config || {};
this.ident = config.ident || Ext.id();

console.log(config);
Ext.applyIf(config,{
title: _('quickstartbuttons.sets.update')
title: _('quickstartbuttons.buttons.create')
,cls: 'quickstartbuttons-window-vtabs'
,bodyCssClass: 'window-vtabs'
,url: QuickstartButtons.config.connector_url
,baseParams: {
action: ((config.isUpdate) ? 'mgr/buttons/update' : 'mgr/buttons/create')
,set: config.setId || config.record.set
,set: ((config.isUpdate) ? config.record.set : config.setId)
}
,width: 650
,resizable: false
Expand Down Expand Up @@ -39,33 +39,11 @@ QuickstartButtons.window.CreateUpdateButton = function(config) {
title: _('quickstartbuttons.general')
,layout: 'form'
,items: [{
layout: 'column'
,border: false
,defaults: { msgTarget: 'under' ,border: false }
,items: [{
layout: 'form'
,columnWidth: .5
,defaults: { msgTarget: 'under' ,border: false }
,items: [{
xtype: 'textfield'
,fieldLabel: _('quickstartbuttons.buttons.text')
,name: 'text'
,anchor: '100%'
,allowBlank: false
}]
},{
layout: 'form'
,columnWidth: .5
,defaults: { msgTarget: 'under' ,border: false }
,items: [{
xtype: 'quickstartbuttons-combo-icons'
,fieldLabel: _('quickstartbuttons.buttons.icon')
,name: 'icon'
,anchor: '100%'
,allowBlank: false
,selected: config.record.icon
}]
}]
xtype: 'textfield'
,fieldLabel: _('quickstartbuttons.buttons.text')
,name: 'text'
,anchor: '100%'
,allowBlank: false
},{
xtype: 'textarea'
,fieldLabel: _('quickstartbuttons.buttons.description')
Expand Down Expand Up @@ -100,6 +78,59 @@ QuickstartButtons.window.CreateUpdateButton = function(config) {
}]
}]
}]
},{
title: _('quickstartbuttons.buttons.icon')
,layout: 'form'
,items: [/*{
html: '<p>' + _('quickstartbuttons.buttons.icon_desc') + '</p><br/>'
,border: false
},*/{
xtype: 'quickstartbuttons-combo-icons'
,name: 'icon'
,fieldLabel: _('quickstartbuttons.buttons.icon.preset')
,anchor: '100%'
,allowBlank: true
,selected: config.record.icon
},{
html: '<br/>'
,border: false
},{
html: '----- ' + _('quickstartbuttons.buttons.icon.or') + ' -----'
,border: false
,bodyStyle: 'text-align:center;'
},{
html: '<br/>'
,border: false
},{
xtype: 'modx-combo-source'
,id: 'quickstartbuttons-button-icon-ms-'+this.ident
,name: 'icon_ms'
,hiddenName: 'icon_ms'
,fieldLabel: _('quickstartbuttons.buttons.icon.ms')
,anchor: '100%'
,allowBlank: true
,listeners: {
'select': { fn: function(cb,rec,idx) {
var fileFld = Ext.getCmp('quickstartbuttons-button-icon-msbrowse-'+this.ident);
fileFld.config.source = rec.id;
fileFld.browser = null; // to make the browser load again
fileFld.setValue('');
fileFld.setDisabled(false);
} ,scope: this }
,scope: this
}
},{
xtype: 'modx-combo-browser'
,id: 'quickstartbuttons-button-icon-msbrowse-'+this.ident
,name: 'icon_file'
,hiddenName: 'icon_file'
,fieldLabel: _('quickstartbuttons.buttons.icon.select')
,anchor: '100%'
,allowBlank: true
,disabled: ((config.isUpdate && !Ext.isEmpty(config.record.icon_ms)) ? false : true)
,hideSourceCombo: true
,allowedFileTypes: 'png,jpg,jpeg,gif,bmp,tiff'
}]
},{
title: _('quickstartbuttons.buttons.link')
,layout: 'form'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<li>
<a href="[[+href:isempty=`#`]]" [[+handler:notempty=`onclick="[[+handler]] return false;"`]] [[+newwindow:notempty=`target="_blank"`]] title="[[+text]]">
<div>
<i class="fa fa-3x [[+iconcls:isempty=`fa-chevron-right`]] icon" [[+iconpath:notempty=`style="background-image: url([[+iconpath]]);"`]]></i>
<i class="[[+iconcls:notempty=`fa fa-3x [[+iconcls]]`]] icon" [[+iconpath:notempty=`style="background-image: url([[+iconpath]]);"`]]></i>
<span>
[[+text]]<br/>
<em>[[+description]]</em>
Expand Down
7 changes: 6 additions & 1 deletion core/components/quickstartbuttons/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@
$_lang['quickstartbuttons.buttons_desc'] = "Below you will find the buttons configured in this set.";
$_lang['quickstartbuttons.buttons.create'] = "Add new button";

$_lang['quickstartbuttons.buttons.icon'] = "Button Icon";
$_lang['quickstartbuttons.buttons.text'] = "Button Text";
$_lang['quickstartbuttons.buttons.description'] = "Description";
$_lang['quickstartbuttons.buttons.ranking'] = "Ranking";
$_lang['quickstartbuttons.buttons.active'] = "Active";

$_lang['quickstartbuttons.buttons.icon'] = "Icon";
$_lang['quickstartbuttons.buttons.icon.preset'] = "Search & choose a preset icon";
$_lang['quickstartbuttons.buttons.icon.or'] = "Or select a custom icon below";
$_lang['quickstartbuttons.buttons.icon.ms'] = "The Media Source to search icons for";
$_lang['quickstartbuttons.buttons.icon.select'] = "Select an icon from Media Source";

$_lang['quickstartbuttons.buttons.link'] = "Link";
$_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.";
$_lang['quickstartbuttons.buttons.link.action'] = "Systems Action";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getDashboardButtons() {
$idx = 1;
foreach($buttons as $button) {

/** @var qsbButton $button */
$phs = $button->toArray();
$phs['idx'] = $idx;
$phs['href'] = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
'extends' => 'xPDOSimpleObject',
'fields' =>
array (
'set' => 0,
'set' => NULL,
'icon' => 0,
'icon_ms' => 0,
'icon_file' => NULL,
'text' => NULL,
'description' => '',
'action_id' => 0,
Expand All @@ -26,18 +28,34 @@
'precision' => '11',
'phptype' => 'integer',
'null' => false,
'default' => 0,
'index' => 'index',
),
'icon' =>
array (
'dbtype' => 'int',
'precision' => '11',
'phptype' => 'integer',
'null' => false,
'null' => true,
'default' => 0,
'index' => 'index',
),
'icon_ms' =>
array (
'dbtype' => 'int',
'precision' => '11',
'phptype' => 'integer',
'null' => true,
'default' => 0,
'index' => 'index',
),
'icon_file' =>
array (
'dbtype' => 'varchar',
'precision' => '255',
'phptype' => 'string',
'null' => true,
'default' => NULL,
),
'text' =>
array (
'dbtype' => 'varchar',
Expand Down Expand Up @@ -135,5 +153,13 @@
'cardinality' => 'one',
'owner' => 'foreign',
),
'MediaSource' =>
array (
'class' => 'modMediaSource',
'local' => 'icon_ms',
'foreign' => 'id',
'cardinality' => 'one',
'owner' => 'foreign',
),
),
);
65 changes: 64 additions & 1 deletion core/components/quickstartbuttons/model/quickstartbuttons/qsbbutton.class.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,65 @@
<?php
class qsbButton extends xPDOSimpleObject {}

class qsbButton extends xPDOSimpleObject {

/**
* {inheritdoc}
* @param string $keyPrefix
* @param bool $rawValues
* @param bool $excludeLazy
* @param bool $includeRelated
* @return array
*/
public function toArray($keyPrefix='', $rawValues=false, $excludeLazy=false, $includeRelated=false) {
$arr = parent::toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated);

// figure out the icon
$icon = $this->getIcon();
if(!empty($icon) && is_array($icon)) {
switch($icon['type']) {
case 'custom':
$arr['iconcls'] = '';
$arr['iconpath'] = $icon['value'];
break;
case 'preset':
default:
$arr['iconcls'] = $icon['value'];
$arr['iconpath'] = '';
break;
}
}

return $arr;
}

/**
* Figures out the icon to use
* @return array
*/
public function getIcon() {

$icon_ms = $this->get('icon_ms');
$icon_file = $this->get('icon_file');
if(!empty($icon_ms) && !empty($icon_file)) {

/** @var modMediaSource|modFileMediaSource $ms */
$ms = $this->getOne('MediaSource');
if(!empty($ms) && is_object($ms)) {
$ms->initialize();

$iconUrl = $ms->getObjectUrl($icon_file);
if(!empty($iconUrl)) {
return array('type' => 'custom', 'value' => $iconUrl);
}
}
}

/** @var qsbIcon $icon - Fallback */
$icon = $this->getOne('Icon');
if(!empty($icon) && is_object($icon)) {
return array('type' => 'preset', 'value' => $icon->get('class'));
}

return array('type' => 'preset', 'value' => 'fa-chevron-right');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
</object>

<object class="qsbButton" table="quickstartbuttons_buttons" extends="xPDOSimpleObject">
<field key="set" dbtype="int" precision="11" phptype="integer" null="false" default="0" index="index" />
<field key="icon" dbtype="int" precision="11" phptype="integer" null="false" default="" index="index" />
<field key="set" dbtype="int" precision="11" phptype="integer" null="false" index="index" />
<field key="icon" dbtype="int" precision="11" phptype="integer" null="true" default="NULL" index="index" />
<field key="icon_ms" dbtype="int" precision="11" phptype="integer" null="true" default="NULL" index="index" />
<field key="icon_file" dbtype="varchar" precision="255" phptype="string" null="true" default="NULL" />
<field key="text" dbtype="varchar" precision="255" phptype="string" null="false" index="index" />
<field key="description" dbtype="text" phptype="string" null="false" default="" />

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

<object class="qsbIcon" table="quickstartbuttons_icons" extends="xPDOSimpleObject">
Expand Down
Loading

0 comments on commit 35c3a1a

Please sign in to comment.