Results 1 to 2 of 2

Thread: Custom quickcreate subpanel form

  1. #1
    franckt is offline Sugar Community Member
    Join Date
    Mar 2010
    Posts
    71

    Default Custom quickcreate subpanel form

    My following "solution" works with SugarCE 6.5.13 but could be tested on previous versions.

    My "problem" was :
    You can, via Studio, customize a quickcreate form for any module. But the custom result will be applied to all subpanels, whatever the parent module is.
    I wanted to have sometimes, for some module, a specific customized subpanel.

    My "solution" is :
    I'm going to take a concrete example. Imagine you want to have a specific customized "Contacts" subpanel on a DetailView of an Opportunity.

    1) Create (If U don't have it already) or go to "custom/modules/Contacts/views" directory

    2) Create there a file called view.subpanelquickcreate.php with this code :
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once "custom/include/EditView/MineSubpanelQuickCreate.php";
    class ContactsSubpanelQuickcreate extends SubpanelQuickCreate {
    public function preDisplay() {
    parent::preDisplay();
    }
    function process($module){
    global $app_strings;
    if($_REQUEST['target_action'] == 'QuickCreate'){
    $this->ev->view = 'QuickCreate';
    }
    $form_name = 'form_Subpanel'.$this->ev->view .'_'.$module;
    $this->ev->formName = $form_name;
    $this->ev->process(true, $form_name);
    echo $this->ev->display(false, true);
    }
    }

    3) As you can see, you have to create in "custom/include/EditView/" a file called "MineSubpanelQuickCreate.php" with this code :
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once "include/EditView/EditView2.php";
    class SubpanelQuickCreate{
    public $defaultProcess = true;
    public $viewType = 'QuickCreate';
    public function SubpanelQuickCreate($module, $view='QuickCreate', $proccessOverride = false) {
    $this->viewType = $view;
    if(!empty($_REQUEST['return_module'])) {
    $parentmodule=$_REQUEST['return_module'];
    $parentmodule=strtolower($parentmodule);
    } else {
    $parentmodule="";
    }
    $source = $this->getModuleViewDefsSourceFile($module, $this->viewType, $parentmodule);
    $this->ev = $this->getEditView();
    $this->ev->view = $this->viewType;
    $this->ev->ss = new Sugar_Smarty();
    $class = $GLOBALS['beanList'][$module];
    $bean = new $class();
    if(!empty($_REQUEST['record'])) {
    $bean->retrieve($_REQUEST['record']);
    }
    $this->ev->setup($module, $bean, $source);
    unset($bean);
    if (!isset($this->ev->defs['templateMeta']['form']['headerTpl'])) {
    $this->ev->defs['templateMeta']['form']['headerTpl'] = 'include/EditView/header.tpl';
    }
    if (!isset($this->ev->defs['templateMeta']['form']['footerTpl'])) {
    $this->ev->defs['templateMeta']['form']['footerTpl'] = 'include/EditView/footer.tpl';
    }
    if (($module!="Contacts")&&($parentmodule=="opportuni ties")) {
    $this->ev->defs['templateMeta']['form']['buttons'] = array('SUBPANELSAVE', 'SUBPANELCANCEL', 'SUBPANELFULLFORM');
    } else {
    $this->ev->defs['templateMeta']['form']['buttons'] = array('SUBPANELSAVE', 'SUBPANELCANCEL');
    }
    loadParentView('edit');
    $viewEditSource = 'modules/'.$module.'/views/view.edit.php';
    if (file_exists('custom/'. $viewEditSource)) {
    $viewEditSource = 'custom/'. $viewEditSource;
    }
    if (file_exists($viewEditSource) && !$proccessOverride) {
    include($viewEditSource);
    $c = $module . 'ViewEdit';
    $customClass = 'Custom' . $c;
    if (class_exists($customClass)) {
    $c = $customClass;
    }
    if (class_exists($c)) {
    $view = new $c;
    if ($view->useForSubpanel) {
    $this->defaultProcess = false;
    if ($view->useModuleQuickCreateTemplate && file_exists('modules/'.$module.'/tpls/QuickCreate.tpl')) {
    $this->ev->defs['templateMeta']['form']['headerTpl'] = 'modules/'.$module.'/tpls/QuickCreate.tpl';
    }
    $view->ev = & $this->ev;
    $view->ss = & $this->ev->ss;
    $class = $GLOBALS['beanList'][$module];
    if (!empty($GLOBALS['beanFiles'][$class])){
    require_once($GLOBALS['beanFiles'][$class]);
    $bean = new $class();
    $view->bean = $bean;
    }
    $this->ev->formName = 'form_Subpanel'.$this->ev->view .'_'.$module;
    $view->showTitle = false;
    $view->display();
    }
    }
    }
    if ($this->defaultProcess && !$proccessOverride) {
    $this->process($module);
    }
    }
    function process($module){
    if ($_REQUEST['target_action'] == 'QuickCreate'){
    $this->ev->view = 'QuickCreate';
    }
    $form_name = 'form_Subpanel'.$this->ev->view .'_'.$module;
    $this->ev->formName = $form_name;
    $this->ev->process(true, $form_name);
    echo $this->ev->display(false, true);
    }
    protected function getEditView() {
    return new EditView();
    }
    // my function to find if a custom 'for_parentmodule_quickcreatedefs' exists
    public function getModuleViewDefsSourceFile($module, $view, $parentmodule) {
    $base = 'modules/'.$module.'/metadata/';
    $source = 'custom/'.$base.'for_'.$parentmodule.'_'.strtolower($view) .'defs.php';
    if (!file_exists($source)) {
    $source = 'custom/'.$base.strtolower($view).'defs.php';
    if (!file_exists($source)) {
    $source = $base.strtolower($view).'defs.php';
    if (!file_exists($source)) {
    $this->viewType = 'EditView';
    $source = 'custom/'.$base.'editviewdefs.php';
    if (!file_exists($source)) {
    $source = $base.'editviewdefs.php';
    }
    }
    }
    }
    return $source;
    }
    }
    ?>

    4) The aim of this previous file is to rewrite the function "getModuleViewDefsSourceFile" in order to check if it exists a "specific quickcreadef" file for a subpanel within a module detailview

    5) For our example, create in "custom/modules/Contacts/metadata" directory a file called "for_opportunities_quickcreatedefs.php"

    That's all... feed this file with what you want specific.. U can also customize the buttons linked to this subpanel in order to pass some values etc...

    6) Last point, in "MineSubpanelQuickCreate.php", you can there allow or not the user to click on the usual "Full form button" with this piece of code :

    if (($module!="Contacts")&&($parentmodule=="opportuni ties")) {
    $this->ev->defs['templateMeta']['form']['buttons'] = array('SUBPANELSAVE', 'SUBPANELCANCEL', 'SUBPANELFULLFORM');
    } else {
    $this->ev->defs['templateMeta']['form']['buttons'] = array('SUBPANELSAVE', 'SUBPANELCANCEL');
    }

    Good luck... I hope I didn't forget anything in my humble demo (with so many hours those last 4 years playing with the code, in order to have upgrade safe solution, may be I did forget a small piece of code over there.. U'll tell me)

    I do hope I will be useful

    (may be same kind of posts and solutions do exist... sorry about that... I confess that I did leave the forum for months...)
    Last edited by franckt; 2013-07-19 at 08:20 PM.

  2. #2
    hats Guest

    Default Re: Custom quickcreate subpanel form

    Hi franckt,

    Thanks. Sure it is and will be helpful.

    Regards

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 2013-06-25, 12:26 PM
  2. How to validate QuickCreate form in subpanel
    By karlee in forum Sugar Developer Website
    Replies: 3
    Last Post: 2009-06-16, 01:04 PM
  3. Add Custom Field to QuickCreate Subpanel
    By Meex in forum Developer Help
    Replies: 1
    Last Post: 2007-11-06, 09:56 AM
  4. Replies: 9
    Last Post: 2007-07-02, 02:00 PM
  5. Replies: 2
    Last Post: 2007-06-01, 02:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •