1<?php
2/**
3 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
4 * all the essential functionalities required for any enterprise.
5 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
6 *
7 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
8 * the GNU General Public License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along with this program;
16 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA  02110-1301, USA
18 *
19 */
20?>
21
22<?php
23
24function getSortClass($column, $sortField, $sortOrder) {
25
26    if (isset($sortField) && isset($sortOrder) && $column == $sortField) {
27        $class = ' headerSort';
28        $class .= ($sortOrder == 'ASC')?'Up':'Down';
29        return $class;
30    }
31
32    return '';
33
34}
35
36?>
37
38<div id="customFieldAddPane" style="display: none;" class="box">
39
40    <div class="head">
41        <h1 id="heading"><?php echo __('Add Custom Field'); ?></h1>
42    </div>
43
44    <div class="inner">
45
46        <form name="frmCustomField" id="frmCustomField" method="post" action="<?php echo url_for('pim/defineCustomField'); ?>">
47
48            <?php echo $form['_csrf_token']; ?>
49            <?php echo $form["field_num"]->render(); ?>
50
51            <fieldset>
52
53                <ol>
54
55                    <li>
56                        <?php echo $form['name']->renderLabel(__('Field Name') . ' <em>*</em>'); ?>
57                        <?php echo $form['name']->render(array("maxlength" => 250)); ?>
58                    </li>
59
60                    <li>
61                        <?php echo $form['screen']->renderLabel(__('Screen') . ' <em>*</em>'); ?>
62                        <?php echo $form['screen']->render(); ?>
63                    </li>
64
65                    <li>
66                        <?php echo $form['type']->renderLabel(__('Type') . ' <em>*</em>'); ?>
67                        <?php echo $form['type']->render(); ?>
68                    </li>
69
70                    <?php $showExtra = ($form->getValue('type') == CustomField::FIELD_TYPE_SELECT) ? 'block' : 'none'; ?>
71                    <li style="display:<?php echo $showExtra; ?>;" id="selectOptions" class="fieldHelpContainer">
72                        <?php echo $form['extra_data']->renderLabel(__('Select Options') . ' <em>*</em>'); ?>
73                        <?php echo $form['extra_data']->render(); ?>
74                        <label class="fieldHelpBottom"><?php echo __("Enter allowed options separated by commas"); ?></label>
75                    </li>
76
77                    <li class="required">
78                        <em>*</em> <?php echo __(CommonMessages::REQUIRED_FIELD); ?>
79                    </li>
80
81                </ol>
82
83                <p>
84                    <input type="button" class="" name="btnSave" id="btnSave" value="<?php echo __("Save"); ?>"/>
85                    <input type="button" class="reset" id="btnCancel" value="<?php echo __("Cancel"); ?>"/>
86                </p>
87
88            </fieldset>
89
90        </form>
91
92    </div>
93
94</div> <!-- End of customFieldAddPane -->
95
96
97<div class="box miniList" id="customFieldListPane">
98
99    <div class="head">
100        <h1><?php echo __("Defined Custom Fields") ?></h1>
101    </div>
102
103    <div class="inner">
104
105        <?php include_partial('global/flash_messages'); ?>
106
107        <form name="standardView" id="standardView" method="post" action="<?php echo url_for('pim/deleteCustomFields') ?>">
108
109            <?php
110            echo $deleteForm['_csrf_token'];
111
112            $fieldsInUse = count($listCustomField);
113            $fieldsLeft = CustomField::MAX_FIELD_NUM - $fieldsInUse;
114            $fieldsLeftMsg = '';
115            if ($fieldsLeft == 0) {
116                $fieldsLeftMsg = __("All customs fields are in use");
117            } else {
118                $fieldsLeftMsg = __("Remaining number of custom fields") . ": $fieldsLeft";
119            }
120            ?>
121            <fieldset>
122                <p id="listActions">
123                    <input type="hidden" name="mode" id="mode" value=""></input>
124
125                    <?php if ($fieldsLeft > 0) { ?>
126                        <input type="button" class="" id="buttonAdd" value="<?php echo __("Add") ?>" />
127                    <?php } ?>
128                    <input type="button" class="delete" id="buttonRemove" value="<?php echo __('Delete'); ?>"/>
129                    <span id="fieldsleft"><?php echo $fieldsLeftMsg; ?></span>
130                </p>
131            </fieldset>
132
133            <table class="table hover" id="customFieldList">
134                <thead>
135                    <tr>
136                        <th class="check" style="width:2%">
137                            <?php if ($fieldsInUse > 0) { ?>
138                                <input type="checkbox" class="checkbox" name="allCheck" value="" id="allCheck" />
139                            <?php } ?>
140                        </th>
141
142                        <th class="fieldName header<?php echo getSortClass('name', $sortField, $sortOrder); ?>" style="width:35%">
143                            <?php echo $sorter->sortLink('name', __('Custom Field Name'), '@customfield_list', ESC_RAW); ?>
144                        </th>
145                        <th style="width:35%" class="header<?php echo getSortClass('screen', $sortField, $sortOrder); ?>">
146                            <?php echo $sorter->sortLink('screen', __('Screen'), '@customfield_list', ESC_RAW); ?>
147                        </th>
148                        <th style="width:28%" class="header<?php echo getSortClass('type', $sortField, $sortOrder); ?>">
149                            <?php echo $sorter->sortLink('type', __('Field Type'), '@customfield_list', ESC_RAW); ?>
150                        </th>
151
152                    </tr>
153                </thead>
154
155                <tbody>
156                    <?php
157                    $row = 0;
158                    $screens = $form->getScreens();
159                    $fieldTypes = $form->getFieldTypes();
160
161                    foreach ($listCustomField as $customField) {
162                        $cssClass = ($row % 2) ? 'even' : 'odd';
163                        $row = $row + 1;
164                        $fieldNum = $customField->getFieldNum();
165                        ?>
166                        <tr class="<?php echo $cssClass ?>">
167                            <td class="check">
168                                <input type='checkbox' class='checkbox innercheckbox' name='chkLocID[]' value='<?php echo $fieldNum ?>' />
169                            </td>
170                            <td class="fieldName">
171                                <a href="#"><?php echo $customField->getName() ?></a>
172                            </td>
173                            <td>
174                                <?php
175                                $screenId = $customField->getScreen();
176                                echo isset($screens[$screenId]) ? $screens[$screenId] : $screenId;
177                                ?>
178                                <input type="hidden" id="screen_<?php echo $fieldNum; ?>" value="<?php echo $screenId; ?>"/>
179                            </td>
180                            <td>
181                                <?php
182                                $type = $customField->getType();
183                                $typeDesc = isset($fieldTypes[$type]) ? $fieldTypes[$type] : $type;
184                                echo $typeDesc;
185                                ?>
186                                <input type="hidden" id="type_<?php echo $fieldNum; ?>" value="<?php echo $type; ?>"/>
187                                <input type="hidden" id="extra_data_<?php echo $fieldNum; ?>" value="<?php echo $customField->getExtraData(); ?>"/>
188                            </td>
189                        </tr>
190                    <?php } ?>
191                </tbody>
192            </table>
193
194        </form>
195
196    </div>
197
198</div> <!-- End of list -->
199
200<!-- Confirmation box HTML: Begins -->
201<div class="modal hide" id="deleteConfModal">
202    <div class="modal-header">
203        <a class="close" data-dismiss="modal">×</a>
204        <h3><?php echo __('OrangeHRM - Confirmation Required'); ?></h3>
205    </div>
206    <div class="modal-body">
207        <p><?php echo __('Will be deleted from all employees'); ?></p>
208        <br>
209        <p><?php echo __(CommonMessages::DELETE_CONFIRMATION); ?></p>
210    </div>
211    <div class="modal-footer">
212        <input type="button" class="btn" data-dismiss="modal" id="dialogDeleteBtn" value="<?php echo __('Ok'); ?>" />
213        <input type="button" class="btn reset" data-dismiss="modal" value="<?php echo __('Cancel'); ?>" />
214    </div>
215</div>
216<!-- Confirmation box HTML: Ends -->
217
218<script type="text/javascript">
219
220    $(document).ready(function() {
221
222        /* Handling loading view */
223
224        var fieldsInUse = <?php echo count($listCustomField); ?>;
225
226        if (fieldsInUse == 0) {
227            $('#customFieldAddPane').css('display', 'block');
228            $('#customFieldListPane').css('display', 'none');
229            $('#btnCancel').css('display', 'none');
230        } else {
231            $('#customFieldAddPane').css('display', 'none');
232            //$('#customFieldListPane').css('display', 'block');
233        }
234
235
236
237        hideextra();
238
239        function hideextra() {
240            if ($('#customField_type').val() == <?php echo CustomField::FIELD_TYPE_SELECT; ?>) {
241                $('#selectOptions').show();
242            } else {
243                $('#selectOptions').hide();
244            }
245        }
246
247        $("#buttonRemove").attr('disabled', 'disabled');
248
249        // When Click Main Tick box
250        $("#allCheck").click(function() {
251            if ($('#allCheck').prop('checked')){
252                $('.innercheckbox').prop('checked', true);
253                $("#buttonRemove").removeAttr('disabled');
254            } else{
255                $('.innercheckbox').prop('checked', false);
256                $("#buttonRemove").attr('disabled', 'disabled');
257            }
258        });
259
260        $(".innercheckbox").click(function() {
261            if($(this).prop('checked'))
262            {
263                $("#buttonRemove").removeAttr('disabled');
264            }else
265            {
266                $('#allCheck').prop('checked', false);
267                $("#buttonRemove").attr('disabled', 'disabled');
268            }
269
270            if($(".innercheckbox").is(':checked')) {
271                $('#buttonRemove').removeAttr('disabled');
272            } else {
273                $('#buttonRemove').attr('disabled','disabled');
274            }
275        });
276
277        //When click remove button
278        $("#buttonRemove").click(function(event) {
279
280            event.preventDefault();
281
282            var checked = $('#customFieldList tbody input.checkbox:checked').length;
283
284            if ( checked == 0) {
285                $('#messagebar').text('<?php echo __js(TopLevelMessages::SELECT_RECORDS) ?>').attr('class', 'messageBalloon_notice');
286            } else {
287                $('#messagebar').text('').attr('class', '');
288
289                var fields = '';
290                $('#customFieldList tbody input.checkbox:checked').each(function(index) {
291                    var name = $(this).parent().next().find('a').text().trim();
292                    if (index == 0) {
293                        fields = name;
294                    } else {
295                        fields = fields + ', ' + name;
296                    }
297                });
298
299                $('#deleteConfModal').modal();
300                return false;
301            }
302        });
303
304        $('#dialogDeleteBtn').click(function() {
305            $("#mode").attr('value', 'delete');
306            $("#standardView").submit();
307        });
308
309        /* Valid From Date */
310        $.validator.addMethod("validateExtra", function(value, element) {
311
312            if ($('#customField_type').val() == <?php echo CustomField::FIELD_TYPE_SELECT; ?>) {
313                var extraVal = $.trim($('#customField_extra_data').val());
314                var len = extraVal.length;
315                if (len == 0) {
316                    return false;
317                }
318            }
319            return true;
320        });
321
322        //form validation
323        var formValidator =
324            $("#frmCustomField").validate({
325            rules: {
326                'customField[name]': {required: true},
327                'customField[type]': {required: true},
328                'customField[screen]': {required: true},
329                'customField[extra_data]': {validateExtra: true}
330            },
331            messages: {
332                'customField[name]': {required: '<?php echo __js(ValidationMessages::REQUIRED); ?>'},
333                'customField[type]': {required: '<?php echo __js(ValidationMessages::REQUIRED); ?>'},
334                'customField[screen]': {required: '<?php echo __js(ValidationMessages::REQUIRED); ?>'},
335                'customField[extra_data]' : {validateExtra: '<?php echo __js(ValidationMessages::REQUIRED); ?>'}
336            }
337        });
338
339        $('#customField_type').change(function() {
340            hideextra();
341        });
342
343        function clearAddForm() {
344            $('#customField_field_num').val('');
345            $('#customField_name').val('');
346            $('#customField_type').val('');
347            $('#customField_screen').val('');
348            $('#customField_extra_data').val('');
349            $('div#customFieldAddPane label.error').hide();
350            $('div#messagebar').text('').attr('class', '');
351        }
352
353        function addEditLinks() {
354            removeEditLinks();
355            $('#customFieldList tbody td.fieldName').wrapInner('<a href="#"/>');
356        }
357
358        function removeEditLinks() {
359            $('#customFieldList tbody td.fieldName a').each(function(index) {
360                $(this).parent().text($(this).text());
361            });
362        }
363
364        $('#btnCancel').click(function() {
365            clearAddForm();
366            $('#customFieldAddPane').css('display', 'none');
367            $('#listActions').show();
368            $('#customFieldList .check').show();
369            addEditLinks();
370            $('div#messagebar').text('').attr('class', '');
371            $(".paddingLeftRequired").hide();
372
373            $('div.error').each(function(){
374                $(this).hide();
375            });
376
377        });
378
379        // Add a emergency contact
380        $('#buttonAdd').click(function() {
381            $("#heading").text("<?php echo __js("Add Custom Field"); ?>");
382            clearAddForm();
383
384            // Hide list action buttons and checkbox
385            $('#listActions').hide();
386            $('#customFieldList .check').hide();
387            removeEditLinks();
388            $('div#messagebar').text('').attr('class', '');
389
390            hideextra();
391
392            //
393            //            // hide validation error messages
394            //            $("label.errortd[generated='true']").css('display', 'none');
395            $('#customFieldAddPane').css('display', 'block');
396
397        });
398
399        $(document).on('click', '#customFieldList tbody a', function() {
400            $("#heading").text("<?php echo __js("Edit Custom Field"); ?>");
401
402            var row = $(this).closest("tr");
403            var fieldNo = row.find('input.checkbox:first').val();
404            var name = $(this).text();
405            var type = $("#type_" + fieldNo).val();
406            var screen = $("#screen_" + fieldNo).val();
407            var extraData = $("#extra_data_" + fieldNo).val();
408
409            $('#customField_field_num').val(fieldNo);
410            $('#customField_name').val(name);
411            $('#customField_type').val(type);
412            $('#customField_screen').val(screen);
413            $('#customField_extra_data').val(extraData);
414
415
416            $('div#messagebar').text('').attr('class', '');
417            hideextra();
418            // hide validation error messages
419
420            $('#listActions').hide();
421            $('#customFieldList .check').hide();
422            $('#customFieldAddPane').css('display', 'block');
423
424        });
425
426        $('#btnSave').click(function() {
427            $('#frmCustomField').submit();
428        });
429
430    });
431
432</script>
433
434