Here are the functions we use for these kind of customizations:
function hideField(fld){
$('#'+fld).closest('.edit-view-row-item').hide();
}
function showField(fld){
$('#'+fld).closest('.edit-view-row-item').show();
}
function addRequiredStar(fld){
$('#'+fld).closest('.edit-view-row-item').find('.label').find('span.required').remove(); // remove it in case it was already there
$('#'+fld).closest('.edit-view-row-item').find('.label').append('<span class="required">*</span>');
}
function removeRequiredStar(fld){
$('#'+fld).closest('.edit-view-row-item').find('.label').find('span.required').remove();
}
function hidePanel(panel){
$('[data-id="'+panel+'"]').closest('.panel-default').hide()
}
function showPanel(panel){
$('[data-id="'+panel+'"]').closest('.panel-default').show()
}
function togglePanel(panel){
$('[data-id="'+panel+'"]').closest('.panel-default').find('[data-toggle="collapse-edit"]').click()
}
function expandPanel(panel){
$('[data-id="'+panel+'"]').closest('.panel-default').find('.collapsed').click()
}
function collapsePanel(panel){
$('[data-id="'+panel+'"]:visible').closest('.panel-default').find('[data-toggle="collapse-edit"]').click()
}
In the metadata files you can add the fields which you want to show in each of the view. For simplicity you can copy the detailviewdefs.php file and modify it.
Check this article for the help to create a custom view.
Now ====>
You can add a condition in view/view.detail.php in preDisplay function to check the values. if the values are related to plot view you can redirect the control to Plot View or to Repair view.
If you are a developer then this is enough help for you. If you are not a developer then it is not your game…hire someone to do it for you.
Thanks every one, I have looked at the responses and have made progress, I have it working for the edit view but not the details view.
For thew edit view file custom/modules/CoMO_Orders/views/view.edit.php I have thiws code what works well.
<?php
require_once 'include/MVC/View/views/view.edit.php';
class CoMO_OrdersViewEdit extends ViewEdit
{
// function runs before view is disaplyed.
public function preDisplay()
{
//echo $_POST['record'];
//get the record ID file
$bean = BeanFactory::getBean('CoMO_Orders', $_POST['record']);
//chec the order type, if it is not a plot (or related order), load quickcreate view.
if ($bean->order_type == "Repair" || $bean->order_type == "Other" || $bean->order_type == "Stock") {
//load smalledit view.
header('Location: /index.php?module=CoMO_Orders&action=SmallEdit&record=' . $bean->id);
exit;
} else {
//contiue to load this view.
$this->ev = new EditView();
$this->ev->ss = &$this->ss;
$this->ev->view = "EditView";
$metadataFile = "modules/CoMO_Orders/metadata/editviewdefs.php";
$this->ev->setup($this->module, $this->bean, $metadataFile, 'include/EditView/EditView.tpl', true, 'editviewdefs');
}
}
}
For the Details view, I have tried to copy it so i have this /var/www/html/custom/modules/CoMO_Orders/views/view.detail.php
<?php
require_once 'include/MVC/View/views/view.detail.php';
class CoMO_OrdersViewDetail extends ViewDetail
{
// function runs before view is disaplyed.
public function preDisplay()
{
$bean = BeanFactory::getBean('CoMO_Orders', $_GET['record']);
//check the order type, if it is not a plot (or related order), load quickcreate view.
if ($bean->order_type == "Repair" || $bean->order_type == "Other" || $bean->order_type == "Stock") {
header('Location: /index.php?module=CoMO_Orders&action=SmallDetail&record=' . $bean->id);
exit;
} else {
$metadataFile = "custom/modules/CoMO_Orders/metadata/detailviewdefs.php";
$this->dv = new DetailView2();
$this->dv->ss = &$this->ss;
$this->dv->setup($this->module, $this->bean, $metadataFile, get_custom_file_if_exists('include/DetailView/DetailView.tpl'));
}
}
}
If the record is no a Repair, Other or Stock. It works fine. If it is then it open up the error window and displays the record in there, Please see the screen shot attached.
Your metadata of detail view should have next format name of file: …/detailrosviewdefs.php . This file will work for “Repair” or “Other” or “Stock” the file ‘detailviewdefs.php’ will work for other.
This example for detailview, but you can do the same thing for editview.
Thanks, Not sure if i am missing some thing here. This is what the view.detail.php, I ended up passing the $bean as well, as it was not entering the if statements without it.
<?php
require_once ‘include/MVC/View/views/view.detail.php’;
class CoMO_OrdersViewDetail extends ViewDetail
{
public function getMetaDataFile($bean)
{
if ($bean->order_type == “Repair” || $bean->order_type == “Other” || $bean->order_type == “Stock”) {
$oldType = $this->type;
$this->type = $oldType . ‘ros’;
}
$metadataFile = parent::getMetaDataFile();
if ($bean->order_type == "Repair" || $bean->order_type == "Other" || $bean->order_type == "Stock") {
$this->type = $oldType;
}
return $metadataFile;
}
// function runs before view is disaplyed.
public function preDisplay()
{
$bean = BeanFactory::getBean('CoMO_Orders', $_GET['record']);
$metadataFile = CoMO_OrdersViewDetail::getMetaDataFile($bean);
echo $metadataFile;exit;
$this->dv = new DetailView2();
$this->dv->ss = &$this->ss;
$this->dv->setup($this->module, $this->bean, $metadataFile, get_custom_file_if_exists('include/DetailView/DetailView.tpl'));
}
}
I added this line to the code echo $metadataFile;exit;
and on a stock item, $metadataFile is blank and for other items it is custom/modules/CoMO_Orders/metadata/detailviewdefs.php
PHP Warning: Declaration of CoMO_OrdersViewDetail::getMetaDataFile($bean) should be compatible with SugarView::getMetaDataFile() in /var/www/html/custom/modules/CoMO_Orders/views/view.detail.php
This has solved the error message, but the symptoms are exactly the same. Now there is not error in apache or suitecrm.log when calling this view.
I am using your function as you typed it. I have it working on my system now.
I assume that you have developer mode active, meaning no caching?
I have added the flowing lines to clear the theme cache for this module when it loads. and that seems to have fixed it.
$repair = new RepairAndClear();
$repair->repairAndClearAll(array('clearThemeCache'), array(translate('CoMO_Orders')), true, false);
So the whole class looks like this:
class CoMO_OrdersViewDetail extends ViewDetail{
public function getMetaDataFile(){
if ($this->bean->order_type == "Repair" || $this->bean->order_type == "Other" || $this->bean->order_type == "Stock") {
$oldType = $this->type;
$this->type = $oldType . 'ros';
}
$metadataFile = parent::getMetaDataFile();
if ($this->bean->order_type == "Repair" || $this->bean->order_type == "Other" || $this->bean->order_type == "Stock") {
$this->type = $oldType;
}
return $metadataFile;
}
public function preDisplay(){
// find out what meta file is needed
$metadataFile = CoMO_OrdersViewDetail::getMetaDataFile();
// Rebuild theme for this moudle to clear the cache, making sure the correct view loads.
$repair = new RepairAndClear();
$repair->repairAndClearAll(array('clearThemeCache'), array(translate('CoMO_Orders')), true, false);
//load view.
$this->dv = new DetailView2();
$this->dv->ss = &$this->ss;
$this->dv->setup($this->module, $this->bean, $metadataFile, get_custom_file_if_exists('include/DetailView/DetailView.tpl'));
}
}
Thanks for you help. I am interested if this is the correct way, as it seems silly to have to clear the cache each load, but for out needs, i doubt it will be too much of an issue.