BxDevFormsSearchFields.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Developer Developer
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxDevFormsSearchFields extends BxTemplStudioFormsSearchFields
  12. {
  13. protected $oModule;
  14. function __construct($aOptions, $oTemplate = false)
  15. {
  16. parent::__construct($aOptions, $oTemplate);
  17. $this->oModule = BxDolModule::getInstance('bx_developer');
  18. $this->sUrlPage = BX_DOL_URL_STUDIO . 'module.php?name=' . $this->oModule->_oConfig->getName() . '&page=forms&form_page=search_fields';
  19. $this->_aOptions['actions_single']['edit']['attr']['title'] = _t('_bx_dev_frm_btn_search_forms_fields_edit');
  20. $sModule = bx_get('form_module');
  21. if(!empty($sModule)) {
  22. $this->sModule = bx_process_input($sModule);
  23. $this->_aQueryAppend['module'] = $this->sModule;
  24. }
  25. $sForm = bx_get('form_form');
  26. if(!empty($sForm)) {
  27. $this->sForm = bx_process_input($sForm);
  28. $this->_aQueryAppend['form'] = $this->sForm;
  29. }
  30. }
  31. public function performActionEdit()
  32. {
  33. $sAction = 'edit';
  34. $sFormObject = $this->oModule->_oConfig->getObject('form_forms_search_fields');
  35. $sFormDisplay = $this->oModule->_oConfig->getObject('form_display_forms_search_fields_edit');
  36. $aIds = bx_get('ids');
  37. if(!$aIds || !is_array($aIds)) {
  38. $iId = (int)bx_get('id');
  39. if(!$iId) {
  40. echoJson(array());
  41. exit;
  42. }
  43. $aIds = array($iId);
  44. }
  45. $iId = $aIds[0];
  46. $aField = array();
  47. $iField = $this->oDb->getSearchFields(array('type' => 'by_id', 'id' => $iId), $aField);
  48. if($iField != 1 || empty($aField)){
  49. echoJson(array());
  50. exit;
  51. }
  52. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay, $this->oModule->_oTemplate);
  53. $oForm->aFormAttrs['action'] = bx_append_url_params(BX_DOL_URL_ROOT . 'grid.php?', array(
  54. 'o' => $this->_sObject,
  55. 'a' => $sAction,
  56. 'module' => $this->sModule,
  57. 'form' => $this->sForm
  58. ));
  59. $aForms = array();
  60. $this->oDb->getSearchForms(array('type' => 'by_module', 'module' => $this->sModule), $aForms, false);
  61. $oForm->aInputs['object']['value'] = $this->sForm;
  62. $oForm->aInputs['object']['values'] = array();
  63. foreach($aForms as $aForm)
  64. $oForm->aInputs['object']['values'][$aForm['object']] = _t($aForm['title']);
  65. asort($oForm->aInputs['object']['values']);
  66. $oForm->aInputs['object']['values'] = array_merge(array('' => _t('_bx_dev_frm_txt_select_object')), $oForm->aInputs['object']['values']);
  67. foreach(BxDolSearchExtended::$SEARCHABLE_TYPES as $sType)
  68. $oForm->aInputs['type']['values'][] = array('key' => $sType, 'value' => _t('_adm_form_txt_field_type_' . $sType));
  69. foreach(BxDolSearchExtended::$TYPE_TO_TYPE_SEARCH[$aField['type']] as $sType)
  70. $oForm->aInputs['search_type']['values'][] = array('key' => $sType, 'value' => _t('_adm_form_txt_field_type_' . $sType));
  71. foreach(BxDolSearchExtended::$TYPE_TO_OPERATOR[$aField['type']] as $sOperator)
  72. $oForm->aInputs['search_operator']['values'][] = array('key' => $sOperator, 'value' => $sOperator);
  73. $oForm->initChecker($aField);
  74. if($oForm->isSubmittedAndValid()) {
  75. if($oForm->update($iId) !== false)
  76. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  77. else
  78. $aRes = array('msg' => _t('_bx_dev_frm_err_search_fields_edit'));
  79. return echoJson($aRes);
  80. }
  81. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-frm-search-fields-edit-popup', _t('_bx_dev_frm_txt_search_fields_edit_popup', _t($aField['caption'])), $this->_oTemplate->parseHtmlByName('form_add_search_field.html', array(
  82. 'form_id' => $oForm->aFormAttrs['id'],
  83. 'form' => $oForm->getCode(true),
  84. 'object' => $this->_sObject,
  85. 'action' => $sAction
  86. )));
  87. return echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  88. }
  89. protected function _getActionEdit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  90. {
  91. if($sType == 'single' && !$this->_isEditable($aRow))
  92. return '';
  93. return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
  94. }
  95. }
  96. /** @} */