ajaxgetcustoms.html.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * The ajaxgetcustoms view file of instance module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2024 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Yanyi Cao <caoyanyi@chandao.com>
  7. * @package instance
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. if($customFields)
  12. {
  13. h::css(<<<CSS
  14. .instance-custom-fields-block.hidden, #createStoreAppForm .form-row-group {display: block !important;}
  15. .custom-field-label.required:before {
  16. content: "*";
  17. display: inline-block;
  18. margin-right: .25rem;
  19. --tw-translate-y: 0.125rem;
  20. --tw-scale-x: 1.25;
  21. --tw-scale-y: 1.25;
  22. transform: translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
  23. --tw-text-opacity: 1;
  24. color: rgba(var(--color-danger-500-rgb),var(--tw-text-opacity))
  25. }
  26. CSS
  27. );
  28. if(!$instanceID)
  29. {
  30. h::css('#customFieldsTable tr {border: none;} .custom-field-label {width: 140px; text-align: right; padding-right: 0.5rem !important;} .custom-field-value {padding: 0.5rem 0 !important;}');
  31. }
  32. $buildFormWg = function($field) use ($config)
  33. {
  34. if(!empty($field->autocomplete))
  35. {
  36. $ref = explode('.', $field->autocomplete);
  37. if(count($ref) == 2 && empty($field->value))
  38. {
  39. switch($field->autocomplete)
  40. {
  41. case 'zentao.http_protocol':
  42. $field->value = strstr(getWebRoot(true), ':', true);
  43. break;
  44. case 'zentao.http_host':
  45. $field->value = trim(strstr(getWebRoot(true), ':', false), ':/');
  46. break;
  47. case 'zentao.webroot':
  48. $field->value = getWebRoot();
  49. break;
  50. case 'zentao.xxd_token':
  51. $field->value = zget($config->xuanxuan, 'key', '');
  52. break;
  53. default:
  54. break;
  55. }
  56. }
  57. }
  58. if($field->type == 'switch') $field->type = 'switcher';
  59. $isInput = in_array($field->type, array('text', 'password', 'number'));
  60. $isSelect = in_array($field->type, array('select', 'radio', 'checkbox'));
  61. if($isSelect)
  62. {
  63. if(!empty($field->options_api)) $field->options = $this->instance->getOptionsByApi($field->options_api);
  64. $field->options = array_column($field->options, 'text', 'value');
  65. if($field->type == 'radio') $field->type = 'radioList';
  66. if($field->type == 'select') $field->type = 'picker';
  67. if($field->type == 'checkbox') $field->type = 'checkList';
  68. }
  69. $value = empty($field->value) ? $field->default : $field->value;
  70. if($field->type == 'switcher') $value = 1;
  71. if($field->type == 'checkList' || $field->style == 'multi') $value = is_array($value) ? $value : explode(zget($field, 'separator', ','), (string)$value);
  72. return control(setClass('custom-field'), set::type($field->type), set::name($field->name . ($field->type == 'checkList' ? '[]' : '')), set::value($value), set::placeholder($field->desc), set::required($field->required), $field->type == 'switcher' && ($field->default || !empty($field->value)) ? set::checked((bool)zget($field, 'value', $field->default)) : null, $isInput ? set::placeholder($field->desc) : null, $isInput ? set::autocomplete('new-password') : null, $isInput ? set::maxlength(zget($field, 'length', 255)) : null, $field->type == 'number' ? set::min(zget($field, 'min', 0)) : null, $field->type == 'number' ? set::min(zget($field, 'min', 0)) : null, $field->type == 'number' ? set::step(zget($field, 'step', 1)) : null, $isSelect ? set::items($field->options) : null, strpos($field->type, 'List') ? set::inline($field->style == 'inline') : null, $field->type == 'picker' ? set::multiple($field->style == 'multi') : null);
  73. };
  74. $dependFields = array();
  75. foreach($customFields as $field)
  76. {
  77. if(!empty($field->depends))
  78. {
  79. foreach($field->depends as $dependField) $dependFields[$dependField->key][] = $field->name;
  80. }
  81. if(!hasPriv('instance', 'manage') && $field->type == 'password') $field->value = preg_replace('/./', '*', $field->value);
  82. $fields[] = h::tr
  83. (
  84. setClass("{$field->name}-row-tr", empty($field->depends) ? null : 'hidden'),
  85. h::td
  86. (
  87. setClass('custom-field-label', !empty($field->required) ? 'required' : null),
  88. zget($lang->instance, $field->name, $field->label)
  89. ),
  90. h::td
  91. (
  92. setClass('custom-field-value', in_array($field->type, array('text', 'password', 'number')) ? 'input-box' : null),
  93. hasPriv('instance', 'manage') ? $buildFormWg($field) : $field->value
  94. ),
  95. $instanceID ? h::td($field->desc) : null
  96. );
  97. }
  98. jsVar('dependFields', $dependFields);
  99. jsVar('customFields', array_column($customFields, null, 'name'));
  100. h::table
  101. (
  102. setID('customFieldsTable'),
  103. setClass('table w-full max-w-full', $instanceID ? 'bordered mt-4' : null),
  104. on::input('#customFieldsTable input')->call('window.setCustomField', jsRaw('this')),
  105. on::change('#customFieldsTable .picker-box input, #customFieldsTable select')->call('window.setCustomField', jsRaw('this')),
  106. $instanceID ? h::tr
  107. (
  108. h::th(setClass('w-1/3'), $lang->instance->custom->name),
  109. h::th($lang->instance->custom->value),
  110. h::th(setClass('w-1/3'), $lang->instance->custom->desc)
  111. ) : null,
  112. $fields,
  113. $instanceID && hasPriv('instance', 'manage') ? h::tr
  114. (
  115. h::td(
  116. set::colspan(3),
  117. setClass('no-label text-center'),
  118. btn
  119. (
  120. setClass('primary custom-btn disabled'),
  121. $lang->save
  122. )
  123. )
  124. ) : null
  125. );
  126. }