Best Atoum code snippet using stub.useScript
FormHelper.php
Source:FormHelper.php
...197 *198 * @return void199 */200 public function checkboxesLimit($context, $max) {201 $this->Html->useScript('/assets/npm-asset/checkboxes.js/dist/jquery.checkboxes-1.2.2.min', ['block' => HtmlHelper::SCRIPT_BOTTOM]);202 $script = <<<CHECKBOX_LIMIT203jQuery(function($) {204 $('{$context}').checkboxes('max', {$max});205});206CHECKBOX_LIMIT;207 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);208 }209 /**210 * http://rmariuzzo.github.io/checkboxes.js/#range-selection-of-checkboxes211 * @param $context string .class or #id212 *213 * @return void214 */215 public function checkboxesRange($context) {216 $this->Html->useScript('/assets/npm-asset/checkboxes.js/dist/jquery.checkboxes-1.2.2.min', ['block' => HtmlHelper::SCRIPT_BOTTOM]);217 $script = <<<CHECKBOX_LIMIT218jQuery(function($) {219 $('{$context}').checkboxes('range', true);220});221CHECKBOX_LIMIT;222 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);223 }224 /**225 * Generates a form input element complete with label and wrapper div.226 *227 * Adds extra tyoes besides the ones supported by parent class method:228 * - `datepicker`,'datetimepicker','timepicker','daterangepicker'229 * Adds markdown options for textarea230 *231 * @param string $fieldName This should be "Modelname.fieldname".232 * @param array $options Each type of input takes different options.233 *234 * @return string Completed form widget.235 * @deprecated Use control() instead.236 */237 public function input($fieldName, array $options = []) {238 return $this->control($fieldName, $options); // TODO: Change the autogenerated stub239 }240 /**241 * Generates a form input element complete with label and wrapper div.242 *243 * Adds extra tyoes besides the ones supported by parent class method:244 * - `datepicker`,'datetimepicker','timepicker','daterangepicker'245 * Adds markdown options for textarea246 *247 * @param string $fieldName This should be "Modelname.fieldname".248 * @param array $options Each type of input takes different options.249 *250 * @return string Completed form widget.251 */252 public function control($fieldName, array $options = []) {253 if (!empty($options['type'])) {254 if (!isset($options['id'])) {255 $options['id'] = TRUE;256 }257 $options = $this->_initInputField($fieldName, $options);258 if (!empty($options['data-mask'])) {259 $options = $this->__datamask($options);260 }261 switch ($options['type']) {262 case 'datepicker':263 $options = $this->__bootstrapDatePicker($options);264 break;265 case 'datetimepicker':266 $options = $this->__bootstrapDateTimePicker($options);267 break;268 case 'timepicker':269 $options = $this->__timePicker($options);270 break;271 case 'timepicker2':272 $options = $this->__timePicker2($options);273 break;274 case 'timerange':275 $options = $this->__timerange($options);276 break;277 case 'daterange':278 $options = $this->__dateRange($options);279 break;280 case 'textarea':281 if (isset($options['markdown'])) {282 $options = $this->__markdown($options);283 }284 if (isset($options['expand'])) {285 $options = $this->__expand($options);286 }287 break;288 case 'select':289 if (isset($options['select-visible-div'])) {290 $options = $this->__selectExtraOptions($options);291 }292 break;293 case 'select2':294 $options = $this->__select2($options);295 break;296 case 'select2sortable':297 $options = $this->__select2Sortable($options);298 break;299 case 'sortable-serialize':300 $options = $this->__sortableSerialize($options);301 break;302 case 'sortable-post':303 $options = $this->__sortablePost($options);304 break;305 case 'duration':306 $options = $this->__durationPicker($options);307 $options['scid-type'] = 'duration';308 break;309 case 'filepond':310 $options = $this->__filepond($fieldName, $options);311 break;312 case 'countries':313 $options = $this->__countries($options);314 break;315 case 'toggle':316 $options = $this->__bootstrapToggle($fieldName, $options);317 break;318 case 'signature':319 $options = $this->__signature($fieldName, $options);320 break;321 }322 }323 if (!empty($options['data-mask'])) {324 if (!isset($options['id'])) {325 $options['id'] = TRUE;326 }327 $options = $this->_initInputField($fieldName, $options);328 $options = $this->__datamask($options);329 }330 return parent::control($fieldName, $options); // TODO: Change the autogenerated stub331 }332 /**333 * @param $options334 *335 * @return mixed336 */337 private function __datamask($options) {338 $this->Html->useScript('Scid.jquery.mask.min', ['block' => HtmlHelper::SCRIPT_BOTTOM]);339 // could add options and build out the script rather then using attribute later340 if (is_array($options['data-mask'])) {341 $mask = $options['data-mask']['mask'];342 $maskOptions = ',' . json_encode($options['data-mask']['options']);343 } else {344 $maskOptions = '';345 $mask = $options['data-mask'];346 }347 unset($options['data-mask']);348 switch ($mask) {349 case 'phone':350 $options = $this->injectClasses('phone', $options);351 if (!in_array('phone', $this->_dataMaskType)) {352 $script = "$('.phone').mask('(000) 000-0000');";353 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);354 $this->_dataMaskType[] = 'phone';355 }356 return $options;357 case 'money2':358 $options = $this->injectClasses('money2', $options);359 if (!in_array('money2', $this->_dataMaskType)) {360 $script = "$('.money2').mask('#,##0.00', {reverse: true});";361 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);362 $this->_dataMaskType[] = 'money2';363 }364 return $options;365 }366 $id = $options['id'];367 $script = "$('#{$id}').mask('{$mask}' {$maskOptions});";368 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);369 return $options;370 }371 private function __bootstrapDatePicker($options) {372 $id = $options['id'];373 if (!empty($options['val'])) {374 $options['val'] = $this->formatValue($options['val'], 'm/d/Y');375 }376 $this->Html->useScript([377 'Scid.moment.min', 'Scid.daterangepicker',378 ], ['block' => HtmlHelper::SCRIPT_BOTTOM]);379 $this->Html->useCssFile('Scid.daterangepicker');380 $options['prepend'] = $this->Html->icon('calendar');381 $options['type'] = 'text';382 $defaultRangeOptions = [383 'singleDatePicker' => TRUE,384 'timePicker' => FALSE,385 'locale' => ['format' => 'MM/DD/YYYY'],386 ];387 $callback = '';388 if (isset($options['rangeOptions']['default']) && $options['rangeOptions']['default'] === FALSE) {389 $callback = ", function(chosen_date) {390 $('#{$id}').val(chosen_date.format('MM/DD/YYYY'));391}";392 }393 $rangeOptionString = $this->__rangeOptions($options, $defaultRangeOptions);394 $this->Html->scriptBlock(self::DOCUMENT_READY_FUNCTION . " {395 $('#{$id}').daterangepicker({$rangeOptionString}{$callback});396 });", ['block' => HtmlHelper::SCRIPT_BOTTOM]);397 return $options;398 }399 public function formatValue($sourceValue, $format = 'm/d/Y g:i a') {400 if (!empty($format) &&401 (402 $sourceValue instanceof Date ||403 $sourceValue instanceof Time ||404 $sourceValue instanceof FrozenTime ||405 $sourceValue instanceof FrozenDate)) {406 $sourceValue = $sourceValue->format($format);407 }408 return $sourceValue;409 }410 /**411 * @url http://www.daterangepicker.com412 * @param $options413 * @param $rangeOptionString414 */415 private function __rangeOptions(&$options, $defaultOptions) {416 if (!empty($options['rangeOptions'])) {417 $rangeOptions = $options['rangeOptions'];418 } else {419 $rangeOptions = [];420 }421 foreach ($defaultOptions as $key => $option) {422 if (!isset($rangeOptions[$key])) {423 $rangeOptions[$key] = $option;424 }425 }426 $rangeOptionDateKeys = ['startDate', 'endDate', 'minDate', 'maxDate'];427 if (!empty($options['startDate']) && !empty($options['endDate'])) {428 $options['value'] =429 CakeTime::format($options['startDate'], '%m/%d/%Y') . ' - ' . CakeTime::format($options['endDate'], '%m/%d/%Y');430 }431 foreach ($rangeOptionDateKeys as $key) {432 if (!empty($options[$key])) {433 $rangeOptions[$key] = $options[$key];434 unset($options[$key]);435 }436 }437 if (isset($rangeOptions['default']) && $rangeOptions['default'] === FALSE) {438 unset($rangeOptions['default']);439 $rangeOptions['autoUpdateInput'] = FALSE;440 }441 if (empty($rangeOptions)) {442 $rangeOptionString = '';443 } else {444 $rangeOptionString = $this->__rangeOptionsString($rangeOptions);445 }446 return $rangeOptionString;447 }448 /**449 * @param $rangeOptions450 */451 private function __rangeOptionsString($rangeOptions) {452 $result = json_encode($rangeOptions);453 $result = str_replace('\/', '/', $result);454 return $result;455 }456 /**457 * @param $options458 * @param $idForInput459 *460 * @return mixed461 */462 private function __bootstrapDateTimePicker($options) {463 $id = $options['id'];464 if (!empty($options['val'])) {465 $options['val'] = $this->formatValue($options['val']);466 }467 $this->Html->useScript([468 'Scid.moment.min', 'Scid.daterangepicker',469 ], ['block' => HtmlHelper::SCRIPT_BOTTOM]);470 $this->Html->useCssFile('Scid.daterangepicker');471 $options['prepend'] = $this->Html->icon('calendar');472 $options['type'] = 'text';473 $defaultRangeOptions = [474 'singleDatePicker' => TRUE,475 'timePicker' => TRUE,476 'locale' => ['format' => 'MM/DD/YYYY h:mm A'],477 ];478 $rangeOptionString = $this->__rangeOptions($options, $defaultRangeOptions);479 $this->Html->scriptBlock(self::DOCUMENT_READY_FUNCTION . " {480 $('#{$id}').daterangepicker({$rangeOptionString});481 });", ['block' => HtmlHelper::SCRIPT_BOTTOM]);482 return $options;483 }484 /**485 * @param $options486 * @return array487 */488 private function __timePicker2($options) {489 $id = $options['id'];490 $this->Html->useScript(['Scid.jquery.timepicker.min',], ['block' => HtmlHelper::SCRIPT_BOTTOM]);491 $this->Html->useCssFile('Scid.jquery.timepicker');492 $options['prepend'] = $this->Html->icon('clock');493 $options['type'] = 'text';494 if (empty($options['width'])) {495 $options['width'] = 8;496 }497 if (empty($options['timepicker'])) {498 $options['timepicker'] = [];499 }500 $defaultOptions = ['timeFormat' => 'g:ia', 'showDuration' => TRUE];501 $timepickerOptions = $defaultOptions + $options['timepicker'];502 $timeKeys = ['minTime', 'maxTime', 'durationTime'];503 if (empty($timepickerOptions['noneOption']) && !empty($options['empty'])) {504 $timepickerOptions['noneOption'] = $options['empty'];505 unset($options['empty']);506 }507 foreach ($timeKeys as $timeKey) {508 if (isset($timepickerOptions[$timeKey]) && ($timepickerOptions[$timeKey] instanceof FrozenTime || $timepickerOptions[$timeKey] instanceof FrozenTime)) {509 /** @var FrozenTime $time */510 $time = $timepickerOptions[$timeKey];511 $timepickerOptions[$timeKey] = $time->format('h:ia');512 }513 }514 $jsonOptions = json_encode($timepickerOptions);515 unset($options['timepicker']);516 $script = /** @lang JavaScript */517 <<<TIMEPICKER518$('#{$id}').timepicker({$jsonOptions});519TIMEPICKER;520 $this->Html->scriptBlock($script);521 return $options;522 }523 /**524 * @param $options525 * @return array526 */527 private function __timerange($options) {528 $id = $options['id'];529 $this->Html->useScript(['Scid.jquery.timepicker.min',], ['block' => HtmlHelper::SCRIPT_BOTTOM]);530 $this->Html->useScript(['Scid.timerange.min',], ['block' => HtmlHelper::SCRIPT_BOTTOM]);531 $this->Html->useCssFile('Scid.jquery.timepicker');532 $options['prepend'] = $this->Html->icon('clock');533 $options['type'] = 'text';534 if (empty($options['width'])) {535 $options['width'] = 8;536 }537 if (empty($options['timepicker'])) {538 $options['timepicker'] = [];539 }540 $defaultOptions = ['timeFormat' => 'g:ia', 'showDuration' => TRUE];541 $timepickerOptions = $defaultOptions + $options['timepicker'];542 $timeKeys = ['minTime', 'maxTime', 'durationTime'];543 if (empty($timepickerOptions['noneOption']) && !empty($options['empty'])) {544 $timepickerOptions['noneOption'] = $options['empty'];545 unset($options['empty']);546 }547 foreach ($timeKeys as $timeKey) {548 if (isset($timepickerOptions[$timeKey]) && ($timepickerOptions[$timeKey] instanceof FrozenTime || $timepickerOptions[$timeKey] instanceof FrozenTime)) {549 /** @var FrozenTime $time */550 $time = $timepickerOptions[$timeKey];551 $timepickerOptions[$timeKey] = $time->format('h:ia');552 }553 }554 $jsonOptions = json_encode($timepickerOptions);555 unset($options['timepicker']);556 $script = /** @lang JavaScript */557 <<<TIMEPICKER558$('#{$id}').timepicker({$jsonOptions});559TIMEPICKER;560 $this->Html->scriptBlock($script);561 return $options;562 }563 /**564 * @param $options565 * @param $idForInput566 *567 * @return mixed568 */569 private function __timePicker($options) {570 $id = $options['id'];571 if (!empty($options['val'])) {572 $options['val'] = $this->formatValue($options['val'], 'g:i a');573 }574 $this->Html->useScript(['Scid.bootstrap-timepicker.min',], ['block' => HtmlHelper::SCRIPT_BOTTOM]);575 $this->Html->useCssFile('Scid.bootstrap-timepicker');576 $options['prepend'] = $this->Html->icon('clock');577 if (!empty($this->_inputDefaults['between'])) {578 $options['between'] = $this->_inputDefaults['between'];579 $options['between'] =580 str_replace('input-group', 'input-group bootstrap-timepicker timepicker', $options['between']);581 } else {582 $options['between'] = "<div class=\"input-group bootstrap-timepicker timepicker\">";583 }584 $options['type'] = 'text';585 $json =586 [587 'icons' => [588 'up' => 'far fa-chevron-up',589 'down' => 'far fa-chevron-down',590 ],591 ];592 if (!empty($options['timepicker'])) {593 $json = $json + $options['timepicker'];594 unset($options['timepicker']);595 }596 $json = json_encode($json);597 $this->Html->scriptBlock(self::DOCUMENT_READY_FUNCTION . " {598 $('#{$id}').timepicker({$json});599 });", ['block' => HtmlHelper::SCRIPT_BOTTOM,]);600 return $options;601 }602 /**603 * @param $options604 * $options can have a sub array 'rangeOptions' with the keys and values below605 * showDropdowns: (boolean) Show year and month select boxes above calendars to jump to a specific month and year606 * showWeekNumbers: (boolean) Show week numbers at the start of each week on the calendars607 * timePicker: (boolean) Allow selection of dates with times, not just dates608 * timePickerIncrement: (number) Increment of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30)609 * timePicker24Hour: (boolean) Use 24-hour instead of 12-hour times, removing the AM/PM selection610 * timePickerSeconds: (boolean) Show seconds in the timePicker611 * ranges: (object) Set predefined date ranges the user can select from.612 * Each key is the label for the range, and its value an array with two dates representing the bounds of the range613 * opens: (string: 'left'/'right'/'center') Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to614 * drops: (string: 'down' or 'up') Whether the picker appears below (default) or above the HTML element it's attached to615 * buttonClasses: (array) CSS class names that will be added to all buttons in the picker616 * applyClass: (string) CSS class string that will be added to the apply button617 * cancelClass: (string) CSS class string that will be added to the cancel button618 * locale: (object) Allows you to provide localized strings for buttons and labels,619 * customize the date display format, and change the first day of week for the calendars620 * singleDatePicker: (boolean) Show only a single calendar to choose one date,621 * instead of a range picker with two calendars;622 * the start and end dates provided to your callback will be the same single date chosen623 * autoApply: (boolean) Hide the apply and cancel buttons, and automatically apply a new date range as soon as two dates or a predefined range is selected624 * parentEl: (string) jQuery selector of the parent element that the date range picker will be added to, if not provided this will be 'body'625 * @param $idForInput626 *627 * @return mixed628 */629 private function __dateRange($options) {630 $id = $options['id'];631 $this->Html->useScript([632 'Scid.moment.min', 'Scid.daterangepicker',633 ], ['block' => HtmlHelper::SCRIPT_BOTTOM,]);634 $this->Html->useCssFile('Scid.daterangepicker');635 $options['prepend'] = $this->Html->icon('calendar');636 $options['type'] = 'text';637 $defaultRangeOptions = ['autoApply' => TRUE];638 $rangeOptionString = $this->__rangeOptions($options, $defaultRangeOptions);639 $this->Html->scriptBlock(self::DOCUMENT_READY_FUNCTION . " {640 $('#{$id}').daterangepicker({$rangeOptionString});641 });", ['block' => HtmlHelper::SCRIPT_BOTTOM,]);642 return $options;643 }644 /**645 * @param $options646 *647 * @return mixed648 */649 private function __markdown($options) {650 $id = $options['id'];651 // note we use a slightly modified from the upstream bootstrap-markdown652 // to fix icon for picture653 $this->Html->useScript([654 'Scid.bootstrap-markdown.scid', 'Scid.markdown',655 'Scid.to-markdown',656 ], ['block' => HtmlHelper::SCRIPT_BOTTOM,]);657 if (!isset($options['rows'])) {658 $options['row'] = 15;659 }660 if (!isset($options['data-width'])) {661 $options['data-width'] = 'inherit';662 }663 $options['data-provide'] = 'markdown';664 $options['data-iconlibrary'] = "fa";665 $options['type'] = 'textarea';666 $markdownOptions = [667 'fullscreen' => ['enable' => FALSE],668 ];669 if (!empty($options['markdown']['snippets'])) {670 $markdownOptions['addionalButtons'] = [];671 foreach ($options['markdown']['snippets'] as $name => $value) {672 $btnName = Inflector::camelize($name);673 $btn = [674 'name' => "cmd{$btnName}",675 'toggle' => FALSE,676 'title' => $name,677 'btnText' => $name,678 'callback' => "function(e){679 // Replace selection with some drinks680 chunk = \"{$value} \"681 // transform selection and set the cursor into chunked text682 e.replaceSelection(chunk)683 cursor = selected.start684 // Set the cursor685 e.setSelection(cursor,cursor+chunk.length)686 }",687 ];688 }689 }690 $markdownOptionsJson = json_encode($markdownOptions);691 $script /** @lang JavaScript */ = <<<SCRIPT692$("#{$id}").markdown({$markdownOptionsJson})693SCRIPT;694 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM,]);695 unset($options['markdown']);696 return $options;697 }698 private function __expand($options) {699 $options = $this->injectClasses(['autoExpand'], $options);700 if (!$this->hasExpandedAdded) {701 $script = <<<EXPAND702$(document)703 .one('focus.autoExpand', 'textarea.autoExpand', function(){704 var savedValue = this.value;705 this.value = '';706 this.baseScrollHeight = this.scrollHeight;707 this.value = savedValue;708 })709 .on('input.autoExpand', 'textarea.autoExpand', function(){710 var minRows = this.getAttribute('data-min-rows')|0, rows;711 this.rows = minRows;712 rows = Math.ceil((this.scrollHeight - this.baseScrollHeight) / 16);713 this.rows = minRows + rows;714 });715EXPAND;716 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);717 $this->hasExpandedAdded = TRUE;718 }719 return $options;720 }721 /**722 * @param null|array $options723 *724 * @return null|array725 */726 private function __selectExtraOptions($options = NULL) {727 if (!empty($options['select-visible-div'])) {728 $groupClass = $options['select-visible-div'];729 unset($options['select-visible-div']);730 $id = $options['id'];731 if (!empty($options['id'])) {732 $id = $options['id'];733 }734 $script = self::DOCUMENT_READY_FUNCTION . "{735 $('select#${id}').change(function(){736 $(this).find('option:selected').each(function(){737 var optionValue = $(this).attr('value');738 if(optionValue){739 $('.${groupClass}').not('.' + optionValue).hide();740 $('.' + optionValue).show();741 } else{742 $('.${groupClass}').hide();743 }744 });745 }).change();746 });";747 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM,]);748 }749 return $options;750 }751 private function __useFullBase() {752 $view = $this->_View;753 $request = $view->getRequest();754 if ($request->is(['pdf'])) {755 return TRUE;756 }757 return FALSE;758 }759 private function __select2($options) {760 /**761 * https://github.com/select2/select2762 * and763 * https://github.com/select2/select2-bootstrap-theme764 * <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />765 * <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>766 */767 $useFullBase = $this->__useFullBase();768 $this->Html->useCssFile(['Scid.select2.min', 'Scid.select2-bootstrap.min'], ['fullBase' => $useFullBase]);769 $this->Html->useScript('Scid.select2.min', ['block' => HtmlHelper::SCRIPT_BOTTOM, 'fullBase' => $useFullBase]);770 $options['type'] = 'select';771 $id = $options['id'];772 $useClass = FALSE;773 if (empty($options['select2'])) {774 $selectOptions = ['minimumResultsForSearch' => 10];775 $options = $this->Html->injectClasses('select2', $options);776 $useClass = TRUE;777 } else {778 $selectOptions = $options['select2'];779 unset($options['select2']);780 }781 $selectOptions = json_encode($selectOptions);782 if ($useClass && !$this->_hasSelect2Added) {783 $script = self::DOCUMENT_READY_FUNCTION . " {784 $('.select2').select2({$selectOptions});785});";786 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);787 $this->_hasSelect2Added = TRUE;788 } else {789 $script = self::DOCUMENT_READY_FUNCTION . " {790 $('#{$id}').select2({$selectOptions});791});";792 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);793 }794 $options = $this->__selectMultipleButtons($options, $id);795 return $options;796 }797 private function __select2Sortable($options) {798 $this->Html->useCssFile(['Scid.select2.min', 'Scid.select2-bootstrap.min']);799 $this->Html->useScript(['Scid.select2.min', 'Scid.jquery-ui.min'], ['block' => HtmlHelper::SCRIPT_BOTTOM]);800 $options['type'] = 'select';801 $id = $options['id'];802 $useClass = FALSE;803 if (empty($options['select2'])) {804 $selectOptions = ['minimumResultsForSearch' => 10];805 $options = $this->Html->injectClasses('select2', $options);806 $useClass = TRUE;807 } else {808 $selectOptions = $options['select2'];809 unset($options['select2']);810 }811 $selectOptions = json_encode($selectOptions);812 if ($useClass && !$this->_hasSelect2Added) {813 $script = self::DOCUMENT_READY_FUNCTION . <<<SELECT_2_SORTABLE_USE814{815 $('#{$id}').select2({$selectOptions});816 function select2_sortable(\$select2){817 var ul = \$select2.next('.select2-container').first('ul.select2-selection__rendered');818 ul.sortable({819 placeholder : 'ui-state-highlight',820 forcePlaceholderSize: true,821 items : 'li:not(.select2-search__field)',822 tolerance : 'pointer',823 stop: function() {824 $($(ul).find('.select2-selection__choice').get().reverse()).each(function() {825 var title = $(this).data('title');826 function hasTitle(title, value) {827 return $(this).html() == title;828}829 var option = $('#test option').filter(function () {830 return $(this).html() == title;831 }).val();832 \$select2.prepend(option);833 });834 }835 });836 }837 select2_sortable($("#{$id}"));838});839SELECT_2_SORTABLE_USE;840 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);841 $this->_hasSelect2Added = TRUE;842 } else {843 $script = self::DOCUMENT_READY_FUNCTION . " {844 $('#{$id}').select2({$selectOptions});845});";846 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);847 }848 return $options;849 }850 /**851 * @param null|array $options852 *853 * @return null|array854 */855 private function __sortableSerialize($options) {856 $this->Html->useScript('Scid.jquery-sortable-min', ['block' => HtmlHelper::SCRIPT_BOTTOM]);857 $id = $options['id'];858 $group = 'serialization';859 if (!empty($options['sortable-serialize']['group'])) {860 $group = $options['sortable-serialize']['group'];861 }862 $tag = 'ul';863 if (!empty($options['sortable-serialize']['tag'])) {864 $tag = $options['sortable-serialize']['tag'];865 }866 $script = "var group = $('${tag}.${group}').sortable({867 group: '${group}',868 delay: 500,869 onDrop: function (\$item, container, _super) {870 var data = group.sortable('serialize').get();871 var jsonString = JSON.stringify(data, null, ' ');872 $('#${id}').val(jsonString);873 _super(\$item, container);874 }875});";876 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM,]);877 if ($options['sortable-serialize']['test'] && $options['sortable-serialize']['test']) {878 $options['type'] = 'textarea';879 $options['label'] = 'Serialized ' . $group;880 } else {881 $options['type'] = 'hidden';882 $this->unlockField($options['name']);883 }884 return $options;885 }886 /**887 * @param null|array $options888 *889 * @return null|array890 */891 private function __sortablePost($options) {892 $this->Html->useScript('Scid.jquery-sortable-min', ['block' => HtmlHelper::SCRIPT_BOTTOM]);893 $id = $options['id'];894 $url = $options['url'];895 if (is_array($url)) {896 $url = $this->Url->build($url);897 }898 unset($options['url']);899 $group = 'serialization';900 if (!empty($options['sortable-serialize']['group'])) {901 $group = $options['sortable-serialize']['group'];902 }903 $tag = 'ul';904 if (!empty($options['sortable-serialize']['tag'])) {905 $tag = $options['sortable-serialize']['tag'];906 }907 if (!empty($options['sortable-serialize']['target_id'])) {908 $target_id = $options['sortable-serialize']['target_id'];909 }910 $script = <<<TAG911var group = $('${tag}.${group}').sortable({912 group: '${group}',913 delay: 500,914 onDrop: function (\$item, container, _super915)916{917 var data = group.sortable('serialize').get();918var token = $('[name="_csrfToken"]').val();919 var jsonString = JSON.stringify(data, null, ' ');920 $('#${id}').val(jsonString);921 $.ajax({922 beforeSend: function (xhr) { // Add this line923 xhr.setRequestHeader('X-CSRF-Token', $('[name="_csrfToken"]').val());924 },925 data: jsonString,926 type: 'POST',927 url: '${url}',928 dataType: "html",929 success: function(data, textStatus) {930 $("#{$target_id}").html(data);931 },932 });933 _super(\$item, container934)935 ;936}937})938;939TAG;940 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);941 if ($options['sortable-serialize']['test'] && $options['sortable-serialize']['test']) {942 $options['type'] = 'textarea';943 $options['label'] = 'Serialized ' . $group;944 } else {945 $options['type'] = 'hidden';946 }947 return $options;948 }949 /**950 * @param null|array $options951 *952 * @return null|array953 */954 private function __durationPicker($options) {955 $id = $options['id'];956 $options['type'] = 'text';957 $this->Html->useScript(['Scid.bootstrap-duration-picker',], ['block' => HtmlHelper::SCRIPT_BOTTOM,]);958 $showSeconds = 'false';959 if (!empty($options['duration']['showSeconds'])) {960 if ($options['duration']['showSeconds']) {961 $showSeconds = 'true';962 }963 }964 $showDays = 'true';965 if (isset($options['duration']['showDays'])) {966 if ($options['duration']['showDays']) {967 $showDays = 'true';968 } else {969 $showDays = 'false';970 }971 }972 $onChanged = '';973 if (!empty($options['duration']['onChanged'])) {974 $onChanged = ',975 onChanged: function (value) {976 ' . $options['duration']['onChanged'] . '977 }';978 }979 $script = "$('#${id}').durationPicker({980 // defines whether to show seconds or not981 showSeconds: ${showSeconds},982 // defines whether to show days or not983 showDays: ${showDays}984 ${onChanged}985});";986 unset($options['duration']);987 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM,]);988 return $options;989 }990 /**991 * https://pqina.nl/filepond/992 *993 * @param $fieldName994 * @param $options995 *996 * @return array997 */998 private function __filepond($fieldName, $options) {999 $filepondOptions = [1000 'lableIdle' =>1001 'Drag & Drop your picture or <span class="filepond--label-action">Browse</span>',1002 ];1003 if (!empty($options['filepond'])) {1004 $filepondOptions = $options['filepond'];1005 unset($options['filepond']);1006 }1007 $this->Html->useScript('Scid.filepond.min');1008 $this->Html->useCssFile('Scid.filepond.min');1009 $options = $this->Html->injectClasses('filepond', $options);1010 foreach ($this->_filepondRequiredPlugins as $name) {1011 $this->_registerFilepondPlugin($name);1012 }1013 foreach ($filepondOptions as $option => $value) {1014 if (!empty($this->_filepondPluginCollections[$option])) {1015 $pluginCollection = $this->_filepondPluginCollections[$option];1016 foreach ($pluginCollection as $name) {1017 $this->_registerFilepondPlugin($name);1018 }1019 }1020 }1021 $filepondOptions = json_encode($filepondOptions);1022 $options['type'] = 'file';1023 $id = $options['id'];1024 $script = "FilePond.create(1025 document.querySelector('#${id}'),1026 ${filepondOptions}1027);";1028 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1029 $this->unlockField($fieldName . '.name');1030 $this->unlockField($fieldName . '.type');1031 $this->unlockField($fieldName . 'tmp_name');1032 $this->unlockField($fieldName . 'error');1033 $this->unlockField($fieldName . 'size');1034 $this->unlockField($fieldName);1035 return $options;1036 }1037 /**1038 * @param $name1039 *1040 * @return void1041 */1042 private function _registerFilepondPlugin($name) {1043 if (empty($this->_filePondPluginsRegistered[$name])) {1044 $value = $this->_filepondPlugins[$name];1045 $this->Html->useScript('Scid.filepond-plugin-' . $value['script'] . '.min');1046 if (!empty($value['css'])) {1047 $this->Html->useCssFile('Scid.filepond-plugin-' . $value['css'] . '.min');1048 }1049 $this->Html->scriptBlock("FilePond.registerPlugin($name);",1050 ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1051 $this->_filePondPluginsRegistered[$name] = TRUE;1052 }1053 }1054 /**1055 *1056 * from https://www.cssscript.com/generic-country-state-dropdown-list-countries-js/#comments1057 *1058 * @param $options1059 *1060 * @return mixed1061 */1062 private function __countries($options) {1063 $this->Html->useScript('Scid.countries');1064 if (empty($options['state_id'])) {1065 $statesId = 'state';1066 } else {1067 $statesId = $options['state_id'];1068 unset($options['state_id']);1069 }1070 $countriesId = $options['id'];1071 $options['type'] = 'select';1072 $script = "populateCountries(\"${countriesId}\", \"${statesId}\");";1073 $this->Html->scriptBlock($script, ['block' => HtmlHelper::SCRIPT_BOTTOM]);1074 return $options;1075 }1076 /**1077 * https://github.com/minhur/bootstrap-toggle1078 * @param string $fieldName1079 * @param array $options can use $options['method'] to set POST or GET or PUT defaults to GET1080 *1081 * @return string1082 */1083 private function __bootstrapToggle($fieldName, $options) {1084 $idForInput = $this->domId($fieldName);1085 $options['type'] = 'checkbox';1086 $options['label'] = '';1087 $this->Html->useScript(['Scid.bootstrap-toggle.min',], ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1088 $this->Html->useCssFile([1089 'Scid.bootstrap-toggle.min',1090 'Scid.bootstrap-toggle-bootstrap4fix',1091 ]);1092 if (!empty($options['value']) && $options['value']) {1093 $options['checked'] = 'checked';1094 }1095 $options['data-toggle'] = 'toggle';1096 $onSwitch = '';1097 $method = 'GET';1098 if (!empty($options['method'])) {1099 $method = strtoupper($options['method']);1100 }1101 if (!empty($options['url'])) {1102 $url = $options['url'];1103 if (is_array($url)) {1104 $url = $this->Url->build($url);1105 }1106 $token = $this->request->getParam('_csrfToken');1107 $onSwitch = /** @lang jquery */1108 <<<SWITCH1109 $(function() {1110 $('#{$idForInput}').change(function() {1111 var state=$(this).prop('checked');1112 $.ajax({1113 type: "{$method}",1114 url: "{$url}&new_state=" + state,1115 data: state,1116 cache: false,1117 beforeSend: function(xhr) {1118 xhr.setRequestHeader('X-CSRF-Token', "{$token}");1119 },1120 success: function(data, textStatus,jqXHR ){1121 console.log(textStatus);1122 console.log(data);1123 console.log(jqXHR);1124 },1125 error: function(jqXHR, textStatus, errorThrown){1126 console.log(textStatus);1127 console.log(errorThrown);1128 console.log(jqXHR);1129 $("#{$idForInput}").bootstrapToggle({1130 onstyle:'danger',offstyle:'danger'});1131 alert(textStatus + ': problem updating database');1132 }1133});1134 })1135 })1136 $("#{$idForInput}").on('switchChange.bootstrapSwitch', function(event, state) {1137 console.log(this); // DOM element1138 console.log(event); // jQuery event1139 console.log(state); // true | false1140 $.ajax({1141 type: "GET",1142 url: "{$url}/new_state:" + state,1143 data: state,1144 cache: false,1145 success: function(data, textStatus,jqXHR ){1146 console.log(textStatus);1147 console.log(data);1148 console.log(jqXHR);1149 },1150 error: function(jqXHR, textStatus, errorThrown){1151 console.log(textStatus);1152 console.log(errorThrown);1153 console.log(jqXHR);1154 $("#{$idForInput}").bootstrapSwitch('state', !state, true);1155 alert(textStatus + ':' + errorThrown);1156 }1157});1158 });1159SWITCH;1160 }1161 $this->Html->scriptBlock($onSwitch, ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1162 return $options;1163 }1164 /**1165 * Generate an ID suitable for use in an ID attribute.1166 *1167 * @param string $value The value to convert into an ID.1168 *1169 * @return string The generated id.1170 */1171 public function domId($value) {1172 return $this->_domId($value);1173 }1174 private function __signature($fieldName, $options) {1175 $id = $options['id'];1176 $wrapper_id = 'signature-pad-' . $id;1177 $options['templateVars']['id'] = $wrapper_id;1178 if (empty($options['templateVars']['canvasClass'])) {1179 $options['templateVars']['canvasClass'] = 'signature-pad-canvas';1180 $options['templateVars']['canvasId'] = 'signature-pad-canvas-' . $id;1181 }1182 if (!empty($options['signature'])) {1183 if (!empty($options['signature']['mime-type'])) {1184 $mimeType = $options['signature']['mime-type'];1185 } else {1186 $mimeType = 'image/svg+xml';1187 }1188 if (!empty($options['signature']['clear_id'])) {1189 $clear_id = $options['signature']['clear_id'];1190 $clear = "document.getElementById('{$clear_id}').addEventListener('click', function () {1191 signaturePad.clear();1192 });";1193 unset($options['signature']['clear']);1194 }1195 if (!empty($options['signature']['undo_id'])) {1196 $undo_id = $options['signature']['undo_id'];1197 $undo = "document.getElementById('{$undo_id}').addEventListener('click', function () {1198 signaturePad.undo();1199 });";1200 unset($options['signature']['undo_id']);1201 }1202 if (!empty($options['signature']['options'])) {1203 $signatureOptions = $options['signature']['options'];1204 }1205 unset($options['signature']);1206 }1207 if (empty($signatureOptions)) {1208 $signatureOptions = ["backgroundColor" => 'rgb(255, 255, 255)'];1209 }1210 $signatureOptions = json_encode($signatureOptions);1211 $signatureOptions = substr($signatureOptions, 0, -1);1212 $signatureOptions .= ",\n onEnd: function (event) {1213 var dataURL = signaturePad.toDataURL('{$mimeType}');1214 document.getElementById('{$id}').value = dataURL;1215 }1216 }";1217 $this->addWidget('signature',1218 ['Scid.Signature', 'text', 'label']);1219 $this->Html->useScript('Scid.signature_pad.min', ['block' => HtmlHelper::SCRIPT_BOTTOM]);1220 $signatureBlock = /** @lang JavaScript 1.8 */1221 <<<SIGNATURE_SCRIPT1222var wrapper = document.getElementById("{$wrapper_id}");1223var canvas = wrapper.querySelector("canvas");1224var signaturePad = new SignaturePad(canvas,1225 // It's Necessary to use an opaque color when saving image as JPEG;1226 // this option can be omitted if only saving as PNG or SVG1227 {$signatureOptions}1228);1229// Adjust canvas coordinate space taking into account pixel ratio,1230// to make it look crisp on mobile devices.1231// This also causes canvas to be cleared.1232function resizeCanvas() {1233 // When zoomed out to less than 100%, for some very strange reason,1234 // some browsers report devicePixelRatio as less than 11235 // and only part of the canvas is cleared then.1236 var ratio = Math.max(window.devicePixelRatio || 1, 1);1237 // This part causes the canvas to be cleared1238 canvas.width = canvas.offsetWidth * ratio;1239 canvas.height = canvas.offsetHeight * ratio;1240 canvas.getContext("2d").scale(ratio, ratio);1241 // This library does not listen for canvas changes, so after the canvas is automatically1242 // cleared by the browser, SignaturePad#isEmpty might still return false, even though the1243 // canvas looks empty, because the internal data of this library wasn't cleared. To make sure1244 // that the state of this library is consistent with visual state of the canvas, you1245 // have to clear it manually.1246 signaturePad.clear();1247}1248// On mobile devices it might make more sense to listen to orientation change,1249// rather than window resize events.1250window.onresize = resizeCanvas;1251resizeCanvas();1252SIGNATURE_SCRIPT;1253 $this->Html->scriptBlock($signatureBlock, ['block' => HtmlHelper::SCRIPT_BOTTOM]);1254 if (!empty($clear)) {1255 $this->Html->scriptBlock($clear, ['block' => HtmlHelper::SCRIPT_BOTTOM]);1256 }1257 if (!empty($undo)) {1258 $this->Html->scriptBlock($undo, ['block' => HtmlHelper::SCRIPT_BOTTOM]);1259 }1260 // $this->Html->fontCursor('#'.$wrapper_id, 'pencil',['hotspot'=>'bottom left','color'=>'brown','outline'=>'rbg(1,1,1)','size'=>32]);1261 return $options;1262 }1263 /**1264 * http://www.bootstrap-switch.org/ maynot support bootstrap 4 try bootstrapToggle1265 *1266 * @param $fieldName1267 * @param $options1268 *1269 * @return string1270 * @deprecated use boostrapToggle instead1271 */1272 private function __bootstrapSwitch($fieldName, $options) {1273 $idForInput = $this->domId($fieldName);1274 $this->Html->useScript(['Scid.bootstrap-switch.min',], ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1275 $this->Html->useCssFile('Scid.bootstrap-switch.min');1276 if (!empty($options['value']) && $options['value']) {1277 $options['checked'] = 'checked';1278 }1279 $script = <<<SCRIPT1280$("#{$idForInput}").bootstrapSwitch();1281SCRIPT;1282 $onSwitch = '';1283 if (!empty($options['url'])) {1284 $url = $options['url'];1285 if (is_array($url)) {1286 $url = Router::url($url);1287 }1288 $onSwitch = <<<SWITCH1289 $("#{$idForInput}").on('switchChange.bootstrapSwitch', function(event, state) {1290 console.log(this); // DOM element1291 console.log(event); // jQuery event1292 console.log(state); // true | false1293 $.ajax({1294 type: "GET",1295 url: "{$url}/new_state:" + state,1296 data: state,1297 cache: false,1298 success: function(data, textStatus,jqXHR ){1299 console.log(textStatus);1300 console.log(data);1301 console.log(jqXHR);1302 },1303 error: function(jqXHR, textStatus, errorThrown){1304 console.log(textStatus);1305 console.log(errorThrown);1306 console.log(jqXHR);1307 $("#{$idForInput}").bootstrapSwitch('state', !state, true);1308 alert(textStatus + ':' + errorThrown);1309 }1310});1311 });1312SWITCH;1313 }1314 $this->Html->scriptBlock($script . $onSwitch, ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1315 return $this->checkbox($fieldName, $options);1316 }1317 /**1318 * @param $fieldName1319 * @param $options1320 *1321 * @return string1322 */1323 private function __bootstrapCheckbox($fieldName, $options) {1324 $this->Html->useScript('Scid.jquery.checkboxes-1.0.5.min', ['block' => HtmlHelper::SCRIPT_BOTTOM]);1325 $text = NULL;1326 $idForInput = $this->domId($fieldName);1327 if (!empty($options['label']['text']) && is_array($options['label'])) {1328 $text = $options['label']['text'];1329 } else if (!empty($options['label']) && is_string($options['label'])) {1330 $text = $options['label'];1331 }1332 if ($text === NULL) {1333 if (strpos($fieldName, '.') !== FALSE) {1334 $fieldElements = explode('.', $fieldName);1335 $text = array_pop($fieldElements);1336 } else {1337 $text = $fieldName;1338 }1339 if (substr($text, -3) === '_id') {1340 $text = substr($text, 0, -3);1341 }1342 $text = __(Inflector::humanize(Inflector::underscore($text)));1343 }1344 $errorClass = '';1345 $error = $this->_extractOption('error', $options, NULL);1346 if ($error !== FALSE) {1347 $errMsg = $this->error($fieldName, $error);1348 if ($errMsg) {1349 $errorClass = ' error';1350 }1351 }1352 $checkAllClass = 'check';1353 if (!empty($options['checkall-class'])) {1354 $checkAllClass = $options['checkall-class'];1355 unset($options['checkall-class']);1356 }1357 $class = [$checkAllClass];1358 if (!empty($options['class'])) {1359 $class = array_merge($class, explode(' ', $options['class']));1360 }1361 $options['class'] = implode(' ', $class);1362 $html = parent::label($fieldName,1363 parent::checkbox($fieldName,1364 $options) . ' ' . $text, $options);1365 if (!empty($errMsg)) {1366 $html .= '<br />' . $errMsg;1367 }1368 $this->__addHelpBlock($options, $idForInput);1369 if (empty($options['before'])) {1370 $html = $this->Html->div('col-sm-offset-3 col-sm-6' . $errorClass, $html);1371 }1372 if (empty($options['div'])) {1373 $html = $this->Html->div('form-group' . $errorClass, $html);1374 }1375 return $html;1376 }1377 /**1378 * @param $fieldName1379 * @param $options1380 *1381 * @return string1382 */1383 private function __bootstrapCheckAll($fieldName, $options) {1384 $text = NULL;1385 $idForInput = $this->domId($fieldName);1386 if (!empty($options['label']['text']) && is_array($options['label'])) {1387 $text = $options['label']['text'];1388 } else if (!empty($options['label']) && is_string($options['label'])) {1389 $text = $options['label'];1390 }1391 if ($text === NULL) {1392 if (strpos($fieldName, '.') !== FALSE) {1393 $fieldElements = explode('.', $fieldName);1394 $text = array_pop($fieldElements);1395 } else {1396 $text = $fieldName;1397 }1398 if (substr($text, -3) === '_id') {1399 $text = substr($text, 0, -3);1400 }1401 $text = __(Inflector::humanize(Inflector::underscore($text)));1402 }1403 $checkAllClass = 'check';1404 if (!empty($options['checkall-class'])) {1405 $checkAllClass = $options['checkall-class'];1406 unset($options['checkall-class']);1407 }1408 $errorClass = '';1409 $error = $this->_extractOption('error', $options, NULL);1410 if ($error !== FALSE) {1411 $errMsg = $this->error($fieldName, $error);1412 if ($errMsg) {1413 $errorClass = ' error';1414 }1415 }1416 $html = parent::label($fieldName,1417 parent::checkbox($fieldName,1418 $options) . ' ' . $text, $options);1419 if (!empty($errMsg)) {1420 $html .= '<br />' . $errMsg;1421 }1422 $this->__addHelpBlock($options, $idForInput);1423 if (empty($options['before'])) {1424 $html = $this->Html->div('col-sm-offset-3 col-sm-6' . $errorClass, $html);1425 }1426 if (empty($options['div'])) {1427 $html = $this->Html->div('form-group' . $errorClass, $html);1428 }1429 $script = <<<CHECK_ALL_SCRIPT1430$("#{$idForInput}").click(function () {1431 $(".{$checkAllClass}").prop('checked', $(this).prop('checked'));1432});1433CHECK_ALL_SCRIPT;1434 $this->Html->scriptBlock($script, ['inline' => FALSE,]);1435 return $html;1436 }1437 /**1438 * @param $options1439 * @param $idForInput1440 *1441 * @return mixed1442 */1443 private function __bootstrapDateTimePickerOld($options, $idForInput) {1444 $this->Html->useScript([1445 'Scid.moment.min',1446 'Scid.bootstrap-datetimepicker.min',1447 ], ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1448 $this->Html->css('Scid.bootstrap-datetimepicker.min', ['block' => TRUE,]);1449 if (!empty($this->_inputDefaults['after'])) {1450 $options['after'] = $this->_inputDefaults['after'];1451 }1452 $options['after'] =1453 '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>' . $options['after'];1454 $options['type'] = 'text';1455 $this->Html->scriptBlock(self::DOCUMENT_READY_FUNCTION . " {1456 $('#{$idForInput}').datetimepicker({1457 pickTime: true1458 });1459 });", ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1460 return $options;1461 }1462 /**1463 * @param $options1464 * @param $idForInput1465 *1466 * @return mixed1467 */1468 private function __bootstrapMonthPicker($options, $idForInput) {1469 $this->Html->useScript([1470 'Scid.moment.min',1471 'Scid.bootstrap-datetimepicker.min',1472 ], ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1473 $this->Html->css('Scid.bootstrap-datetimepicker.min' , ['block' => TRUE,]);1474 if (!empty($this->_inputDefaults['after'])) {1475 $options['after'] = $this->_inputDefaults['after'];1476 }1477 $options['after'] =1478 '<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>' . $options['after'];1479 $options['type'] = 'text';1480 $this->Html->scriptBlock(self::DOCUMENT_READY_FUNCTION . " {1481 $('#{$idForInput}').datetimepicker({1482 pickTime: false,1483 format: 'MM/YYYY'1484 });1485 });", ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1486 return $options;1487 }1488 /**1489 * @param $options1490 * @param $idForInput1491 *1492 * @return mixed1493 */1494 private function __bootstrapTimePickerOld($options, $idForInput) {1495 $this->Html->useScript([1496 'Scid.moment.min',1497 'Scid.bootstrap-datetimepicker.min',1498 ], ['block' => HtmlHelper::SCRIPT_BOTTOM,]);1499 $this->Html->css('Scid.bootstrap-datetimepicker.min', ['block' => TRUE,]);1500 if (!empty($this->_inputDefaults['after'])) {1501 $options['after'] = $this->_inputDefaults['after'];1502 }1503 $options['after'] =1504 '<span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>' . $options['after'];1505 $options['type'] = 'text';1506 $this->Html->scriptBlock(self::DOCUMENT_READY_FUNCTION . " {1507 $('#{$idForInput}').datetimepicker({1508 pickDate: false,1509 minuteStepping:15,...
bundle.php
Source:bundle.php
...310 }311 /**312 * @param $name313 */314 public function useScript($name)315 {316 $url = $this->fileUrl("scripts/{$name}");317 if ($url) {318 \TAO::useScript($url);319 }320 }321 /**322 * @param $class323 * @param bool|false $check324 * @return bool|string325 */326 public function className($class, $check = false)327 {328 $className = "\\App\\Bundle\\{$this->name}\\{$class}";329 $file = \TAO::getClassFile($className);330 if (!is_file($file)) {331 $className = "\\TAO\\Bundle\\{$this->name}\\{$class}";332 if ($check) {...
PaymentHelper.php
Source:PaymentHelper.php
...101 $scriptUrl = 'https://jstest.authorize.net/v1/Accept.js';102 } else {103 $scriptUrl = 'https://js.authorize.net/v1/Accept.js';104 }105 $this->Html->useScript($scriptUrl, [106 'charset' => 'utf-8', 'type' => 'text/javascript',107 'block' => HtmlHelper::SCRIPT_BOTTOM,108 ]);109 $script = /** @lang JavaScript 1.8 */110 <<<ON_CLICK_SCRIPT111function {$onclick} {112 if (typeof event !== 'undefined') {113 event.target.disabled = true;114 }115 var authData = {};116 authData.clientKey = "{$client_key}";117 authData.apiLoginID = "{$api_login}";118 var cardData = {};119 cardData.cardNumber = document.getElementById("{$cardNumber}").value;120 cardData.fullName = document.getElementById("{$firstName}").value + ' ' + document.getElementById("{$lastName}").value;121 cardData.month = document.getElementById("{$month}").value;122 cardData.year = document.getElementById("{$year}").value;123 cardData.cardCode = document.getElementById("{$cardCode}").value;124 cardData.zip = document.getElementById("{$zip}").value;125 cardData.cardNumber = cardData.cardNumber.replace(/\D/g, '');126 // If using banking information instead of card information,127 // build a bankData object instead of a cardData object.128 //129 // var bankData = {};130 // bankData.accountNumber = document.getElementById('accountNumber').value;131 // bankData.routingNumber = document.getElementById('routingNumber').value;132 // bankData.nameOnAccount = document.getElementById('nameOnAccount').value;133 // bankData.accountType = document.getElementById('accountType').value;134 var secureData = {};135 secureData.authData = authData;136 secureData.cardData = cardData;137 // If using banking information instead of card information,138 // send the bankData object instead of the cardData object.139 //140 // secureData.bankData = bankData;141 Accept.dispatchData(secureData, responseHandler);142 function responseHandler(response) {143 if (response.messages.resultCode === "Error") {144 var i = 0;145 while (i < response.messages.message.length) {146 console.log(147 response.messages.message[i].code + ": " +148 response.messages.message[i].text149 );150 alert(response.messages.message[i].code + ": " +151 response.messages.message[i].text);152 i = i + 1;153 if (typeof event !== 'undefined') {154 event.target.disabled = false;155 }156 }157 } else {158 paymentFormUpdate(response.opaqueData);159 }160 }161}162function paymentFormUpdate(opaqueData) {163 document.getElementById("dataDescriptor").value = opaqueData.dataDescriptor;164 document.getElementById("dataValue").value = opaqueData.dataValue;165 var cc_num = document.getElementById("{$cardNumber}").value;166 cc_num = cc_num.substring(cc_num.length - 4, cc_num.length);167 document.getElementById("{$cardNumber}").value = cc_num;168 document.getElementById("{$cardCode}").removeAttribute("required");169 document.getElementById("{$cardCode}").value = "";170 document.getElementById("{$form_id}").submit();171}172ON_CLICK_SCRIPT;173 } else {174 if ($this->_sandbox) {175 $scriptUrl = 'https://jstest.authorize.net/v3/AcceptUI.js';176 } else {177 $scriptUrl = 'https://js.authorize.net/v3/AcceptUI.js';178 }179 $this->Html->useScript($scriptUrl, [180 'charset' => 'utf-8', 'type' => 'text/javascript',181 'block' => HtmlHelper::SCRIPT_BOTTOM,182 ]);183 $script = /** @lang javascript */184 <<<HOSTED_SCRIPT185function responseHandler(response) {186 if (response.messages.resultCode === "Error") {187 var i = 0;188 while (i < response.messages.message.length) {189 console.log(190 response.messages.message[i].code + ": " +191 response.messages.message[i].text192 );193 i = i + 1;...
useScript
Using AI Code Generation
1$stub->useScript("2.php");2$stub->useScript("3.php");3$stub->useScript("4.php");4$stub->useScript("4.php");5$stub->useScript("5.php");6$stub->useScript("6.php");7$stub->useScript("7.php");8$stub->useScript("8.php");9$stub->useScript("9.php");10$stub->useScript("10.php");11$stub->useScript("11.php");12$stub->useScript("12.php");13$stub->useScript("13.php");14$stub->useScript("14.php");15$stub->useScript("15.php");16$stub->useScript("16.php");17$stub->useScript("17.php");18$stub->useScript("18.php");19$stub->useScript("19.php");
useScript
Using AI Code Generation
1";2$obj = new stub();3$obj->useScript('test.php');4$obj->useScript('test2.php');5";6$obj = new stub();7$obj->useScript('test.php');8$obj->useScript('test2.php');
useScript
Using AI Code Generation
1$stub = new Stub;2$stub->useScript('2.php');3echo "Hello World";4class Stub {5 public function useScript($scriptName) {6 include $scriptName;7 }8}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with useScript on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!