Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions _bootstrap/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
if ($vcPlugin) {
if (!createObject('modPluginEvent', array(
'pluginid' => $vcPlugin->get('id'),
'event' => 'OnHandleRequest',
'event' => 'OnMODXInit',
'priority' => 0,
), array('pluginid','event'), false)) {
echo "Error creating modPluginEvent.\n";
Expand Down Expand Up @@ -140,7 +140,8 @@
/* Create the tables */
$objectContainers = array(
'cgGroup',
'cgSetting'
'cgSetting',
'cgContextValue',
);
echo "Creating tables...\n";
$manager = $modx->getManager();
Expand Down
1 change: 1 addition & 0 deletions _build/build.schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
$objects = array(
'cgSetting',
'cgGroup',
'cgContextValue',
);

foreach ($objects as $object) {
Expand Down
10 changes: 8 additions & 2 deletions _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function getSnippetContent($filename = '') {
/* define version */
define('PKG_NAME','ClientConfig');
define('PKG_NAME_LOWER',strtolower(PKG_NAME));
define('PKG_VERSION','1.4.2');
define('PKG_RELEASE','pl');
define('PKG_VERSION','2.0.0');
define('PKG_RELEASE','dev5');

/* load modx */
require_once dirname(dirname(__FILE__)) . '/config.core.php';
Expand Down Expand Up @@ -152,6 +152,9 @@ function getSnippetContent($filename = '') {
$vehicle->resolve('php',array(
'source' => $sources['resolvers'] . 'tables.resolver.php',
));
$vehicle->resolve('php',array(
'source' => $sources['resolvers'] . 'setupoptions.resolver.php',
));

$modx->log(modX::LOG_LEVEL_INFO,'Packaged in resolvers.'); flush();
$builder->putVehicle($vehicle);
Expand All @@ -161,6 +164,9 @@ function getSnippetContent($filename = '') {
'license' => file_get_contents($sources['docs'] . 'license.txt'),
'readme' => file_get_contents($sources['docs'] . 'readme.txt'),
'changelog' => file_get_contents($sources['docs'] . 'changelog.txt'),
'setup-options' => array(
'source' => $sources['build'].'setup.options.php',
),
));
$modx->log(modX::LOG_LEVEL_INFO,'Packaged in package attributes.'); flush();

Expand Down
1 change: 1 addition & 0 deletions _build/data/transport.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'admin_groups' => 'Administrator',
'clear_cache' => true,
'vertical_tabs' => false,
'context_aware' => false,
'google_fonts_api_key' => '',
);

Expand Down
16 changes: 16 additions & 0 deletions _build/resolvers/setupoptions.resolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

// Convenience
if (!isset($modx) && isset($object) && isset($object->xpdo)) {
$modx = $object->xpdo;
}

$contextAware = array_key_exists('clientconfig_context_aware', $options) ? (bool)$options['clientconfig_context_aware'] : false;

$setting = $modx->getObject('modSystemSetting', ['key' => 'clientconfig.context_aware']);
if ($setting instanceof modSystemSetting) {
$setting->set('value', $contextAware);
$setting->save();
}

return true;
6 changes: 5 additions & 1 deletion _build/resolvers/tables.resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
$manager = $modx->getManager();
$loglevel = $modx->setLogLevel(modX::LOG_LEVEL_ERROR);

$objects = array('cgSetting', 'cgGroup');
$objects = array(
'cgSetting',
'cgGroup',
'cgContextValue',
);
foreach ($objects as $obj) {
$manager->createObjectContainer($obj);
}
Expand Down
36 changes: 36 additions & 0 deletions _build/setup.options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:

$isContextAware = $modx->getOption('clientconfig.context_aware', null, false);
$globalChecked = $isContextAware ? '' : 'checked="checked"';
$contextChecked = $isContextAware ? 'checked="checked"' : '';

return <<<HTML
<p>ClientConfig 2.0 comes in two different flavours: global, and multi context mode. </p>
<br>
<ul style="list-style: disc; padding-left: 2em; padding-bottom: 1em;">
<li>In global mode, your users can manage settings that <b>affect the entire website</b>.</li>
<li>In multi-context mode, a context selector is added to the top right of the configuration screen, allowing the user to set <b>different values for each independent context</b>.</li>
</ul>

<p>Which mode would you like to use?</p>

<label>
<input type="radio" name="clientconfig_context_aware" value="0" {$globalChecked}>
Global mode
</label>
<label>
<input type="radio" name="clientconfig_context_aware" value="1" {$contextChecked}>
Multi-context mode
</label>

<p>You can change the mode later through the <code>clientconfig.context_aware</code> system setting.</p>

HTML;
break;
}

return '';
26 changes: 25 additions & 1 deletion assets/components/clientconfig/js/mgr/clientconfig.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,31 @@ Ext.extend(ClientConfig,Ext.Component,{
config: {
connector_url: ''
},
inVersion: false
inVersion: false,

destroyRTEs: function(rtes) {
for (var i = 0; i < rtes.length; i++) {
var rte = rtes[i];
if (window.tinymce
&& window.tinymce.editors
&& window.tinymce.editors[rte])
{
window.tinymce.editors[rte].remove();
}
else if (window.CKEDITOR
&& window.CKEDITOR.instances
&& window.CKEDITOR.instances[rte]
) {
CKEDITOR.instances[rte].destroy()
}
else if (window.$red) {
var editor = $red('#' + rte);
if (editor && editor.redactor) {
editor.redactor('core.destroy');
}
}
}
}
});
Ext.reg('clientconfig',ClientConfig);
ClientConfig = new ClientConfig();
83 changes: 78 additions & 5 deletions assets/components/clientconfig/js/mgr/sections/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ClientConfig.page.Home = function(config) {
items: [{
html: '<h2>' + _('clientconfig') + '</h2>',
border: false,
cls: 'modx-page-header'
cls: 'modx-page-header',
id: 'clientconfig-header'
}, {
xtype: 'modx-formpanel',
id: 'clientconfig-formpanel-home',
Expand All @@ -19,6 +20,9 @@ ClientConfig.page.Home = function(config) {
border: !!ClientConfig.config.verticalTabs && !MODx.config.connector_url,
anchor: '100%',
items: [{
xtype: 'hidden',
name: 'context'
},{
xtype: (!!ClientConfig.config.verticalTabs) ? 'modx-vtabs' : 'modx-tabs',
border: false,
deferredRender: false,
Expand Down Expand Up @@ -64,7 +68,13 @@ Ext.extend(ClientConfig.page.Home,MODx.Component,{
MODx.loadRTE(id);
});
}
}, 250)

if (ClientConfig.contextAware && ClientConfig.initialContext && ClientConfig.initialContext.key) {
var contextSelector = Ext.getCmp('clientconfig-combo-contexts');
contextSelector.setValue(ClientConfig.initialContext.key);
contextSelector.fireEvent('select', contextSelector);
}
}, 150)
},
getTabs: function() {
var tabs = [],
Expand Down Expand Up @@ -206,20 +216,38 @@ Ext.extend(ClientConfig.page.Home,MODx.Component,{
},

getButtons: function() {
var buttons = [{
var buttons = [];

if (ClientConfig.contextAware) {
buttons.push('-',{
xtype: 'panel',
html: '<span style="padding-left: 1em; padding-right: 1em;">' + _('clientconfig.choose_context') + ': </span>'
},{
emptyText: _('clientconfig.choose_context'),
xtype: 'clientconfig-combo-contexts',
id: 'clientconfig-combo-contexts',
listeners: {
change: {fn: this.switchContext, scope: this},
select: {fn: this.switchContext, scope: this}
}
});
}

buttons.push({
text: _('clientconfig.save_config'),
handler: this.save,
cls: 'primary-button',
scope: this,
keys: [{
key: MODx.config.keymap_save || 's',
ctrl: true,
fn: this.save
}]
}];
});

if (ClientConfig.isAdmin) {
buttons.push('-',{
text: _('clientconfig.admin'),
text: '<i class="icon icon-cog"></i> ' + _('clientconfig.admin'),
handler: this.openAdminPanel,
scope: this
})
Expand All @@ -228,6 +256,51 @@ Ext.extend(ClientConfig.page.Home,MODx.Component,{
return buttons;
},

switchContext: function(field) {
var ctx = field.getValue(),
fp = Ext.getCmp('clientconfig-formpanel-home'),
heading = Ext.getCmp('clientconfig-header'),
rtes = this.rtes;
fp.el.mask(_('loading'));

MODx.Ajax.request({
url: ClientConfig.config.connectorUrl,
params: {
action: ctx.length > 0 ? 'mgr/settings/getcontextaware' : 'mgr/settings/getglobal',
context: ctx
},
listeners: {
success: {fn: function(r) {
var form = fp.getForm();
if (form) {
// Destroy RTEs before resetting and updating the form
ClientConfig.destroyRTEs(rtes);

// Set the new context-specific values
form.reset();
form.setValues(r.object);

// Re-initialize editors
if (MODx.loadRTE) {
Ext.each(rtes, function(id, index) {
MODx.loadRTE(id);
});
}
}
fp.el.unmask();
var headingText = r.object.context_name.length > 0
? _('clientconfig.config_for_context', {context: r.object.context_name})
: _('clientconfig');
heading.update('<h2>' + headingText + '</h2>');
}, scope: this},
failure: {fn: function() {
fp.el.unmask();
}, scope: this},
scope: this
}
});
},

save: function() {
var fp = Ext.getCmp('clientconfig-formpanel-home');
if (fp && fp.getForm()) {
Expand Down
25 changes: 25 additions & 0 deletions assets/components/clientconfig/js/mgr/widgets/combos.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,28 @@ ClientConfig.combo.GoogleFontList = function(config) {
};
Ext.extend(ClientConfig.combo.GoogleFontList, MODx.combo.ComboBox);
Ext.reg('googlefontlist',ClientConfig.combo.GoogleFontList);

ClientConfig.combo.ContextList = function(config) {
config = config || {};
Ext.applyIf(config,{
url: ClientConfig.config.connectorUrl,
baseParams: {
action: 'mgr/contexts/getlist',
exclude: 'mgr',
combo: true
},
fields: ['key','name'],
hiddenName: config.name || 'context',
valueField: 'key',
displayField: 'name',
pageSize: 20
// Typeahead prevents the dropdown from opening on click, needs a solution first
// editable: true,
// typeahead: true,
// forceSelection: true,
// queryParam: 'search',
});
ClientConfig.combo.ContextList.superclass.constructor.call(this,config);
};
Ext.extend(ClientConfig.combo.ContextList, MODx.combo.ComboBox);
Ext.reg('clientconfig-combo-contexts',ClientConfig.combo.ContextList);
19 changes: 17 additions & 2 deletions core/components/clientconfig/controllers/home.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function process(array $scriptProperties = array()) {
$c->sortby('label','ASC');
foreach ($group->getMany('Settings', $c) as $setting) {
$sa = $setting->toArray();
if (in_array($sa['xtype'],array('checkbox','xcheckbox'))) {
if (in_array($sa['xtype'], array('checkbox','xcheckbox'), true)) {
$sa['value'] = (bool)$sa['value'];
}

if ($sa['xtype'] == 'googlefontlist') {
if ($sa['xtype'] === 'googlefontlist') {
$googleFontsApiKey = $this->modx->getOption('clientconfig.google_fonts_api_key', null, '');
$sa['xtype'] = empty($googleFontsApiKey) ? 'textfield' : $sa['xtype'];
}
Expand All @@ -46,6 +46,19 @@ public function process(array $scriptProperties = array()) {
}
$this->loadRichTextEditor();
$this->tabs = $tabs;

if (array_key_exists('context', $scriptProperties) && $this->modx->getOption('clientconfig.context_aware')) {
$key = $scriptProperties['context'];
$context = $this->modx->getObject('modContext', ['key' => $key]);
if ($context instanceof modContext) {

$this->addHtml('<script type="text/javascript">
Ext.onReady(function() {
ClientConfig.initialContext = ' . $context->toJSON() . ';
});
</script>');
}
}
}

/**
Expand All @@ -72,9 +85,11 @@ public function loadCustomCssJs() {
$this->addJavascript($this->clientconfig->config['jsUrl'].'mgr/widgets/combos.js');
$this->addLastJavascript($this->clientconfig->config['jsUrl'].'mgr/sections/home.js');

$contextAware = $this->modx->getOption('clientconfig.context_aware') ? 'true' : 'false';
$this->addHtml('<script type="text/javascript">
Ext.onReady(function() {
ClientConfig.data = '.$this->modx->toJSON($this->tabs).';
ClientConfig.contextAware = ' . $contextAware . ';
ClientConfig.isAdmin = ' . (($this->clientconfig->hasAdminPermission()) ? '1' : '0') .';
MODx.load({ xtype: "clientconfig-page-home" });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

/* If we got the class (gotta be careful of failed migrations), grab settings and go! */
if ($clientConfig instanceof ClientConfig) {
$settings = $clientConfig->getSettings();
$contextKey = $modx->context instanceof modContext ? $modx->context->get('key') : 'web';
$settings = $clientConfig->getSettings($contextKey);

/* Make settings available as [[++tags]] */
$modx->setPlaceholders($settings, '+');
Expand All @@ -54,4 +55,4 @@
break;
}

return;
return;
4 changes: 4 additions & 0 deletions core/components/clientconfig/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@
$_lang['clientconfig.source'] = 'Media Source';
$_lang['clientconfig.source.desc'] = 'The media source to use for the file browser.';

// New 2017-09-13
$_lang['clientconfig.choose_context'] = 'Choose Context';
$_lang['clientconfig.global_values'] = 'Global';
$_lang['clientconfig.config_for_context'] = 'Configuration for [[+context]]';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
class cgContextValue extends xPDOSimpleObject {}
Loading