Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15423 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15337 efrain 1
<?php
2
$acl            = $this->viewModel()->getRoot()->getVariable('acl');
3
$currentUser    = $this->currentUserHelper();
4
 
5
$roleName = $currentUser->getUserTypeId();
6
 
7
 
8
$routeSave       = $this->url('settings/my-private-network/intro');
9
 
10
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
11
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
12
 
13
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
14
 
15
 
16
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
17
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
18
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
19
 
20
$this->inlineScript()->captureStart();
21
echo <<<JS
22
    jQuery( document ).ready(function( $ ) {
23
 
24
        $.validator.setDefaults({
25
            debug: true,
26
            highlight: function(element) {
27
                $(element).addClass('is-invalid');
28
            },
29
            unhighlight: function(element) {
30
                $(element).removeClass('is-invalid');
31
            },
32
            errorElement: 'span',
33
            errorClass: 'error invalid-feedback',
34
            errorPlacement: function(error, element) {
35
                if(element.parent('.btn-file').length) {
36
                    error.insertAfter(element.parent().parent());
37
                } else if(element.parent('.toggle').length) {
38
                    error.insertAfter(element.parent().parent());
39
                } else {
40
                    error.insertAfter(element.parent());
41
                }
42
            }
43
        });
44
 
45
 
46
        $.fn.showFormErrorValidator = function(fieldname, errors) {
47
            var field = $(fieldname);
48
            if(field) {
49
                $(field).addClass('is-invalid');
50
 
51
 
52
                var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
53
                if(element.parent('.btn-file').length) {
54
                    error.insertAfter(element.parent().parent());
55
                } else if(element.parent('.toggle').length) {
56
                    error.insertAfter(element.parent().parent());
57
                } else {
58
                    error.insertAfter(element.parent());
59
                }
60
            }
61
        };
62
 
63
var validator  = $('#form').validate({
64
        debug: true,
65
        onclick: false,
66
        onkeyup: false,
67
        ignore: [],
68
        rules: {
69
            'intro': {
70
                updateCkeditor:function() {
71
                        CKEDITOR.instances.intro.updateElement();
72
                },
73
                required: true
74
            },
75
 
76
 
77
        },
78
        submitHandler: function(form)
79
        {
80
            var formdata = false;
81
            if (window.FormData){
82
                formdata = new FormData(form); //form[0]);
83
            }
84
 
85
            $('input[type="submit"]').prop('disabled', true);
86
 
87
            $.ajax({
88
                'dataType'  : 'json',
89
                'accept'    : 'application/json',
90
                'method'    : 'post',
91
                'url'       :  $('#form').attr('action'),
92
                'data'      :  formdata,
93
                'processData': false,
94
                'contentType': false,
95
            }).done(function(response) {
96
                if(response['success']) {
97
                    $.fn.showSuccess(response['data']);
98
 
99
                } else {
100
                    validator.resetForm();
101
                    if(jQuery.type(response['data']) == 'string') {
102
                        $.fn.showError(response['data']);
103
                    } else  {
104
                        $.each(response['data'], function( fieldname, errors ) {
105
                            $.fn.showFormErrorValidator('#form #' + fieldname, errors);
106
                        });
107
                    }
108
                }
109
            }).fail(function( jqXHR, textStatus, errorThrown) {
110
                $.fn.showError(textStatus);
111
            }).always(function() {
112
                NProgress.done();
113
            });
114
            return false;
115
        },
116
        invalidHandler: function(form, validator) {
117
 
118
        }
119
    });
120
 
121
 
122
    CKEDITOR.replace('intro');
123
 
124
});
125
JS;
126
$this->inlineScript()->captureEnd();
127
?>
128
 
129
<!-- Content Header (Page header) -->
130
<section class="content-header">
131
	<div class="container-fluid">
132
    	<div class="row mb-2">
133
        	<div class="col-sm-12">
134
            	<h1>LABEL_MY_PRIVATE_NETWORK_INTRO</h1>
135
			</div>
136
		</div>
137
		<div class="row mb-2">
138
        	<div class="col-sm-12">
139
    		<?php
140
           	    $form = $this->form;
141
                $form->setAttributes([
142
                    'method'  => 'post',
143
                	'action'  => $routeSave,
144
                    'name'    => 'form',
145
                    'id'      => 'form',
146
                ]);
147
 
148
                $form->prepare();
149
                echo $this->form()->openTag($form);
150
            ?>
151
    		<div class="form-group">
152
          		<?php
153
                $element = $form->get('intro');
154
                $element->setAttributes(['id' => 'intro', 'class' => 'form-control', 'rows' => '2','class' => 'form-control']);
155
                // $element->setOptions(['label' => 'LABEL_INTRO']);
156
                // echo $this->formLabel($element);
157
                echo $this->formTextArea($element);
158
                ?>
159
       		</div>
160
    		<div class="form-group">
161
            	<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
162
      		</div>
163
       		<?php echo $this->form()->closeTag($form); ?>
164
			</div>
165
		</div>
166
	</div><!-- /.container-fluid -->
167
</section>