Passed
Push — develop ( 28c299...928e2a )
by Mathias
12:40
created

Job::getEventManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
ccs 0
cts 6
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** Jobs forms */
11
namespace Jobs\Form;
12
13
use Core\Form\Event\FormEvent;
14
use Core\Form\WizardContainer;
15
use Zend\EventManager\EventManager;
16
use Zend\EventManager\EventManagerInterface;
17
use Zend\View\Renderer\PhpRenderer as Renderer;
18
use Core\Form\propagateAttributeInterface;
19
20
/**
21
 * Jobs form container. Defines all formulars for entering a job position.
22
 *
23
 * @author Mathias Weitz <[email protected]>
24
 */
25
class Job extends WizardContainer
26
{
27
28
    /**
29
     * The event manager
30
     *
31
     * @var EventManagerInterface
32
     */
33
    protected $events;
34
35
    public function setEventManager(EventManagerInterface $events)
36
    {
37
        $this->events = $events;
38
39
        return $this;
40
    }
41
42
    public function getEventManager()
43
    {
44
        if (!$this->events) {
45
            $this->setEventManager(new EventManager());
46
        }
47
48
        return $this->events;
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     *
54
     * Adds the standard forms and child containers.
55
     *
56
     * @see \Zend\Form\Element::init()
57
     */
58
    public function init()
59
    {
60
        $elements = [
61
            'general' => [
62
                'priority' => 100,
63
                'label' => /*@translate*/ 'Basic Data',
64
                'options' => [
65
                    'label' => /*@translate*/ 'Basic Data'
66
                ],
67
                'property' => true,
68
                'forms' => [
69
70
                    'locationForm' => array(
71
                        'type' => 'Jobs/Base',
72
                        'property' => true,
73
                        'options' => array(
74
                            'enable_descriptions' => true,
75
                            'description' => /*@translate*/ 'Please choose a descriptive title and a location for your job posting ',
76
                            'display_mode' => 'summary'
77
                        )
78
                    ),
79
                    'nameForm' => array(
80
                        'type' => 'Jobs/CompanyName',
81
                        'property' => true,
82
                        'options' => array(
83
                            'enable_descriptions' => true,
84
                            'description' => /*@translate*/ 'Please choose the name of the hiring organization. The selected name defines the template of the job opening.',
85
                            'display_mode' => 'summary'
86
                        )
87
                    ),
88
                    'salaryForm' => array(
89
                        'type' => 'Jobs/Salary',
90
                        'property' => 'salary',
91
                        'options' => array(
92
                            'enable_descriptions' => true,
93
                            'description' => /*@translate*/ 'Please choose a salary of your job opening.',
94
                            'display_mode' => 'summary'
95
                        )
96
                    ),
97
                    'classifications' => [
98
                        'type' => 'Jobs/Classifications',
99
                        'options' => [
100
                            'enable_descriptions' => true,
101
                            'description' => /*@translate*/ 'Classify the job.',
102
                            'display_mode' => 'summary',
103
                        ],
104
                    ],
105
                    'portalForm' => array(
106
                        'type' => 'Jobs/Multipost',
107
                        'property' => true,
108
                        'options' => array(
109
                            'enable_descriptions' => true,
110
                            'description' => /*@translate*/ 'Please choose the portals, where you wish to publish your job opening.',
111
                            'display_mode' => 'summary'
112
                        )
113
                    ),
114
                    'customerNote' => [
115
                        'type' => 'Jobs/CustomerNote',
116
                        'property' => true,
117
                        'options' => [
118
                            'enable_descriptions' => true,
119
                            'description' => /*@translate*/ 'If there is something you want us to know about this job offering, you can type it here.',
120
                            'display_mode' => 'summary'
121
                        ]
122
                    ]
123
                ],
124
            ],
125
126
            'description' => [
127
                'priority' => '80',
128
                'options' => [ 'label' => /*@translate*/ 'Create job opening' ],
129
                'property' => true,
130
                'forms' => [
131
                    'descriptionForm' => array(
132
                        'type' => 'Jobs/Description',
133
                        'property' => true,
134
                    ),
135
                ],
136
            ],
137
138
            'preview' => [
139
                'priority' => 60,
140
                'options' => [ 'label' => /*@translate*/ 'Preview' ],
141
                'property' => true,
142
                'forms' => [
143
                    'previewForm' => array(
144
                        'type' => 'Jobs/Preview',
145
                        'property' => true,
146
                    ),
147
                ],
148
            ],
149
150
        ];
151
152
        $this->setForms($elements);
153
154
        $events  = $this->getEventManager();
155
        $events->trigger(FormEvent::EVENT_INIT, $this);
156
    }
157
158
    public function renderPost(Renderer $renderer)
159
    {
160
        $coreformsjs   = $renderer->basepath('modules/Core/js/core.forms.js');
0 ignored issues
show
Unused Code introduced by
The assignment to $coreformsjs is dead and can be removed.
Loading history...
161
        $javaScript = <<<JS
162
        $(document).ready(function() {
163
164
            console.log('attached yk.forms.done to ', \$('form'));
165
166
             \$('form').on('yk.forms.done', function(event, data) {
167
                //if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {}
168
                if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {
169
                    if (typeof data['data']['jobvalid'] != 'undefined' && data['data']['jobvalid'] === true) {
170
                        $('#job_incomplete').hide();
171
                        \$('.wizard-container .finish').removeClass('disabled');
172
                    }
173
                    else {
174
                        $('#job_incomplete').show();
175
                        \$('.wizard-container .finish').addClass('disabled');
176
                    }
177
                }
178
                \$('#job_errormessages').empty();
179
180
                if (typeof data['data']['errorMessage'] != 'undefined') {
181
                    $('#job_errormessages').append(data['data']['errorMessage']);
182
                }
183
                console.debug('job-form-inline', event, data);
184
             });
185
             \$('.wizard-container').on('wizard:tabShow.jobcontainer', function(e, \$tab, \$nav, index) {
186
                var \$link = \$tab.find('a');
187
                var href = \$link.attr('href');
188
                var \$target = \$(href);
189
                var \$iframe = \$target.find('iframe');
190
191
                \$iframe.each(function() { this.contentDocument.location.reload(true); });
192
193
                var \$productList = \$target.find('#product-list-wrapper');
194
                if (\$productList.length) {
195
                    \$productList.html('').load('/' + lang + '/jobs/channel-list?id=' + \$('#general-nameForm-job').val());
196
                }
197
             });
198
199
             \$('.wizard-container .finish a').click(function (e) {
200
                if (\$(e.currentTarget).parent().hasClass('disabled')) {
201
                    e.preventDefault();
202
                    return false;
203
                }
204
             });
205
206
        });
207
JS;
208
209
        $renderer->headScript()->appendScript($javaScript);
210
211
        return parent::renderPost($renderer);
212
    }
213
214
215
    public function enableAll($enable = true)
216
    {
217
        foreach ($this->activeForms as $formkey) {
218
            $forms = $this->getForm($formkey);
219
            if ($forms instanceof propagateAttributeInterface) {
220
                $forms->enableAll($enable);
221
            }
222
        }
223
        return $this;
224
    }
225
}
226