dolibarr  7.0.0-beta
admin_extrafields_add.tpl.php
1 <?php
2 /* Copyright (C) 2010-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
4  * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
29 // Protection to avoid direct call of template
30 if (empty($conf) || ! is_object($conf))
31 {
32  print "Error, template page can't be called as URL";
33  exit;
34 }
35 
36 
37 $langs->load("modulebuilder");
38 
39 ?>
40 
41 <!-- BEGIN PHP TEMPLATE admin_extrafields_add.tpl.php -->
42 <script type="text/javascript">
43  jQuery(document).ready(function() {
44  function init_typeoffields(type)
45  {
46  console.log("We select a new type = "+type);
47  var size = jQuery("#size");
48  var computed_value = jQuery("#computed_value");
49  var langfile = jQuery("#langfile");
50  var default_value = jQuery("#default_value");
51  var unique = jQuery("#unique");
52  var required = jQuery("#required");
53  var alwayseditable = jQuery("#alwayseditable");
54  var list = jQuery("#list");
55  <?php
56  if ((GETPOST('type','alpha') != "select") && (GETPOST('type','alpha') != "sellist"))
57  {
58  print 'jQuery("#value_choice").hide();';
59  }
60 
61  if (GETPOST('type','alpha') == "separate")
62  {
63  print "jQuery('#size, #default_value, #langfile').val('').prop('disabled', true);";
64  print 'jQuery("#value_choice").hide();';
65  }
66  ?>
67 
68  // Case of computed field
69  console.log(type);
70  if (type == '' || type == 'varchar' || type == 'int' || type == 'double' || type == 'price') {
71  jQuery("tr.extra_computed_value").show();
72  } else {
73  computed_value.val(''); jQuery("tr.extra_computed_value").hide();
74  }
75  if (computed_value.val())
76  {
77  console.log("We enter a computed formula");
78  jQuery("#default_value").val('');
79  /* jQuery("#unique, #required, #alwayseditable, #list").removeAttr('checked'); */
80  jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', true);
81  jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").hide();
82  }
83  else
84  {
85  console.log("No computed formula");
86  jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', false);
87  jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").show();
88  }
89 
90  if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
91  else if (type == 'datetime') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
92  else if (type == 'double') { size.val('24,8').removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
93  else if (type == 'int') { size.val('10').removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
94  else if (type == 'text') { size.val('2000').removeAttr('disabled'); unique.prop('disabled', true).removeAttr('checked'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
95  else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
96  else if (type == 'boolean') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide();}
97  else if (type == 'price') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide();}
98  else if (type == 'select') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
99  else if (type == 'sellist') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").show();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
100  else if (type == 'radio') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
101  else if (type == 'checkbox') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
102  else if (type == 'chkbxlst') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").show();jQuery("#helplink").hide();}
103  else if (type == 'link') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").show();}
104  else if (type == 'separate') {
105  langfile.val('').prop('disabled',true);size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); required.val('').prop('disabled', true);
106  jQuery("#value_choice").hide();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();
107  }
108  else { // type = string
109  size.val('').prop('disabled', true);
110  unique.removeAttr('disabled');
111  }
112 
113  if (type == 'separate')
114  {
115  required.removeAttr('checked').prop('disabled', true); alwayseditable.removeAttr('checked').prop('disabled', true); list.removeAttr('checked').prop('disabled', true);
116  jQuery('#size, #default_value, #langfile').val('').prop('disabled', true);
117  jQuery('#list').val(3); // visible on create/update/view form only
118  }
119  else
120  {
121  default_value.removeAttr('disabled');
122  langfile.removeAttr('disabled');required.removeAttr('disabled'); alwayseditable.removeAttr('disabled'); list.removeAttr('disabled');
123  }
124  }
125  init_typeoffields('<?php echo GETPOST('type','alpha'); ?>');
126  jQuery("#type").change(function() {
127  init_typeoffields($(this).val());
128  });
129 
130  // If we enter a formula, we disable other fields
131  jQuery("#computed_value").keyup(function() {
132  init_typeoffields(jQuery('#type').val());
133  });
134  });
135 </script>
136 
137 <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
138 <input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>">
139 <input type="hidden" name="action" value="add">
140 
141 <?php dol_fiche_head(); ?>
142 
143 <table summary="listofattributes" class="border centpercent">
144 <!-- Label -->
145 <tr><td class="titlefield fieldrequired"><?php echo $langs->trans("Label"); ?></td><td class="valeur"><input type="text" name="label" size="40" value="<?php echo GETPOST('label','alpha'); ?>"></td></tr>
146 <!-- Code -->
147 <tr><td class="fieldrequired"><?php echo $langs->trans("AttributeCode"); ?></td><td class="valeur"><input type="text" name="attrname" id="attrname" size="10" value="<?php echo GETPOST('attrname','alpha'); ?>"> (<?php echo $langs->trans("AlphaNumOnlyLowerCharsAndNoSpace"); ?>)</td></tr>
148 <!-- Type -->
149 <tr><td class="fieldrequired"><?php echo $langs->trans("Type"); ?></td><td class="valeur">
150 <?php print $form->selectarray('type',$type2label,GETPOST('type','alpha')); ?>
151 </td></tr>
152 <!-- Size -->
153 <tr class="extra_size"><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td class="valeur"><input id="size" type="text" name="size" size="5" value="<?php echo (GETPOST('size','alpha')?GETPOST('size','alpha'):''); ?>"></td></tr>
154 <!-- Default Value (for select list / radio/ checkbox) -->
155 <tr id="value_choice">
156 <td>
157  <?php echo $langs->trans("Value"); ?>
158 </td>
159 <td>
160  <table class="nobordernopadding">
161  <tr><td>
162  <textarea name="param" id="param" cols="80" rows="<?php echo ROWS_4 ?>"><?php echo GETPOST('param','alpha'); ?></textarea>
163  </td><td>
164  <span id="helpselect"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpselect"),1,0,'', 0, 2, 'helpvalue1')?></span>
165  <span id="helpsellist"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpsellist"),1,0,'', 0, 2, 'helpvalue2')?></span>
166  <span id="helpchkbxlst"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelpchkbxlst"),1,0,'', 0, 2, 'helpvalue3')?></span>
167  <span id="helplink"><?php print $form->textwithpicto('', $langs->trans("ExtrafieldParamHelplink"),1,0,'', 0, 2, 'helpvalue4')?></span>
168  </td></tr>
169  </table>
170 </td>
171 </tr>
172 <!-- Position -->
173 <tr><td class="titlefield"><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo GETPOST('pos','int'); ?>"></td></tr>
174 <!-- Language file -->
175 <tr><td class="titlefield"><?php echo $langs->trans("LanguageFile"); ?></td><td class="valeur"><input type="text" id="langfile" name="langfile" class="minwidth200" value="<?php echo dol_escape_htmltag(GETPOST('langfile','alpha')); ?>"></td></tr>
176 <!-- Computed Value -->
177 <tr class="extra_computed_value"><td><?php echo $form->textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?></td><td class="valeur"><input id="computed_value" type="text" name="computed_value" class="quatrevingtpercent" value="<?php echo (GETPOST('computed_value','none')?GETPOST('computed_value','none'):''); ?>"></td></tr>
178 <!-- Default Value (at sql setup level) -->
179 <tr class="extra_default_value"><td><?php echo $langs->trans("DefaultValue").' ('.$langs->trans("Database").')'; ?></td><td class="valeur"><input id="default_value" type="text" name="default_value" size="5" value="<?php echo (GETPOST('default_value','alpha')?GETPOST('default_value','alpha'):''); ?>"></td></tr>
180 <!-- Unique -->
181 <tr class="extra_unique"><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique"<?php echo (GETPOST('unique','alpha')?' checked':''); ?>></td></tr>
182 <!-- Required -->
183 <tr class="extra_required"><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo (GETPOST('required','alpha')?' checked':''); ?>></td></tr>
184 <!-- Always editable -->
185 <tr class="extra_alwayseditable"><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ((GETPOST('alwayseditable','alpha') || ! GETPOST('button','alpha'))?' checked':''); ?>></td></tr>
186 <?php if ($conf->multicompany->enabled) { ?>
187  <tr><td><?php echo $langs->trans("AllEntities"); ?></td><td class="valeur"><input id="entitycurrentorall" type="checkbox" name="entitycurrentorall"<?php echo (GETPOST('entitycurrentorall','alpha') ? '':' checked'); ?>></td></tr>
188 <?php } ?>
189 <!-- Visibility -->
190 <tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
191 </td><td class="valeur"><input id="list" size="1" type="text" name="list" value="<?php echo GETPOST('list','int')!='' ? GETPOST('list','int') : '1'; ?>"></td></tr>
192 </table>
193 
194 <?php dol_fiche_end(); ?>
195 
196 <div align="center"><input type="submit" name="button" class="button" value="<?php echo $langs->trans("Save"); ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
197 <input type="submit" name="button" class="button" value="<?php echo $langs->trans("Cancel"); ?>"></div>
198 
199 </form>
200 
201 <!-- END PHP TEMPLATE admin_extrafields_add.tpl.php -->
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_fiche_end($notab=0)
Show tab footer of a card.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
print
Draft customers invoices.
Definition: index.php:91
type
Definition: viewcat.php:283