Anyone know how to get the new 1.4 WYSIWYG editor (TinyMCE) working with custom admin pages?
I have some modules I made that have input fields in the admin->system->config section, and I’d like to get the new editor to show on the textareas there, but I can't find where they are defined.
To load the TINY MCE on a specific page, use the following function on the Adminhtml Edit block of your module:
protected function _prepareLayout() {
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}
To enable the editor for a certain editable textfield, just use 'wysiwyg' => true, instead of 'wysiwyg' => false. i.e.:
$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true,
'required' => true,
));
Here are a few simple steps that will help you make TinyMCE work with Magento CMS pages.
Step 1. Download and unpack TinyMCE to root /js folder. Two things to keep in mind here. Download regular version (not jQuery version) of TinyMCE. This is due to the fact that Magento uses Prototype, so we need to avoid conflicts. Second, watch out for unpack location. Your tiny_mce.js file should be accessible on js/tiny_mce/tiny_mce.js path.
Step 2. Open the app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php file. Locate the
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('cms')->__('Content'),
'title' => Mage::helper('cms')->__('Content'),
'style' => 'height:36em;',
'wysiwyg' => false,
'required' => true,
));
and change it to
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('cms')->__('Content'),
'title' => Mage::helper('cms')->__('Content'),
'style' => 'height:36em;',
'wysiwyg' => true,
'theme' => 'advanced',
'required' => true,
));
As you can see, here we changed on existing attribute ("wysiwyg") value and added new attribute "theme".
Step 3. Open the /lib/Varien/Data/Form/Element/Editor.php file and locate the method getElementHtml(). Here we change
$html = '
<textarea name="'.$this->getName().'" title="'.$this->getTitle().'" id="'.$this->getHtmlId().'" class="textarea '.$this->getClass().'" '.$this->serialize($this->getHtmlAttributes()).' >'.$this->getEscapedValue().'</textarea>
<script type="text/javascript">
// <![CDATA[
/* tinyMCE.init({
mode : "exact",
theme : "'.$this->getTheme().'",
elements : "' . $element . '",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
theme_advanced_resize_horizontal : "false",
theme_advanced_resizing : "false",
apply_source_formatting : "true",
convert_urls : "false",
force_br_newlines : "true",
doctype : \'< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\'
});*/
//]]>
</script>';
to
$html = '
<textarea name="'.$this->getName().'" title="'.$this->getTitle().'" id="'.$this->getHtmlId().'" class="textarea '.$this->getClass().'" '.$this->serialize($this->getHtmlAttributes()).' >'.$this->getEscapedValue().'</textarea>
<script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
//< ![CDATA[
Event.observe(window, "load", function() {
tinyMCE.init({
mode : "exact",
theme : "'.$this->getTheme().'",
elements : "' . $element . '",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
theme_advanced_resize_horizontal : "false",
theme_advanced_resizing : "false",
apply_source_formatting : "true",
convert_urls : "false",
force_br_newlines : "true",
doctype : \'< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\'
});
});
//]]>
</script>';
As you can see, there were only three minor changes needed (download, modify, modify) to get the TinyMCE editor working.
Hope this helps. Cheers.
© Branko Ajzele (source)
in EW_Press_Block_Adminhtml_Press_Edit
(EW/Press/Block/Adminhtml/Press/Edit.php)
paste this function
protected function _prepareLayout()
{
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled())
{
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}
and than in the form.php (EW_Press_Block_Adminhtml_Press_Edit_Tab_Form)
/(EW/Press/Block/Adminhtml/Press/Edit/Tab/Form.php)/
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
add it so it will look like below:
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('module')->__('Site Description'),
'title' => Mage::helper('module')->__('Site Description'),
'style' => 'width:400px; height:300px;',
'required' => true,
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true
));
now reload the page to see the effect.
Here are the steps that I followed.
Preparing editor used in edit form
app/code/local/Mynamespace/Mymodule/Block/Adminhtml/Mymodule/Edit.php
protected function _prepareLayout()
{
// added this code
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
}
parent::_prepareLayout();
}
Transforming textarea to editor
app/code/local/Mynamespace/Mymodule/Block/Adminhtml/Mymodule/Edit/Tab/Form.php
Include the content within ‘_prepareForm()‘ function
$config = Mage::getSingleton('cms/wysiwyg_config')->getConfig(
array(
'add_widgets' => false,
'add_variables' => false,
'add_images' => false,
'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/',
));
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('mymodule')->__('Content'),
'title' => Mage::helper('mymodule')->__(’Content'),
'style’ => 'width:700px; height:320px;',
'wysiwyg' => true,
'required' => true,
'config' => $config,
));
Based on the above post i have written an article entitled:
How to use WYSIWYG editor (TinyMCE) in custom Admin Magento Module
Hope this helps.
Related
I was wondering whether I can call the action automatically through ajax one by one for each row of the GridView after the page is load.
All I can do now is trigger the call manually through button click, already returned the value correctly.
Here is my GridView:
<?php Pjax::begin(['id' => 'payment-list-view-container', 'timeout' => 5000]); ?>
<?= GridView::widget([
'id' => 'payment-table',
'dataProvider' => $dataProvider,
'resizableColumns' => false,
'tableOptions' => ['class' => 'table table-striped'],
'pjax'=>true,
'pjaxSettings' => [
'options' => [
'id' => 'payment-table',
'enablePushState' => false,
],
],
'columns' => [
[
'class' => 'kartik\grid\SerialColumn',
'header' => 'No.',
],
[
'header' => 'Title',
'attribute' => 'name',
],
[
'attribute' => 'date_start',
'header' => 'Payment Date',
'value' => function($model){
return Yii::$app->formatter->asDatetime($model->payment_date, "php:d F Y");
}
],
[
'header' => 'Action',
'format' => 'raw',
'value' => function($model) use ($export_type){
return Html::a('Open', '',
[
'data-url'=>'/model/payment/check-status/id/'. $model->id . '?exportType=' . $export_type ,
'class'=>'check-payment-status'
]);
}
],
],
]); ?>
<?php Pjax::end(); ?>
Here is my js:
<?php
$js = <<<JS
$(document).ready(function(){
function checkStatus() {
$(".check-payment-status").off().on("click", function(e){
e.preventDefault();
var url = $(this).attr("data-url");
$.pjax.defaults.timeout = false;
$.ajax({
url : url,
type : "post",
dataType: 'json',
success: function (response) {
// do something
}, error : function () {
// do nothing
}
});
});
}
checkStatus();
});
JS;
$this->registerJs($js);
I guess I need to use something like this, but still don't know how to implement it
$.each($('.check-payment-status'), function (i, el) {
//do something
});
So can I really do that? Calling the action automatically after the page load for each row?
All you need to do is to trigger the click event on the buttons.
$(document).ready(function() {
//bind the click handler
$('.btn').on('click', function(e) {
e.preventDefault();
console.log("Clicked " + $(this).text());
});
//click each button
$('.btn').each(function() {
$(this).trigger('click');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Link 1<br>
Link 2<br>
Link 3<br>
I am using laravel backpack as a crud and i'm creating a laravel admin panel with it. I need to use the summernote wysiwyg field and there is a options field attribute with laravel backpack and I am trying to input the minheight option for summer note however it does not add it to the intiatlaztion properly
$this->crud->addField([
'name' => 'desc',
'type' => 'summernote',
'label' => "feature description",
'options' => [
'minheight: 300'
]
]);
as you can see it does not increase the mineheight does anyone have any ideas?
i have a work around but it requires me to edit vendor files which it not something i want to have to deal with.
Place this script below your page to modify size and other characteristics of summernote editor:
<script type="text/javascript">
$(document).ready(function() {
$('#summernote').summernote({
height: 250,
disableResizeEditor: true // This is optional if you want to remove resize
});
});
</script>
Place your rows and cols size in the attributes array !
$this->crud->addField([
'name' => 'desc',
'type' => 'textarea',
'label' => "feature description",
'attributes' => [
'rows' => 20,
'cols' => 20
]
]);
You wrote your options property wrong.
'options' => [
'minheight: 300'
]
While actually it should be:
'options' => [
'minheight' => 300
]
See the difference?
You can use summernote API like this:
$this->crud->addField([
'name' => 'desc',
'type' => 'summernote',
'label' => "feature description",
'options' => [
'minheight' => 300,
'height' => 400
]
]);
$this->crud->addField([
// Summernote
'name' => 'description',
'label' => 'Описание',
'type' => 'summernote',
'options' => [
'placeholder'=> 'Содержание статьи',
'height'=> 500,
'toolbar'=>[
['style', ['style']],
['font', ['bold']], // show only bold button
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['view', ['fullscreen', 'codeview', 'help']]
],
]
]);
I am having a trouble on getting the value of the selected drop-down list(package_id) to populate the next fields particularly the Departure Time and Price which is in the Package Model.
Here is my code in View/Reservations/package.ctp:
<?php echo $this->Form->create('Reservation'); ?>
<table cellspacing="10">
<?php
echo $this->Html->tableCells(array(
array(
'Date: ',
$this->Form->input('date', array('label' => false, 'type' => 'text', 'class' => 'datepicker'))
),
array(
'Package Name:',
$this->Form->input('package_id', array('label' => false, 'options' => $name, 'id' => 'PackageID', 'empty' => '-- Select Package --'))
),
array(
'Departure Time:',
$this->Form->input('departure_time', array('label' => false, 'type' => 'label', 'id' => 'test'))
),
array(
'Price:',
$this->Form->input('price', array('label' => false, 'id' => 'test'))
),
array(
'Number of Person:',
$this->Form->input('number_of_people', array('label' => false))
),
array(
'Total Price:',
$this->Form->input('price', array('label' => false))
),
array(
'',
$this->Form->Submit('Book Now', array('class' => 'button'))
),
));
?>
</table>
and Here is my code in public function package():
$options = $this->Packages->find('list'); //or whatever conditions you want
$this->set('name', $options);
I was trying to use JS helper but I can't get it right here is my code:
$this->Js->get('#PackageID');
$this->Js->event('change',
$this->Js->request(array(
'controller'=>'Reservation',
'action'=>'getPackage'
), array(
'update'=> '#test',
'async' => true,
'method' => 'post',
'dataExpression' => true,
'data'=> $this->Js->serializeForm(array(
'isForm' => true,
'inline' => true))
)
)
);
Feel free to ask questions for clarification. Thank You in advance :)
Try this :
in the view .ctp , add this js function :
<script language="JavaScript">
jQuery(document).ready(function() {
$("#PackageID").chosen().bind('change', function() {
$.post('/project_name/controller_name/listDeparetementByPackage/'+$(this).val(), function(data) {
$("#test").empty().append(data);
$("#test").trigger("liszt:updated");
}, 'html');
});
});
</script>
and in your controller , here is the function to get the departements by pacakge id :
function listDeparetementByPackage($package = null ) {
$this->layout = 'ajax';
$this->beforeRender();
$this->autoRender = false;
$data = $this->Package->Departement->find('list', array('fields' => array('Departement.id', 'Departement.libelle'),
'conditions' => array('Departement.package_id' => $package),
'recursive' => 0 ));
if(count($data)>0){
foreach($data as $key => $val) {
echo "<option value=$key>$val</option>";
}
}else{
echo "<option></option>"; // if the result is empty , show a select empty
}
}
Hope it helps .
I would like to create a read-only field in the backend at the client's Magento.
create fields to know (through a module) is as follows:
$installer->addAttribute("customer", "attrcode", array(
"type" => "varchar",
"backend" => "",
"label" => "label",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
));
this way it creates the field, but he's not just reading ...
Thank You
One possible solution is to use javascript to disable the button on page load
Create a js file and upload it to your admin skin/js directory (disable_button.js)
add
document.observe('dom:loaded', function(){
$("target_input_id").disabled=true;
});
Then add or update you local.xml to include the js files
<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_customer_edit>
<reference name="head">
<action method="addItem"><type>skin_js</type><script>js/disable_button.js</script></action>
</reference>
</adminhtml_customer_edit>
</layout>
I don't think what you are trying to is possible using addAttribute(), _prepareValues($attr) method only allow specific values that are store in $data.
Take a look # app/code/core/Mage/Eav/Model/Entity/Setup.php
public function addAttribute($entityTypeId, $code, array $attr)
{
$entityTypeId = $this->getEntityTypeId($entityTypeId);
$data = array_merge(
array(
'entity_type_id' => $entityTypeId,
'attribute_code' => $code
),
$this->_prepareValues($attr);
);
.....
if ($attributeId) {
$this->updateAttribute($entityTypeId, $attributeId, $data, null, $sortOrder);
} else {
$this->_insertAttribute($data);
}
.......
}
protected function _prepareValues($attr)
{
$data = array(
'backend_model' => $this->_getValue($attr, 'backend'),
'backend_type' => $this->_getValue($attr, 'type', 'varchar'),
'backend_table' => $this->_getValue($attr, 'table'),
'frontend_model' => $this->_getValue($attr, 'frontend'),
'frontend_input' => $this->_getValue($attr, 'input', 'text'),
'frontend_label' => $this->_getValue($attr, 'label'),
'frontend_class' => $this->_getValue($attr, 'frontend_class'),
'source_model' => $this->_getValue($attr, 'source'),
'is_required' => $this->_getValue($attr, 'required', 1),
'is_user_defined' => $this->_getValue($attr, 'user_defined', 0),
'default_value' => $this->_getValue($attr, 'default'),
'is_unique' => $this->_getValue($attr, 'unique', 0),
'note' => $this->_getValue($attr, 'note'),
'is_global' => $this->_getValue($attr, 'global',
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
),
);
return $data;
}
I have developed exactly such extension that work for products, categories and CMS pages. You just have to define some rules and choose which attributes you want to show as read-only.
Extension URL: https://www.bubbleshop.net/magento-admin-readonly.html
I need two additional fields for adding additional notes with each order besides comments...
I have trying running this script found on the web
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute = array(
'type' => 'text',
'backend_type' => 'text',
'frontend_input' => 'text',
'is_user_defined' => true,
'label' => 'Your attribute label',
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'default' => ''
);
$installer->addAttribute('order', 'your_attribute_code', $attribute);
$installer->endSetup();
But after running and checking the order form there were no additional field beside comments.... any one has any idea about how i could do it..