Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6388 | Rev 6521 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5050 efrain 1
<?php
6388 efrain 2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
$roleName       = $currentUser->getUserTypeId();
5050 efrain 5
 
6388 efrain 6
$routeQuestions     = $this->url('my-coach/questions');
7
$routeQuestionAdd   = $this->url('my-coach/questions/add');
8
$allowQuestionAdd   = $acl->isAllowed($roleName, 'my-coach/questions/add') ? 1 : 0;
5050 efrain 9
 
6388 efrain 10
 
11
 
12
 
13
$this->inlineScript()->appendFile($this->basePath('vendors/ckeditor/ckeditor.js'));
14
 
15
$this->headLink()->appendStylesheet($this->basePath('vendors/nprogress/nprogress.css'));
16
$this->inlineScript()->appendFile($this->basePath('vendors/nprogress/nprogress.js'));
17
 
18
$this->headLink()->appendStylesheet($this->basePath('vendors/select2/css/select2.min.css'));
19
$this->headLink()->appendStylesheet($this->basePath('vendors/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
20
$this->inlineScript()->appendFile($this->basePath('vendors/select2/js/select2.min.js'));
21
 
22
$this->inlineScript()->appendFile($this->basePath('vendors/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
23
$this->inlineScript()->appendFile($this->basePath('vendors/jsrender/jsrender.min.js'));
24
 
25
 
26
$this->inlineScript()->appendFile($this->basePath('vendors/jquery-validation/jquery.validate.js'));
27
$this->inlineScript()->appendFile($this->basePath('vendors/jquery-validation/additional-methods.js'));
28
$this->inlineScript()->appendFile($this->basePath('vendors/jquery-validation/localization/messages_es.js'));
29
 
30
 
31
 
32
$this->inlineScript()->captureStart();
33
echo <<<JS
34
 
35
jQuery( document ).ready(function( $ ) {
36
$.fn.reload = function() {
37
 
38
        NProgress.start();
39
        $.ajax({
40
            'dataType'  : 'json',
41
            'accept'    : 'application/json',
42
            'method'    : 'get',
43
            'url'       :  '$routeQuestions',
44
            'data'      : {
45
                'search' : $('#form-filter #search').val(),
46
                'category_id' : $('li.my-coach-category-li-selected > a.my-coach-category-a').data('uuid') ,
47
 
48
            }
49
        }).done(function(response) {
50
            if(response['success']) {
51
                $('#my-coach-record-list').empty();
52
 
53
 
54
                if(response['data']['items'].length > 0) {
55
 
56
 
57
 
58
                    $( "#my-coach-record-list" ).html(
59
                		$( "#recordTemplate" ).render( response['data']['items'] )
60
                	);
61
                } else {
62
                    var html = '<div class="company-title"><div class="widget widget-jobs"><div class="sd-title">ERROR_NO_RECORD_MATCHED_YOUR_QUERY</div></div></div>';
63
                    $( "#my-coach-record-list" ).html(html);
64
                }
65
 
66
 
67
                $('button.btn-my-coach-delete').confirmation({
68
                    rootSelector: 'button.btn-my-coach-delete',
69
                    title : 'LABEL_ARE_YOU_SURE',
70
                    singleton : true,
71
                    btnOkLabel: 'LABEL_YES',
72
                    btnCancelLabel: 'LABEL_NO',
73
                    onConfirm: function(value) {
74
                        var action = $(this).data('link');
75
                        NProgress.start();
76
                        $.ajax({
77
                            'dataType'  : 'json',
78
                            'accept'    : 'application/json',
79
                            'method'    : 'post',
80
                            'url'       :  action,
81
                        }).done(function(response) {
82
                            if(response['success']) {
83
                                $.fn.showSuccess(response['data']);
84
 
85
                                $.fn.reload();
86
                            } else {
87
                                $.fn.showError(response['data']);
88
                            }
89
                        }).fail(function( jqXHR, textStatus, errorThrown) {
90
                            $.fn.showError(textStatus);
91
                        }).always(function() {
92
                            NProgress.done();
93
                        });
94
 
95
                        return false;
96
                    },
97
                });
98
 
99
            } else {
100
                $.fn.showError(response['data']);
101
            }
102
        }).fail(function( jqXHR, textStatus, errorThrown) {
103
            $.fn.showError(textStatus);
104
        }).always(function() {
105
            NProgress.done();
106
        });
107
 
108
    }
109
 
110
 
111
    $.validator.setDefaults({
112
        debug: true,
113
        highlight: function(element) {
114
            $(element).addClass('is-invalid');
115
        },
116
        unhighlight: function(element) {
117
            $(element).removeClass('is-invalid');
118
        },
119
        errorElement: 'span',
120
        errorClass: 'error invalid-feedback',
121
        errorPlacement: function(error, element) {
122
            if(element.parent('.btn-file').length) {
123
                error.insertAfter(element.parent().parent());
124
            } else if(element.parent('.toggle').length) {
125
                error.insertAfter(element.parent().parent());
126
            } else {
127
                error.insertAfter(element.parent());
128
            }
129
        }
130
    });
131
 
132
 
133
    $.fn.showFormErrorValidator = function(fieldname, errors) {
134
        var field = $(fieldname);
135
        if(field) {
136
            $(field).addClass('is-invalid');
137
 
138
 
139
            var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
140
            if(element.parent('.btn-file').length) {
141
                error.insertAfter(element.parent().parent());
142
            } else if(element.parent('.toggle').length) {
143
                error.insertAfter(element.parent().parent());
144
            } else {
145
                error.insertAfter(element.parent());
146
            }
147
        }
148
    };
149
 
150
    var validatorQuestion = $('#form-question').validate({
151
        debug: true,
152
        onclick: false,
153
        onkeyup: false,
154
        ignore: [],
155
        rules: {
156
            'category_id': {
157
                required: true,
158
            },
159
            'title': {
160
                required: true,
161
                maxlength: 128,
162
            },
163
            'description': {
164
                updateCkeditor:function() {
165
                        CKEDITOR.instances.description_question.updateElement();
166
                },
167
 
168
                required: true
169
            },
170
 
171
        },
172
        submitHandler: function(form)
173
        {
174
 
175
 
176
			NProgress.start();
177
            $.ajax({
178
                'dataType'  : 'json',
179
                'accept'    : 'application/json',
180
                'method'    : 'post',
181
                'url'       :  $('#form-question').attr('action'),
182
                'data'      :  $('#form-question').serialize(),
183
 
184
            }).done(function(response) {
185
 
186
				if(response['success']) {
187
 
188
                    $('#modal-question').modal('hide');
189
 
190
                    $.fn.showSuccess(response['data']);
191
                    $.fn.reload();
192
 
193
 
194
 
195
                } else {
196
                    validatorQuestion.resetForm();
197
                    if(jQuery.type(response['data']) == 'string') {
198
                        $.fn.showError(response['data']);
199
                    } else  {
200
                        $.each(response['data'], function( fieldname, errors ) {
201
                            $.fn.showFormErrorValidator('#form-question #' + fieldname, errors);
202
                        });
203
                    }
204
                }
205
            }).fail(function( jqXHR, textStatus, errorThrown) {
206
                $.fn.showError(textStatus);
207
            }).always(function() {
208
                NProgress.done();
209
            });
210
            return false;
211
        },
212
        invalidHandler: function(form, validator) {
213
 
214
        }
215
    });
216
 
217
 
218
    $('a.my-coach-category-a').click(function(e) {
219
        e.preventDefault();
220
 
221
 
222
        $('li.my-coach-category-li').removeClass('my-coach-category-li-selected');
223
        $(this).closest('li.my-coach-category-li').addClass('my-coach-category-li-selected');
224
 
225
        $.fn.reload();
226
    });
227
 
228
    $('body').on('click', 'button.btn-my-coach-edit', function(e) {
229
        e.preventDefault();
230
        var action = $(this).data('link');
231
        NProgress.start();
232
        $.ajax({
233
            'dataType'  : 'json',
234
            'accept'    : 'application/json',
235
            'method'    : 'get',
236
            'url'       :  action,
237
        }).done(function(response) {
238
            if(response['success']) {
239
 
240
                $('#form-question').attr('action', action);
241
                $('#form-question #category_id').val(response['data']['category_id']).trigger('change');
242
                $('#form-question #title').val(response['data']['title']);
243
                CKEDITOR.instances.description_question.setData(response['data']['description']);
244
 
245
                $('#modal-question').modal('show');
246
            } else {
247
                $.fn.showError(response['data']);
248
            }
249
        }).fail(function( jqXHR, textStatus, errorThrown) {
250
            $.fn.showError(textStatus);
251
        }).always(function() {
252
            NProgress.done();
253
        });
254
 
255
    });
256
 
257
 
258
    $('#form-filter #search').keyup(function(e) {
259
 
260
        e.preventDefault();
261
 
262
        $.fn.reload();
263
    })
264
 
265
    $('button.btn-search').click(function(e) {
266
        e.preventDefault();
267
 
268
        $.fn.reload();
269
    });
270
 
271
    $('#my-coach-add-question').click(function(e) {
272
        e.preventDefault();
273
 
274
        $('#form-question').attr('action', '$routeQuestionAdd');
275
        $('#form-question #title').val('');
276
        $('#form-question #category_id').val('').trigger('change');
277
        CKEDITOR.instances.description_question.setData('');
278
 
279
        $('#modal-question').modal('show');
280
    });
281
 
282
    $('#form-question #category_id').select2({
283
        theme: 'bootstrap4'
284
    })
285
 
286
    $('button.btn-cancel').click(function(e) {
287
        e.preventDefault();
288
 
289
 
290
        $('#modal-question').modal('hide');
291
    });
292
 
293
    $.fn.reload()
294
 
295
 
296
    CKEDITOR.replace('description_question',{
297
        toolbar: [
298
                    { name: 'editing', items: ['Scayt'] },
299
                    { name: 'links', items: ['Link', 'Unlink'] },
300
                    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'] },
301
                    { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', 'RemoveFormat'] },
302
                    '/',
303
                    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
304
                    { name: 'styles', items: ['Styles', 'Format'] },
305
                    { name: 'tools', items: ['Maximize'] }
306
                ],
307
                removePlugins: 'elementspath,Anchor',
308
                heigth: 100
309
    });
310
});
5050 efrain 311
JS;
6388 efrain 312
 
313
$this->inlineScript()->captureEnd();
314
$this->headLink()->appendStylesheet('/look-and-field/my-coach.css');
5050 efrain 315
?>
316
 
6388 efrain 317
<section class="companies-info container px-0">
318
    <div class="company-title">
319
        <h1 class="title mx-auto">LABEL_MY_COACH</h1>
320
        <?php if($allowQuestionAdd) : ?>
321
            <h2 class="title cursor-pointer" id="my-coach-add-question">
322
                LABEL_MY_COACH_QUESTION_ADD
323
            </h2>
324
       <?php endif; ?>
5050 efrain 325
 
6388 efrain 326
    </div>
5050 efrain 327
 
6388 efrain 328
    <div class="row gap-3" id="row-list">
329
        <div class="my-coach-category-list col-12 col-md-3">
330
            <ul>
331
                <li class="my-coach-category-li my-coach-category-li-selected">
332
                    <a class="my-coach-category-a" href="" data-uuid="">LABEL_MY_COACH_CATEGORY_ALL</a>
333
                </li>
334
                <?php
335
                foreach ($categories as $categorie) :
336
                ?>
337
                    <li class="my-coach-category-li">
338
                        <a class="my-coach-category-a" href="" data-uuid="<?php echo $categorie['uuid'] ?>"><?php echo $categorie['name'] ?></a>
339
                    </li>
340
 
341
                <?php endforeach; ?>
342
            </ul>
343
        </div>
344
 
345
 
346
        <div class="col px-0">
347
            <div class="search-box">
348
                <form id="form-filter" name="form-filter">
349
                    <input type="text" name="search" id="search" class="form-control"><button class="btn btn-search">LABEL_SEARCH</button>
350
                </form>
351
            </div>
352
 
353
            <div id="my-coach-record-list" class="my-coach-record-list mt-3">
354
            </div>
355
 
356
            <div id="my-coach-pagination">
357
            </div>
358
 
359
        </div>
360
    </div>
361
 
362
 
363
<!-- The Modal -->
364
<div class="modal" id="modal-question">
365
    <div class="modal-dialog  modal-xl">
366
        <div class="modal-content">
367
 
368
            <!-- Modal Header -->
369
            <div class="modal-header">
370
                <h4 class="modal-title">LABEL_QUESTION</h4>
371
                <button type="button" class="close" data-dismiss="modal">&times;</button>
372
            </div>
373
 
374
            <!-- Modal body -->
375
            <div class="modal-body">
376
                <?php
377
                $form = $this->formQuestion;
378
                $form->setAttributes([
379
                    'method'    => 'post',
380
                    'name'      => 'form-questiom',
381
                    'id'        => 'form-question'
382
                ]);
383
 
384
                $form->prepare();
385
                echo $this->form()->openTag($form);
386
                ?>
387
                <div class="form-group">
388
                    <?php
389
                    $element = $form->get('title');
390
                    $element->setOptions(['label' => 'LABEL_TITLE']);
391
                    $element->setAttributes(['class' => 'form-control']);
392
 
393
                    echo $this->formLabel($element);
394
                    echo $this->formText($element);
395
                    ?>
396
                </div>
397
              	<div class="form-group">
398
                    <?php
399
                    $element = $form->get('description');
400
                    $element->setOptions(['label' => 'LABEL_DESCRIPTION']);
401
                    $element->setAttributes(['class' => 'form-control', 'id' => 'description_question']);
402
 
403
                    echo $this->formLabel($element);
404
                    echo $this->formTextArea($element);
405
                    ?>
406
                </div>
407
                <div class="form-group">
408
                    <?php
409
 
410
                    $element = $form->get('category_id');
411
                    $element->setOptions(['label' => 'LABEL_CATEGORY']);
412
 
413
                    echo $this->formLabel($element);
414
                    echo $this->formSelect($element);
415
                    ?>
416
                </div>
417
                <div class="text-right">
418
                    <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
419
                    <button type="button" class="btn btn-light btn-cancel">LABEL_CANCEL</button>
420
                </div>
421
                <?php echo $this->form()->closeTag($form); ?>
422
            </div>
423
 
424
 
425
        </div>
426
    </div>
427
</div>
428
 
429
 
430
 
431
</section>
432
 
433
 
434
<script id="recordTemplate" type="text/x-jsrender">
435
    <div class="my-coach-record-card" >
436
        <div class="my-coach-record-card-container" >
437
            <div class="my-coach-record-card-resume" >
438
                <ul>
6481 efrain 439
                    <li><span id="answers-{{:uuid}}"> {{:answers}} </span> LABEL_MY_COACH_ANSWERS</li>
440
                    <li><span id="reactions-{{:uuid}}"> {{:reactions}} </span> LABEL_MY_COACH_REACTIONS</li>
441
                    <li><span id="views-{{:uuid}}"> {{:views}} </span> LABEL_MY_COACH_VIEWS</li>
6388 efrain 442
                </ul>
443
            </div>
444
            <div class="my-coach-record-card-content" >
445
                <h2><a href="{{:link_view}}">{{>title}}</a></h2>
446
                <p>{{>description}}</p>
447
                <div class="d-flex align-items-center justify-content-between">
448
                    <ul class="d-flex align-items-center  my-coach-record-card-categories">
449
                        {{for categories}}
450
                        <li>{{:category}}</li>
451
                        {{/for}}
452
                    </ul>
453
                    <span>LABEL_MY_COACH_QUESTION {{:added_on}} </span>
454
                </div>
455
            </div>
456
        </div>
457
 
458
        <div class="d-flex align-items-center justify-content-between">
459
            {{if link_edit }}
460
            <button data-link="{{>link_edit}}" class="btn-my-coach-edit"> <i class="fa fa-pencil" aria-hidden="true"></i> </button>
461
            {{/if}}
462
            {{if link_delete }}
463
            <button data-link="{{>link_delete}}" class="btn-my-coach-delete"> <i class="fa fa-trash" aria-hidden="true"></i> </button>
464
            {{/if}}
465
        </div>
466
    </div>
467
</script>