File   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A renderInner() 0 20 1
A renderScript() 0 19 1
1
<?php
2
namespace Rocket\UI\Forms\Fields;
3
4
/**
5
 * Manage file fields
6
 */
7
8
/**
9
 * Creates a file field
10
 *
11
 * @author Stéphane Goetz
12
 */
13
class File extends Field
14
{
15
    /**
16
     * Extends the type
17
     * @param string $id
18
     * @param array $data
19
     */
20
    public function __construct($id, $data = [])
21
    {
22
        $this->type = 'file';
23
24
        parent::__construct($id, $data);
25
    }
26
27
    /**
28
     * Creates a field with special tags
29
     */
30
    protected function renderInner()
31
    {
32
        $this->input_attributes['type'] = 'text';
33
        $this->input_attributes['id'] = $this->id . '__fake';
34
        $this->input_attributes['value'] = '';
35
        $wrong_one = '<input' . $this->renderAttributes($this->input_attributes) . ' />';
36
37
        $this->input_attributes['type'] = 'file';
38
        $this->input_attributes['class'][] = 'file';
39
        $this->input_attributes['id'] = $this->id;
40
        $real_file = '<input' . $this->renderAttributes($this->input_attributes) . ' />';
41
42
        $this->result .= '<span class="fileinputs">';
43
        $this->result .= $real_file;
44
        $this->result .= '<span class="fakefile">';
45
        $this->result .= $wrong_one;
46
        $this->result .= '<input type="button"' . ' value="Browse" class="button_button" />';
47
        $this->result .= '</span>';
48
        $this->result .= '</span>';
49
    }
50
51
    /**
52
     * Renders the scripts
53
     */
54
    protected function renderScript()
55
    {
56
        $this->getJS()->ready(
57
            "$('#" . $this->id . "')
58
                .bind('change', function() {
59
                    $('#" . $this->id . "__fake').val($('#" . $this->id . "').val());
60
                })
61
                .bind('mouseover', function() {
62
                    $('#" . $this->id . "__fake').addClass('hover');
63
                })
64
                .bind('mouseout', function() {
65
                    $('#" . $this->id . "__fake').val($('#" . $this->id . "').val()).removeClass('hover');
66
                });
67
            $('#" . $this->id . "__fake').bind('focus', function(){
68
                $('#" . $this->id . "').click();
69
                $('#" . $this->id . "__fake').blur();
70
            });"
71
        );
72
    }
73
}
74