| 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 |   | 
        
           | 15423 | stevensc | 45 |         $.fn.handleDisable = function() {
 | 
        
           |  |  | 46 |             const disabledValue = $('button[type="submit"]').prop('disabled')
 | 
        
           |  |  | 47 |             $('button[type="submit"]').prop('disabled', !disabledValue);
 | 
        
           |  |  | 48 |         }
 | 
        
           | 15337 | efrain | 49 |   | 
        
           |  |  | 50 |         $.fn.showFormErrorValidator = function(fieldname, errors) {
 | 
        
           |  |  | 51 |             var field = $(fieldname);
 | 
        
           |  |  | 52 |             if(field) {
 | 
        
           |  |  | 53 |                 $(field).addClass('is-invalid');
 | 
        
           |  |  | 54 |   | 
        
           |  |  | 55 |   | 
        
           |  |  | 56 |                 var error = $('<span id="' + fieldname +'-error" class="error invalid-feedback">' + errors + '</div>');
 | 
        
           |  |  | 57 |                 if(element.parent('.btn-file').length) {
 | 
        
           |  |  | 58 |                     error.insertAfter(element.parent().parent());
 | 
        
           |  |  | 59 |                 } else if(element.parent('.toggle').length) {
 | 
        
           |  |  | 60 |                     error.insertAfter(element.parent().parent());
 | 
        
           |  |  | 61 |                 } else {
 | 
        
           |  |  | 62 |                     error.insertAfter(element.parent());
 | 
        
           |  |  | 63 |                 }
 | 
        
           |  |  | 64 |             }
 | 
        
           |  |  | 65 |         };
 | 
        
           |  |  | 66 |   | 
        
           |  |  | 67 | var validator  = $('#form').validate({
 | 
        
           |  |  | 68 |         debug: true,
 | 
        
           |  |  | 69 |         onclick: false,
 | 
        
           |  |  | 70 |         onkeyup: false,
 | 
        
           |  |  | 71 |         ignore: [],
 | 
        
           |  |  | 72 |         rules: {
 | 
        
           |  |  | 73 |             'intro': {
 | 
        
           |  |  | 74 |                 updateCkeditor:function() {
 | 
        
           |  |  | 75 |                         CKEDITOR.instances.intro.updateElement();
 | 
        
           |  |  | 76 |                 },
 | 
        
           |  |  | 77 |                 required: true
 | 
        
           |  |  | 78 |             },
 | 
        
           |  |  | 79 |   | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 |         },
 | 
        
           |  |  | 82 |         submitHandler: function(form)
 | 
        
           |  |  | 83 |         {
 | 
        
           |  |  | 84 |             var formdata = false;
 | 
        
           |  |  | 85 |             if (window.FormData){
 | 
        
           |  |  | 86 |                 formdata = new FormData(form); //form[0]);
 | 
        
           |  |  | 87 |             }
 | 
        
           |  |  | 88 |   | 
        
           | 15423 | stevensc | 89 |             $.fn.handleDisable()
 | 
        
           | 15337 | efrain | 90 |   | 
        
           |  |  | 91 |             $.ajax({
 | 
        
           |  |  | 92 |                 'dataType'  : 'json',
 | 
        
           |  |  | 93 |                 'accept'    : 'application/json',
 | 
        
           |  |  | 94 |                 'method'    : 'post',
 | 
        
           |  |  | 95 |                 'url'       :  $('#form').attr('action'),
 | 
        
           |  |  | 96 |                 'data'      :  formdata,
 | 
        
           |  |  | 97 |                 'processData': false,
 | 
        
           |  |  | 98 |                 'contentType': false,
 | 
        
           |  |  | 99 |             }).done(function(response) {
 | 
        
           |  |  | 100 |                 if(response['success']) {
 | 
        
           | 15423 | stevensc | 101 |                     $.fn.showSuccess(response['data'], $.fn.handleDisable);
 | 
        
           | 15337 | efrain | 102 |   | 
        
           |  |  | 103 |                 } else {
 | 
        
           |  |  | 104 |                     validator.resetForm();
 | 
        
           |  |  | 105 |                     if(jQuery.type(response['data']) == 'string') {
 | 
        
           |  |  | 106 |                         $.fn.showError(response['data']);
 | 
        
           |  |  | 107 |                     } else  {
 | 
        
           |  |  | 108 |                         $.each(response['data'], function( fieldname, errors ) {
 | 
        
           |  |  | 109 |                             $.fn.showFormErrorValidator('#form #' + fieldname, errors);
 | 
        
           |  |  | 110 |                         });
 | 
        
           |  |  | 111 |                     }
 | 
        
           |  |  | 112 |                 }
 | 
        
           |  |  | 113 |             }).fail(function( jqXHR, textStatus, errorThrown) {
 | 
        
           |  |  | 114 |                 $.fn.showError(textStatus);
 | 
        
           |  |  | 115 |             }).always(function() {
 | 
        
           |  |  | 116 |                 NProgress.done();
 | 
        
           |  |  | 117 |             });
 | 
        
           |  |  | 118 |             return false;
 | 
        
           |  |  | 119 |         },
 | 
        
           |  |  | 120 |         invalidHandler: function(form, validator) {
 | 
        
           |  |  | 121 |   | 
        
           |  |  | 122 |         }
 | 
        
           |  |  | 123 |     });
 | 
        
           |  |  | 124 |   | 
        
           |  |  | 125 |   | 
        
           |  |  | 126 |     CKEDITOR.replace('intro');
 | 
        
           |  |  | 127 |   | 
        
           |  |  | 128 | });
 | 
        
           |  |  | 129 | JS;
 | 
        
           |  |  | 130 | $this->inlineScript()->captureEnd();
 | 
        
           |  |  | 131 | ?>
 | 
        
           |  |  | 132 |   | 
        
           |  |  | 133 | <!-- Content Header (Page header) -->
 | 
        
           |  |  | 134 | <section class="content-header">
 | 
        
           |  |  | 135 | 	<div class="container-fluid">
 | 
        
           |  |  | 136 |     	<div class="row mb-2">
 | 
        
           |  |  | 137 |         	<div class="col-sm-12">
 | 
        
           |  |  | 138 |             	<h1>LABEL_MY_PRIVATE_NETWORK_INTRO</h1>
 | 
        
           |  |  | 139 | 			</div>
 | 
        
           |  |  | 140 | 		</div>
 | 
        
           |  |  | 141 | 		<div class="row mb-2">
 | 
        
           |  |  | 142 |         	<div class="col-sm-12">
 | 
        
           |  |  | 143 |     		<?php
 | 
        
           |  |  | 144 |            	    $form = $this->form;
 | 
        
           |  |  | 145 |                 $form->setAttributes([
 | 
        
           |  |  | 146 |                     'method'  => 'post',
 | 
        
           |  |  | 147 |                 	'action'  => $routeSave,
 | 
        
           |  |  | 148 |                     'name'    => 'form',
 | 
        
           |  |  | 149 |                     'id'      => 'form',
 | 
        
           |  |  | 150 |                 ]);
 | 
        
           |  |  | 151 |   | 
        
           |  |  | 152 |                 $form->prepare();
 | 
        
           |  |  | 153 |                 echo $this->form()->openTag($form);
 | 
        
           |  |  | 154 |             ?>
 | 
        
           |  |  | 155 |     		<div class="form-group">
 | 
        
           |  |  | 156 |           		<?php
 | 
        
           |  |  | 157 |                 $element = $form->get('intro');
 | 
        
           |  |  | 158 |                 $element->setAttributes(['id' => 'intro', 'class' => 'form-control', 'rows' => '2','class' => 'form-control']);
 | 
        
           |  |  | 159 |                 // $element->setOptions(['label' => 'LABEL_INTRO']);
 | 
        
           |  |  | 160 |                 // echo $this->formLabel($element);
 | 
        
           |  |  | 161 |                 echo $this->formTextArea($element);
 | 
        
           |  |  | 162 |                 ?>
 | 
        
           |  |  | 163 |        		</div>
 | 
        
           |  |  | 164 |     		<div class="form-group">
 | 
        
           |  |  | 165 |             	<button type="submit" class="btn btn-primary">LABEL_SAVE</button>
 | 
        
           |  |  | 166 |       		</div>
 | 
        
           |  |  | 167 |        		<?php echo $this->form()->closeTag($form); ?>
 | 
        
           |  |  | 168 | 			</div>
 | 
        
           |  |  | 169 | 		</div>
 | 
        
           |  |  | 170 | 	</div><!-- /.container-fluid -->
 | 
        
           |  |  | 171 | </section>
 |