mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-19 04:46:42 +02:00
Add ckeditor as htmlarea widget
This commit is contained in:
@@ -98,6 +98,17 @@ class etemplate_widget_customfields extends etemplate_widget_transformer
|
|||||||
unset(self::$request->modifications[$form_name]['app']);
|
unset(self::$request->modifications[$form_name]['app']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->getElementAttribute($form_name, 'customfields'))
|
||||||
|
{
|
||||||
|
$customfields =& $this->getElementAttribute($form_name, 'customfields');
|
||||||
|
}
|
||||||
|
elseif($app)
|
||||||
|
{
|
||||||
|
// Checking creates it even if it wasn't there
|
||||||
|
unset(self::$request->modifications[$form_name]['customfields']);
|
||||||
|
$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
|
||||||
|
}
|
||||||
|
|
||||||
if(!$app)
|
if(!$app)
|
||||||
{
|
{
|
||||||
$app =& $this->setElementAttribute(self::GLOBAL_VALS, 'app', $GLOBALS['egw_info']['flags']['currentapp']);
|
$app =& $this->setElementAttribute(self::GLOBAL_VALS, 'app', $GLOBALS['egw_info']['flags']['currentapp']);
|
||||||
@@ -124,10 +135,12 @@ class etemplate_widget_customfields extends etemplate_widget_transformer
|
|||||||
$field_filter = explode(',', $this->attrs['field_names']);
|
$field_filter = explode(',', $this->attrs['field_names']);
|
||||||
}
|
}
|
||||||
$fields = $customfields;
|
$fields = $customfields;
|
||||||
|
|
||||||
foreach((array)$fields as $key => $field)
|
foreach((array)$fields as $key => $field)
|
||||||
{
|
{
|
||||||
// remove private or non-private cf's, if only one kind should be displayed
|
// remove private or non-private cf's, if only one kind should be displayed
|
||||||
if ((string)$this->attrs['use-private'] !== '' && (boolean)$field['private'] != (boolean)$this->attrs['use-private'])
|
if ((string)self::expand_name($this->attrs['use-private'],0,0) !== '' &&
|
||||||
|
(boolean)$field['private'] != (boolean)$this->attrs['use-private'])
|
||||||
{
|
{
|
||||||
unset($fields[$key]);
|
unset($fields[$key]);
|
||||||
}
|
}
|
||||||
@@ -190,12 +203,22 @@ class etemplate_widget_customfields extends etemplate_widget_transformer
|
|||||||
parent::beforeSendToClient($cname);
|
parent::beforeSendToClient($cname);
|
||||||
|
|
||||||
// Re-format date custom fields from Y-m-d
|
// Re-format date custom fields from Y-m-d
|
||||||
|
$field_settings =& self::get_array(self::$request->modifications, "{$this->id}[customfields]",true);
|
||||||
|
$field_settings = array();
|
||||||
foreach($fields as $fname => $field)
|
foreach($fields as $fname => $field)
|
||||||
{
|
{
|
||||||
if($field['type'] == 'date' && self::$request->content[self::$prefix.$fname])
|
if($field['type'] == 'date' && self::$request->content[self::$prefix.$fname])
|
||||||
{
|
{
|
||||||
self::$request->content[self::$prefix.$fname] = strtotime(self::$request->content[self::$prefix.$fname]);
|
self::$request->content[self::$prefix.$fname] = strtotime(self::$request->content[self::$prefix.$fname]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run beforeSendToClient for each field
|
||||||
|
$widget = self::factory($field['type'], '<?xml version="1.0"?><'.$field['type'].' type="'.$field['type'].'"/>', self::$prefix.$fname);
|
||||||
|
if(method_exists($widget, 'beforeSendToClient'))
|
||||||
|
{
|
||||||
|
$widget->id = "customfields[{$fname}]";
|
||||||
|
$widget->beforeSendToClient($this->id, $fname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,6 +16,29 @@
|
|||||||
*/
|
*/
|
||||||
class etemplate_widget_htmlarea extends etemplate_widget
|
class etemplate_widget_htmlarea extends etemplate_widget
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected $legacy_options = 'mode,height,width,expand_toolbar,base_href';
|
||||||
|
|
||||||
|
public $attrs = array(
|
||||||
|
'height' => '400px',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill config options
|
||||||
|
*
|
||||||
|
* @param string $cname
|
||||||
|
*/
|
||||||
|
public function beforeSendToClient($cname)
|
||||||
|
{
|
||||||
|
$form_name = self::form_name($cname, $this->id);
|
||||||
|
|
||||||
|
|
||||||
|
$config = egw_ckeditor_config::get_ckeditor_config_array($this->attrs['mode'], $this->attrs['height'],
|
||||||
|
$this->attrs['expand_toolbar'],$this->attrs['base_href']
|
||||||
|
);
|
||||||
|
self::$request->modifications[$form_name]['config'] = $config;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate input
|
* Validate input
|
||||||
*
|
*
|
||||||
|
@@ -216,7 +216,16 @@ var et2_customfields_list = et2_baseWidget.extend([et2_IDetachedDOM], {
|
|||||||
var data = this.getArrayMgr("modifications").getEntry(this.id);
|
var data = this.getArrayMgr("modifications").getEntry(this.id);
|
||||||
// Check for global settings
|
// Check for global settings
|
||||||
var global_data = this.getArrayMgr("modifications").getRoot().getEntry('~custom_fields~', true);
|
var global_data = this.getArrayMgr("modifications").getRoot().getEntry('~custom_fields~', true);
|
||||||
if(global_data) data = jQuery.extend({}, data, global_data);
|
if(global_data)
|
||||||
|
{
|
||||||
|
for(var key in data)
|
||||||
|
{
|
||||||
|
if(global_data[key])
|
||||||
|
{
|
||||||
|
data[key] = jQuery.extend(true, {}, data[key], global_data[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for(var key in data)
|
for(var key in data)
|
||||||
{
|
{
|
||||||
if(typeof data[key] === 'object' && ! _attrs[key]) _attrs[key] = data[key];
|
if(typeof data[key] === 'object' && ! _attrs[key]) _attrs[key] = data[key];
|
||||||
@@ -303,7 +312,19 @@ var et2_customfields_list = et2_baseWidget.extend([et2_IDetachedDOM], {
|
|||||||
attrs.select_options = field.values;
|
attrs.select_options = field.values;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
_setup_htmlarea: function(field_name, field, attrs) {
|
||||||
|
attrs.config = field.config ? field.config : {};
|
||||||
|
attrs.config.toolbarStartupExpanded = false;
|
||||||
|
if(field.len)
|
||||||
|
{
|
||||||
|
var options = field.len.split(',');
|
||||||
|
if(options.length) attrs.config.width = options[0];
|
||||||
|
if(options.length > 1) attrs.config.mode = options[1];
|
||||||
|
if(options.length > 2) attrs.config.toolbarStartupExpanded = options[2];
|
||||||
|
}
|
||||||
|
attrs.config.height = ((field.rows ? field.rows : 5) *16) +'px';
|
||||||
|
return true;
|
||||||
|
},
|
||||||
_setup_radio: function(field_name, field, attrs) {
|
_setup_radio: function(field_name, field, attrs) {
|
||||||
// No label on the widget itself
|
// No label on the widget itself
|
||||||
delete(attrs.label);
|
delete(attrs.label);
|
||||||
|
96
etemplate/js/et2_widget_htmlarea.js
Normal file
96
etemplate/js/et2_widget_htmlarea.js
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/**
|
||||||
|
* eGroupWare eTemplate2 - JS widget for HTML editing
|
||||||
|
*
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
|
* @package etemplate
|
||||||
|
* @subpackage api
|
||||||
|
* @link http://www.egroupware.org
|
||||||
|
* @author Nathan Gray
|
||||||
|
* @copyright Nathan Gray 2012
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/*egw:uses
|
||||||
|
jsapi.jsapi; // Needed for egw_seperateJavaScript
|
||||||
|
jquery.jquery;
|
||||||
|
/phpgwapi/js/ckeditor3/ckeditor.js;
|
||||||
|
/phpgwapi/js/ckeditor3/config.js;
|
||||||
|
/phpgwapi/js/ckeditor3/adapters/jquery.js;
|
||||||
|
et2_core_baseWidget;
|
||||||
|
*/
|
||||||
|
|
||||||
|
var et2_htmlarea = et2_inputWidget.extend({
|
||||||
|
|
||||||
|
attributes: {
|
||||||
|
'mode': {
|
||||||
|
'name': 'Mode',
|
||||||
|
'description': 'One of {ascii|simple|extended|advanced}',
|
||||||
|
'default': 'simple',
|
||||||
|
'type': 'string'
|
||||||
|
},
|
||||||
|
'height': {
|
||||||
|
'name': 'Height',
|
||||||
|
'default': et2_no_init,
|
||||||
|
'type': 'string'
|
||||||
|
},
|
||||||
|
'width': {
|
||||||
|
'name': 'Width',
|
||||||
|
'default': et2_no_init,
|
||||||
|
'type': 'string'
|
||||||
|
},
|
||||||
|
'expand_toolbar': {
|
||||||
|
'name': 'Expand Toolbar',
|
||||||
|
'default': true,
|
||||||
|
'type':'any',
|
||||||
|
},
|
||||||
|
'base_href': {
|
||||||
|
'name': 'Image base path',
|
||||||
|
'default': et2_no_init,
|
||||||
|
'type': 'string',
|
||||||
|
'description': 'activates the browser for images at the path (relative to the docroot)'
|
||||||
|
},
|
||||||
|
'config': {
|
||||||
|
// internal default configuration
|
||||||
|
'type':'any',
|
||||||
|
'default': et2_no_init
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
legacyOptions: ['mode','height','width','expand_toolbar','base_href'],
|
||||||
|
|
||||||
|
ck_props: {},
|
||||||
|
init: function(_parent, _attrs) {
|
||||||
|
this.ck_props = _attrs['config'] ? _attrs['config'] : {};
|
||||||
|
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
|
||||||
|
// Allow no child widgets
|
||||||
|
this.supportedWidgetClasses = [];
|
||||||
|
|
||||||
|
|
||||||
|
this.htmlNode = $j(document.createElement("div"));
|
||||||
|
this.setDOMNode(this.htmlNode[0]);
|
||||||
|
},
|
||||||
|
|
||||||
|
doLoadingFinished: function() {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
this.htmlNode.ckeditor(function() {},this.ck_props);
|
||||||
|
},
|
||||||
|
|
||||||
|
destroy: function() {
|
||||||
|
this.htmlNode.ckeditorGet().destroy(true);
|
||||||
|
},
|
||||||
|
set_value: function(_value) {
|
||||||
|
this.htmlNode.val(_value);
|
||||||
|
},
|
||||||
|
|
||||||
|
getValue: function() {
|
||||||
|
return this.htmlNode.val();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
et2_register_widget(et2_htmlarea, ["htmlarea"]);
|
||||||
|
|
||||||
|
|
@@ -30,6 +30,7 @@
|
|||||||
et2_widget_diff;
|
et2_widget_diff;
|
||||||
et2_widget_styles;
|
et2_widget_styles;
|
||||||
et2_widget_html;
|
et2_widget_html;
|
||||||
|
et2_widget_htmlarea;
|
||||||
et2_widget_tabs;
|
et2_widget_tabs;
|
||||||
et2_widget_tree;
|
et2_widget_tree;
|
||||||
et2_widget_historylog;
|
et2_widget_historylog;
|
||||||
|
Reference in New Issue
Block a user