How to list child items if parent is active in refinerycms? - refinerycms

I have this code to list all children of a certain page:
<ul class="sidenav">
<%= render :partial => '/refinery/menu_branch',
:collection => refinery_menu_pages.select{|p| p.parent_id == #page.root.id},
:locals => {
:hide_children => false,
:apply_css => true
} -%>
</ul>
e.g.
Item1
cItem1
cItem2
How can I modify the code to show the children of a children page?, e.g.:
Item1
cItem1
cItem2
ccItem1
ccItem2
ccItem3
Item2

Since this code is recursive, I'm surprised it doesn't show multiple levels already. That is to say, the menu_branch partial calls the menu_branch partial until it children are nil.
Here's the code from the _menu_branch partial in RefineryCMS 2.0:
<%= render :partial => '/refinery/menu_branch', :collection => children,
:locals => {
:apply_css => local_assigns[:apply_css],
:hide_children => !!hide_children,
:menu_levels => local_assigns[:menu_levels]
} -%>
Notice that this one includes :menu_levels. You could try copying and pasting that instead, or maybe just replace local_assigns[:menu_levels] with an integer for the number of levels you want to show.

Related

cakephp 3: change class input error

I build my form template according the documentation. It seemed everything was fine until I get fields errors. Now I have two problems:
How can I change the class name of the forms fields when they get error?
Solution:
$this->loadHelper('Form', [
'templates' => 'your_template_file',
'errorClass' => 'your-class',
]);
How can I set escape => false in the error-message from cakephp, when the field get error? Because I have icon within that div, such as
<div class="error-message"><i class="fa fa-times"></i> My error</div>
Well, I got part of th solution. To escape HTML I could put $this->Form->error('field', null, ['escape' => false]); in all fields, but it´s a hard manually task. I´d like to keep escape with default of all fields errors. I could edit the FormHelper.php class. However, I think that is not good idea.
My form template is:
'formStart' => '<form {{attrs}} class="form-horizontal" novalidate>',
'inputContainer' => '{{content}}',
'input' => '<input type="{{type}}" name="{{name}}" {{attrs}} class="form-control"/>',
'checkbox' => '<input type="checkbox" value="{{value}}" name="{{name}}" {{attrs}}/>',
'textareaContainerError' => '{{content}}',
'textarea' => '<textarea name="{{name}}" {{attrs}} class="form-control"></textarea>',
'select' => '<select name="{{name}}" {{attrs}} class="form-control">{{content}}</select>',
'button' => '<button {{attrs}} class="btn btn-primary">{{text}}</button>',
'nestingLabel' => '{{input}}',
'formGroup' => '{{input}}',
to the second part of the question: you can extend FormHelper like in code below, so that escape will be set to false by default
// extended FormHelper, this goes in src/View/Helper
namespace App\View\Helper;
use Cake\View\Helper;
class MyFormHelper extends Helper\FormHelper
{
public function error($field, $text = null, array $options = [])
{
if (!isset($options['escape'])) {
$options['escape'] = false;
}
return parent::error($field, $text, $options);
}
}
next create alias for this helper in AppController.php
public $helpers = [
'Form' => ['className' => 'MyForm']
];
this also allows you to add more customization of your own and at any time, you can go back to default implementation of FormHelper, just remove that alias from AppController.php.
For those who wants an 'easy solution' to escape error message on some fields, you cant simply set escape options to false :
<?= $this->Form->input('email', [
"label" => "Email",
"error" => [
"escape" => false
]
]) ?>

Form Element decorators Zend Framework

I'm using Zend Framework 1 and this library to integrate Twitter-bootstrap. It's great library, but I want to add new decorators for it (for Zend Form Element File), so that it looked like here
So instead of
<input id="image" type="file" name="image">
I want to render something like that (with all styles and javascript)
<span class="btn btn-success fileinput-button">
<i class="icon-plus icon-white"></i>
<span>Add files...</span>
<input type="file" multiple="" name="files[]">
</span>
I'm new to Zend Framework and do not know how to do that.
The question is, what have I put in library/Twitter/Form.php, in public/css and public/javascript to make it work?
Or maybe I have to do something else?
I tried to add decorators in Form.php, but no decorators applied (I do not remember what I did exactly)
So the main question is, how can I add this decorators for my Element in library/Twitter?
Edited:
I was working on the problem and managed to show a green button with a "plus" picture using jQuery-file-upload-ui.css (do not remember a name of the file) and changing $decorators in Form.php where code
if($element instanceof Zend_Form_Element_File)
is situated to
$decorators = array(
"ViewHelper",
array("Errors", array("placement" => "append")),
array("Description", array("tag" => "span", "class" => "help-block")),
array(array("ivanov2" => "HtmlTag"), array("tag" => "i", "class" => "icon-plus icon-white",'openOnly' => true,)),
array(array('close' => 'HtmlTag'), array('tag' => 'i', 'closeOnly' => true)),
array(array("ivanov" => "HtmlTag"), array("tag" => "span", "class" => "btn btn-success fileinput-button")),
array(array("innerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "controls")),
array("Label", array("class" => "control-label")),
array(array("outerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "control-group"))
);
But I still do not know how I can place an element with some content (for example with text):
<span>Add Files..</span>
And also I want to use drag and drop, but do not know how.

if else to render a different form in the view of a rails 2 app

I am trying to render one of two slightly different forms with an unless else:
unless many_items
form_tag purchases_url(:item1 => item1), :id => "id1_#{item1}", :method => "post", :class=> "order-form" do
else
form_tag purchases_url(:item1 => item1, :item2 => item2), :id => "upgrade_#{item2}", :class => "upgrade_form" do
end
rest of form
button
<%end%>
but I get an error, of course.
I don't really know haw to do this..
I used a nil to prevent from the second variable to exist
parent_order = item2.present? ? item2 : nil
form_id = gig.is_item? ? "1#{gig.id}" : "2#{gig.id}"
form_class = gig.is_item? ? "1" : "2"
form_tag purchases_url(:item1 => item1 ,:item2 => items), :id => form_id, :method => "post", :class=> form_class do
%>

Ruby on Rails Formtastic Multiple Options in Member_Label

I have a relational model where users have managers that are also users. The below code works great and does exactly what it's suppose to, but it's only displaying the first name of the manager. I'm trying to get this to show both the first name and the last name of the manager.
<%= sf.input :managers, :as => :check_boxes, :member_label => (:firstname) ,:input_html => { :size => 20, :multiple => true}%>
The other field i'm trying to add is the :lastname. I cannot figure out how to get :member_label to take both fields.
I figured it out. By using the Proc.new, I was able to add in both first name and last name.
<%= sf.input :managers, :as => :check_boxes, :member_label => Proc.new { |t| h(t.firstname + " " + t.lastname) } ,:input_html => { :size => 20, :multiple => true}%>

Edit only one column in MvcContrib Grid + MVC 2.0

How can I edit only one of the columns( the last one) in the MvcContrib Grid. When the Edit button is clicked other columns should not be editable.
I have the following grid
<% Html.Grid(Model.InnerModel.ListRecords)
.Empty("No data available")
.Attributes(new Hash(id => "ReportResultsTable"))
.Columns(column =>
{
column.For(x => x.DateReceived);
column.For(x => x.OrderNumber);
column.For(x => x.DateSent);
column.For(x => x.Comments);
}).Render(); %>
I need to allow the user to enter Comments, but rest of the columns should not be editable.
how can I do that.