Completed
Pull Request — develop (#522)
by ANTHONIUS
12:09
created

Job   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
eloc 123
dl 0
loc 190
c 0
b 0
f 0
ccs 0
cts 151
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A enableAll() 0 9 3
A getEventManager() 0 7 2
A renderPost() 0 54 1
B init() 0 89 1
A setEventManager() 0 5 1
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
                    'classifications' => [
89
                        'type' => 'Jobs/Classifications',
90
                        'options' => [
91
                            'enable_descriptions' => true,
92
                            'description' => /*@translate*/ 'Classify the job.',
93
                            'display_mode' => 'summary',
94
                        ],
95
                    ],
96
                    'portalForm' => array(
97
                        'type' => 'Jobs/Multipost',
98
                        'property' => true,
99
                        'options' => array(
100
                            'enable_descriptions' => true,
101
                            'description' => /*@translate*/ 'Please choose the portals, where you wish to publish your job opening.',
102
                            'display_mode' => 'summary'
103
                        )
104
                    ),
105
                    'customerNote' => [
106
                        'type' => 'Jobs/CustomerNote',
107
                        'property' => true,
108
                        'options' => [
109
                            'enable_descriptions' => true,
110
                            'description' => /*@translate*/ 'If there is something you want us to know about this job offering, you can type it here.',
111
                            'display_mode' => 'summary'
112
                        ]
113
                    ]
114
                ],
115
            ],
116
117
            'description' => [
118
                'priority' => '80',
119
                'options' => [ 'label' => /*@translate*/ 'Create job opening' ],
120
                'property' => true,
121
                'forms' => [
122
                    'descriptionForm' => array(
123
                        'type' => 'Jobs/Description',
124
                        'property' => true,
125
                    ),
126
                ],
127
            ],
128
129
            'preview' => [
130
                'priority' => 60,
131
                'options' => [ 'label' => /*@translate*/ 'Preview' ],
132
                'property' => true,
133
                'forms' => [
134
                    'previewForm' => array(
135
                        'type' => 'Jobs/Preview',
136
                        'property' => true,
137
                    ),
138
                ],
139
            ],
140
141
        ];
142
143
        $this->setForms($elements);
144
145
        $events  = $this->getEventManager();
146
        $events->trigger(FormEvent::EVENT_INIT, $this);
147
    }
148
149
    public function renderPost(Renderer $renderer)
150
    {
151
        $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...
152
        $javaScript = <<<JS
153
        $(document).ready(function() {
154
155
            console.log('attached yk.forms.done to ', \$('form'));
156
157
             \$('form').on('yk.forms.done', function(event, data) {
158
                //if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {}
159
                if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {
160
                    if (typeof data['data']['jobvalid'] != 'undefined' && data['data']['jobvalid'] === true) {
161
                        $('#job_incomplete').hide();
162
                        \$('.wizard-container .finish').removeClass('disabled');
163
                    }
164
                    else {
165
                        $('#job_incomplete').show();
166
                        \$('.wizard-container .finish').addClass('disabled');
167
                    }
168
                }
169
                \$('#job_errormessages').empty();
170
171
                if (typeof data['data']['errorMessage'] != 'undefined') {
172
                    $('#job_errormessages').append(data['data']['errorMessage']);
173
                }
174
                console.debug('job-form-inline', event, data);
175
             });
176
             \$('.wizard-container').on('wizard:tabShow.jobcontainer', function(e, \$tab, \$nav, index) {
177
                var \$link = \$tab.find('a');
178
                var href = \$link.attr('href');
179
                var \$target = \$(href);
180
                var \$iframe = \$target.find('iframe');
181
182
                \$iframe.each(function() { this.contentDocument.location.reload(true); });
183
184
                var \$productList = \$target.find('#product-list-wrapper');
185
                if (\$productList.length) {
186
                    \$productList.html('').load('/' + lang + '/jobs/channel-list?id=' + \$('#general-nameForm-job').val());
187
                }
188
             });
189
190
             \$('.wizard-container .finish a').click(function (e) {
191
                if (\$(e.currentTarget).parent().hasClass('disabled')) {
192
                    e.preventDefault();
193
                    return false;
194
                }
195
             });
196
197
        });
198
JS;
199
200
        $renderer->headScript()->appendScript($javaScript);
201
202
        return parent::renderPost($renderer);
203
    }
204
205
206
    public function enableAll($enable = true)
207
    {
208
        foreach ($this->activeForms as $formkey) {
209
            $forms = $this->getForm($formkey);
210
            if ($forms instanceof propagateAttributeInterface) {
211
                $forms->enableAll($enable);
212
            }
213
        }
214
        return $this;
215
    }
216
}
217