How to use tplInput method in ng-mocks

Best JavaScript code snippet using ng-mocks

field.js

Source:field.js Github

copy

Full Screen

1/* This file is part of Indico.2 * Copyright (C) 2002 - 2014 European Organization for Nuclear Research (CERN).3 *4 * Indico is free software; you can redistribute it and/or5 * modify it under the terms of the GNU General Public License as6 * published by the Free Software Foundation; either version 2 of the7 * License, or (at your option) any later version.8 *9 * Indico is distributed in the hope that it will be useful, but10 * WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12 * General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with Indico; if not, see <http://www.gnu.org/licenses/>.16 */17ndRegForm.controller('FieldCtrl', function($scope, regFormFactory) {18 $scope.fieldApi = {};19 var getRequestParams = function(field) {20 return {21 confId: $scope.confId,22 sectionId: $scope.section.id,23 fieldId: field.id24 };25 };26 $scope.fieldApi.disableField = function(field) {27 regFormFactory.Fields.disable(getRequestParams(field), function(updatedField) {28 regFormFactory.processResponse(updatedField, {29 success: function(updatedField) {30 var index = -1;31 _.find($scope.section.items, function(item) {32 index++;33 return item.id == $scope.field.id;34 });35 $scope.field.disabled = updatedField.disabled;36 $scope.section.items.splice(index, 1);37 $scope.section.items.push($scope.field);38 }39 });40 });41 };42 $scope.fieldApi.enableField = function(field) {43 regFormFactory.Fields.enable(getRequestParams(field), function(updatedField) {44 regFormFactory.processResponse(updatedField, {45 success: function(updatedField) {46 var index = -1;47 _.find($scope.section.items, function(item) {48 index++;49 return item.id == $scope.field.id;50 });51 $scope.field.disabled = updatedField.disabled;52 $scope.section.items.splice(index, 1);53 $scope.section.items.push($scope.field);54 }55 });56 });57 };58 $scope.fieldApi.removeField = function(field) {59 $scope.sectionApi.removeField($scope.section, field);60 };61 $scope.fieldApi.updateField = function(field, data) {62 var postData = getRequestParams(field);63 postData = angular.extend(postData, {fieldData: data});64 if ($scope.isNew()) {65 delete postData['fieldId'];66 }67 regFormFactory.Fields.save(postData, function(response) {68 regFormFactory.processResponse(response, {69 success: function(response) {70 $scope.field = angular.extend($scope.field, response);71 }72 });73 });74 };75 $scope.getName = function(input) {76 if (input == 'date') {77 return '_genfield_' + $scope.section.id + '_' + $scope.field.id + '_';78 } else {79 return '*genfield*' + $scope.section.id + '-' + $scope.field.id;80 }81 };82 $scope.openFieldSettings = function() {83 $scope.dialog.open = true;84 };85 $scope.canBeDeleted = function(field) {86 return field.lock? field.lock.indexOf('delete') == -1 : false;87 };88 $scope.canBeDisabled = function(field) {89 return field.lock? field.lock.indexOf('disable') == -1 : false;90 };91 $scope.isNew = function() {92 return $scope.field.id == -1;93 };94 $scope.settings = {95 billable: false,96 date: false,97 defaultValue: false,98 singleColumn: false,99 itemtable: false,100 mandatory: true,101 number: false,102 placesLimit: false,103 rowsAndColumns: false,104 size: false,105 formData: [106 'caption',107 'description',108 'mandatory'109 ]110 };111 $scope.dialog = {112 open: false,113 title: function() {114 return $scope.isNew()? $T('New Field') : $T('Edit Field');115 },116 okButton: function() {117 return $scope.isNew()? $T('Add') : $T('Update');118 },119 onOk: function(dialogScope) {120 if (dialogScope.optionsForm.$invalid === true) {121 dialogScope.$apply(dialogScope.setSelectedTab('tab-options'));122 return false;123 }124 if ($scope.settings.itemtable && !dialogScope.hasRadioItems()) {125 dialogScope.$apply(dialogScope.setSelectedTab('tab-editItems'));126 return false;127 }128 $scope.fieldApi.updateField($scope.field, dialogScope.formData);129 return true;130 },131 onCancel: function() {132 if ($scope.isNew()) {133 $scope.sectionApi.removeNewField();134 }135 }136 };137 $scope.fieldName = $scope.getName($scope.field.input);138});139ndRegForm.controller('BillableCtrl', function($scope, $filter) {140 $scope.getBillableStr = function(item, userValue, type) {141 var str = '';142 if ($scope.isBillable(item)) {143 str += ' {0} {1}'.format(item.price, $scope.currency);144 }145 if ($scope.hasPlacesLimit(item)) {146 if ($scope.hasPlacesLeft(item, userValue, type)) {147 str += ' [{0} {1}]'.format($scope.getNoPlacesLeft(item, userValue, type), $filter('i18n')('place(s) left'));148 } else {149 str += ' [{0}]'.format($filter('i18n')('no places left'));150 }151 }152 return str;153 };154 $scope.isBillable = function(item) {155 item = item || {};156 return item.billable || item.isBillable;157 };158 $scope.isDisabled = function(item, userValue, type) {159 item = item || {};160 return (item.disabled === true || item.isEnabled === false) ||161 !$scope.hasPlacesLeft(item, userValue, type) || item.cancelled === true;162 };163 $scope.hasPlacesLeft = function(item, userValue, type) {164 item = item || {};165 if (!$scope.hasPlacesLimit(item)) {166 return true;167 } else {168 return $scope.getNoPlacesLeft(item, userValue, type) > 0;169 }170 };171 $scope.hasPlacesLimit = function(item) {172 item = item || {};173 if (item.placesLimit !== undefined) {174 return item.placesLimit !== 0;175 }176 return false;177 };178 $scope.paymentBlocked = function(item, userdata, validation) {179 item = item || {};180 userdata = userdata || {};181 if (validation !== undefined) {182 return ($scope.isBillable(item) && userdata.paid) || validation(userdata);183 } else {184 return $scope.isBillable(item) && userdata.paid;185 }186 };187 $scope.getNoPlacesLeft = function(item, userValue, type) {188 var noPlaces = item.noPlacesLeft;189 if(type === 'checkbox' && userValue === 'yes'){190 noPlaces += 1;191 } else if (type === 'radio' && item.caption === userValue) {192 noPlaces += 1;193 } else if (type === 'accomodation' && item.id === userValue) {194 noPlaces += 1;195 } else if (type === 'socialEvent') {196 noPlaces += userValue;197 }198 return noPlaces;199 };200});201ndRegForm.directive('ndField', function($rootScope, url, regFormFactory) {202 return {203 restrict: 'E',204 replace: true,205 templateUrl: url.tpl('field.tpl.html'),206 controller: 'FieldCtrl',207 link: function(scope) {208 // This is a broadcast message from parent (section) scope209 // TODO look for broadcast messages to children the angular way210 scope.$parent.$watch('dialogs.newfield', function(val) {211 if (val && scope.isNew()) {212 scope.dialog.open = true;213 scope.$parent.dialogs.newfield = false;214 }215 });216 }217 };218});219ndRegForm.directive('ndCheckboxField', function(url) {220 return {221 require: 'ndField',222 controller: function($scope) {223 $scope.tplInput = url.tpl('fields/checkbox.tpl.html');224 },225 link: function(scope) {226 scope.checkboxValue = false;227 scope.settings.fieldName = $T("Multiple choices/checkbox");228 scope.settings.billable = true;229 scope.settings.singleColumn = true;230 scope.settings.placesLimit = true;231 scope.settings.formData.push('billable');232 scope.settings.formData.push('price');233 scope.settings.formData.push('placesLimit');234 scope.$watch('userdata[fieldName]', function() {235 scope.checkboxValue = scope.userdata[scope.fieldName] === 'yes';236 });237 }238 };239});240ndRegForm.directive('ndCountryField', function(url) {241 return {242 require: 'ndField',243 controller: function($scope) {244 $scope.tplInput = url.tpl('fields/country.tpl.html');245 },246 link: function(scope) {247 scope.settings.fieldName = $T("Country");248 }249 };250});251ndRegForm.directive('ndDateField', function(url) {252 return {253 require: 'ndField',254 controller: function($scope) {255 $scope.tplInput = url.tpl('fields/date.tpl.html');256 },257 link: function(scope) {258 scope.settings.fieldName = $T("Date");259 scope.settings.date = true;260 scope.settings.formData.push(['values', 'displayFormats']);261 scope.settings.formData.push(['values', 'dateFormat']);262 scope.dateInputs = [263 '{0}Day'.format(scope.getName(scope.field.input)),264 '{0}Month'.format(scope.getName(scope.field.input)),265 '{0}Year'.format(scope.getName(scope.field.input)),266 '{0}Hour'.format(scope.getName(scope.field.input)),267 '{0}Min'.format(scope.getName(scope.field.input))268 ];269 scope.showTime = function(str) {270 return str? str.match('H') !== null : false;271 };272 }273 };274});275ndRegForm.directive('ndFileField', function(url) {276 return {277 require: 'ndField',278 controller: function($scope) {279 $scope.tplInput = url.tpl('fields/file.tpl.html');280 },281 link: function(scope) {282 scope.settings.fieldName = $T("File");283 scope.removeAttachment = function() {284 delete scope.userdata[scope.getName(scope.field.input)];285 };286 }287 };288});289ndRegForm.directive('ndLabelField', function(url) {290 return {291 require: 'ndField',292 controller: function($scope) {293 $scope.tplInput = url.tpl('fields/label.tpl.html');294 },295 link: function(scope) {296 scope.settings.fieldName = $T("Free Text");297 scope.settings.singleColumn = true;298 scope.settings.billable = true;299 scope.settings.mandatory = false;300 scope.settings.formData.push('billable');301 scope.settings.formData.push('price');302 }303 };304});305ndRegForm.directive('ndNumberField', function(url) {306 return {307 require: 'ndField',308 controller: function($scope) {309 $scope.tplInput = url.tpl('fields/number.tpl.html');310 },311 link: function(scope) {312 scope.settings.fieldName = $T("Number");313 scope.settings.billable = true;314 scope.settings.number = true;315 scope.settings.formData.push('billable');316 scope.settings.formData.push('price');317 scope.settings.formData.push(['values', 'minValue']);318 scope.settings.formData.push(['values', 'length']);319 scope.updateSubtotal = function() {320 var value = scope.userdata[scope.fieldName];321 if ((isNaN(parseInt(value, 10)) || parseInt(value, 10) < 0)) {322 scope.subtotal = 0;323 } else {324 scope.subtotal = parseInt(value, 10) * parseInt(scope.field.price, 10);325 }326 };327 scope.$watch('userdata[fieldName]', function() {328 scope.updateSubtotal();329 });330 }331 };332});333ndRegForm.directive('ndRadioField', function(url) {334 return {335 require: 'ndField',336 controller: function($scope) {337 $scope.tplInput = url.tpl('fields/radio.tpl.html');338 },339 link: function(scope) {340 scope.settings.fieldName = $T("Multiple options/One choice");341 scope.settings.defaultValue = true;342 scope.settings.itemtable = true;343 // keep track of the selected radio item344 scope.radioValue = {};345 scope.$watch('userdata[fieldName]', function(){346 scope.radioValue['id'] = scope.getId(scope.getValue(scope.fieldName));347 });348 scope.getInputTpl = function(inputType) {349 return url.tpl('fields/{0}.tpl.html'.format(inputType));350 };351 scope.anyBillableItemPayed = function(userdata) {352 if (userdata.paid) {353 var item = _.find(scope.field.values.radioitems, function(item) {354 return item.caption == userdata[scope.getName(scope.field.input)];355 }) || {};356 return item.isBillable && item.price !== '' && item.price !== 0;357 }358 return false;359 };360 scope.getId = function(fieldValue) {361 var id;362 if (fieldValue !== undefined) {363 var item = _.find(scope.field.values.radioitems, function(item) {364 return item.caption == fieldValue;365 });366 if (item !== undefined) {367 id = item.id;368 }369 }370 return id;371 };372 scope.getValue = function(fieldName) {373 if (!scope.userdata[fieldName] || scope.userdata[fieldName] === '') {374 return scope.field.values.defaultItem;375 } else {376 return scope.userdata[fieldName];377 }378 };379 scope.getSelectedItem = function(itemId) {380 return _.find(scope.field.values.radioitems, function(item) {381 return item.id == itemId;382 });383 };384 scope.settings.formData.push(['values', 'defaultItem']);385 scope.settings.formData.push(['values', 'inputType']);386 scope.settings.editionTable = {387 sortable: false,388 actions: ['remove', 'sortable'],389 colNames:[390 $T("Caption"),391 $T("Billable"),392 $T("Price"),393 $T("Places limit"),394 $T("Enabled")],395 colModel: [396 {name:'caption',397 index:'caption',398 align: 'center',399 width:160,400 editable: true,401 edittype: "text",402 editoptions: {403 size: "30",404 maxlength: "50"}},405 {name:'billable',406 index:'isBillable',407 width: 60,408 editable: true,409 align: 'center',410 defaultVal: false,411 edittype: 'bool_select'},412 {name: 'price',413 index: 'price',414 align: 'center',415 width: 50,416 editable: true,417 edittype: "text",418 editoptions: {419 size: "7",420 maxlength: "20"}},421 {name: 'placesLimit',422 index: 'placesLimit',423 align: 'center',424 width: 80,425 editable: true,426 edittype: "text",427 editoptions: {428 size: "7",429 maxlength: "20"}},430 {name: 'isEnabled',431 index: 'isEnabled',432 width: 60,433 editable: true,434 align: 'center',435 edittype: 'bool_select',436 defaultVal: true}437 ]438 };439 }440 };441});442ndRegForm.directive('ndTelephoneField', function(url) {443 return {444 require: 'ndField',445 controller: function($scope) {446 $scope.tplInput = url.tpl('fields/telephone.tpl.html');447 },448 link: function(scope) {449 scope.settings.fieldName = $T("Telephone");450 scope.settings.formData.push(['values', 'length']);451 }452 };453});454ndRegForm.directive('ndTextField', function(url) {455 return {456 require: 'ndField',457 controller: function($scope) {458 $scope.tplInput = url.tpl('fields/text.tpl.html');459 },460 link: function(scope) {461 scope.settings.fieldName = $T("Text");462 scope.settings.size = true;463 scope.settings.formData.push(['values', 'length']);464 }465 };466});467ndRegForm.directive('ndTextareaField', function(url) {468 return {469 require: 'ndField',470 controller: function($scope) {471 $scope.tplInput = url.tpl('fields/textarea.tpl.html');472 },473 link: function(scope) {474 scope.settings.fieldName = $T("Textarea");475 scope.settings.rowsAndColumns = true;476 scope.settings.formData.push(['values', 'numberOfColumns']);477 scope.settings.formData.push(['values', 'numberOfRows']);478 }479 };480});481ndRegForm.directive('ndYesnoField', function(url) {482 return {483 require: 'ndField',484 controller: function($scope) {485 $scope.tplInput = url.tpl('fields/yesno.tpl.html');486 },487 link: function(scope) {488 scope.settings.fieldName = $T("Yes/No");489 scope.settings.billable = true;490 scope.settings.placesLimit = true;491 scope.settings.formData.push('billable');492 scope.settings.formData.push('price');493 scope.settings.formData.push('placesLimit');494 }495 };496});497ndRegForm.directive('ndFieldDialog', function(url) {498 return {499 require: 'ndDialog',500 controller: function($scope) {501 $scope.templateUrl = url.tpl('fields/dialogs/base.tpl.html');502 $scope.actions.init = function() {503 $scope.field = $scope.data;504 $scope.settings = $scope.config;505 $scope.formData = {};506 $scope.formData.radioitems = [];507 $scope.formData.input = $scope.field.input;508 $scope.formData.disabled = $scope.field.disabled;509 _.each($scope.settings.formData, function(item) {510 if (Array.isArray(item) && $scope.field[item[0]] !== undefined) {511 $scope.formData[item[1]] = angular.copy($scope.field[item[0]][item[1]]);512 } else {513 $scope.formData[item] = angular.copy($scope.field[item]);514 }515 });516 _.each($scope.field.values.radioitems, function(item, ind) {517 $scope.formData.radioitems[ind] = angular.copy(item);518 });519 $scope.tabSelected = "tab-options";520 $scope.parsePrice();521 };522 $scope.parsePrice = function() {523 if ($scope.formData.price !== undefined) {524 $scope.formData.price = parseFloat($scope.formData.price);525 if (isNaN($scope.formData.price)) {526 $scope.formData.price = "";527 }528 }529 };530 $scope.addItem = function() {531 $scope.formData.radioitems.push({532 id:'isNew',533 placesLimit: 0,534 price: 0,535 isEnabled: true,536 isBillable: false537 });538 };539 $scope.sortItems = function() {540 $scope.formData.radioitems = _.sortBy($scope.formData.radioitems, function(radioitem) {541 return radioitem.caption.toLowerCase();542 });543 };544 },545 link: function(scope) {546 scope.getTpl = function(file) {547 return url.tpl(file);548 };549 scope.hasRadioItems = function () {550 return _.any(scope.formData.radioitems, function(item) {551 return item.remove !== true;552 });553 };554 }555 };...

Full Screen

Full Screen

radius_config.js

Source:radius_config.js Github

copy

Full Screen

1$( document ).on('GlangLoaded',function() {2 3 function addRadiusProfile( id, desc ) {4 5 $('#radius-groups').append('<h3 id="radius-groups-'+id+'">'+id+'<div class="iconbar"></div></h3>');6 7 var tplAddField = $('#tpl-add-field').clone( true ).attr('id',null);8 $('#radius-groups').append(tplAddField);9 createOptionAddField(tplAddField);10 addInput(tplAddField, 'description', [desc], { 'label': Glang.get('description'), 'buttons': { 'cancel': clearInput } });11 12 };13 14 function createOptionAddField( target ) {15 var sel = $(target).find('.add-field select');16 var opts = $(target).data().schema.may;17 for (var i in opts) {18 $(sel).append('<option value="'+opts[i]+'">'+opts[i]+'</option>');19 }20 $(sel).change(changedAddField);21 };22 23 function initAddField( id, opt_name, value ) {24 var grp = $('#radius-groups-'+id);25 var opt = $(grp).next().find('select option[value='+opt_name+']').first();26 if ( $(opt).length > 0 && $(opt).css('display') != 'none' ) {27 $(opt).css('display','none');28 addInput( $(grp).next(), opt_name, value, makeOpts( opt_name ));29 }30 };31 32 function changedAddField() {33 if ( $(this).val().length > 0 ) {34 addInput( $(this).parents('.ui-accordion-content').first(), $(this).val(), [''], makeOpts( $(this).val() ));35 $(this).find('option:selected').css('display','none');36 $(this).val('')37 $('#radius-groups').accordion('refresh');38 }39 };40 41 function makeOpts( name ) {42 var schema = $('#tpl-add-field').data().schema;43 var opts = { 'buttons': { 'cancel': clearInput, 'trash': removeInput} };44 var attr = schema.attr_dict[name];45 if ( attr != undefined ) {46 if ( !attr['single-value'] ) opts.buttons.plus = addInputField;47 opts.syntax = attr.syntax;48 } 49 if ( name == 'radiusGroupName' ) {50 opts.type = 'select';51 opts.label = Glang.get('admin group');52 opts.adm_groups = schema.adm_groups;53 }54 return opts;55 };56 57 function clearInput() {58 $(this).parents('.hline').find('input').val('');59 $(this).parents('.hline').find('select').val('');60 };61 62 function removeInput() {63 var name = $(this).parents('.hline').first().find('label').first().data().value;64 $(this).parents('.ui-accordion-content').first().find('select option[value='+name+']').css('display','');65 $(this).parents('.hline').remove();66 $('#radius-groups').accordion('refresh');67 };68 69 function addInput( target, name, value, opts ) {70 var id = $(target).prev().attr('id').replace(/^radius-groups-/,'');71 var tplType = opts.type? opts.type : 'input';72 var tplInput = $('#tpl-'+tplType).clone().attr('id',null);73 $(tplInput).find('label').html((opts.label)?opts.label:name).data({'value':name});74 for (var i in value) {75 var tplBox = $('#tpl-input-box').clone(true).attr('id',null);76 var objInput = null;77 if ( tplType == 'select' ) {78 objInput = $('<select>');79 $(objInput).append($('<option>').val("").html(Glang.get('Select value')));80 for ( var gid in opts.adm_groups ) $(objInput).append($('<option>').val(gid).html(opts.adm_groups[gid]));81 $(objInput).val("");82 } else objInput = $('<input type="text" placeholder="'+Glang.get('Required value')+'">');83 $(objInput).addClass('transparent').attr('name','profiles['+id+']['+name+'][]').val(value[i]);84 $(tplInput).find('div.input-right').append($(tplBox).append(objInput));85 }86 testShowInputField( tplInput );87 if ( opts.buttons )88 for ( var btn in opts.buttons )89 $(tplInput).find('.iconbar').append( $('<button></button>').button({ icons: { primary: 'ui-icon-'+btn } }).click(opts.buttons[btn]));90 $(target).find('.input-grp').append(tplInput);91 };92 93 function updateTips( t ) {94 $('#tpl-dialog-add .err-msg').find('label').html( t )95 $('#tpl-dialog-add .err-msg').animate({ opacity: 1 }, 500);96 setTimeout(function() { $('#tpl-dialog-add .err-msg').animate({opacity: 0}, 1000 ); }, 3000 );97 };98 99 function addMessage( target, msg, type, prefix ) {100 if ( typeof msg === 'object' ) {101 for ( var i in msg ) addMessage( target, msg[i], type, ((!i.match(/^[0-9]+$/))||prefix)? ((prefix?prefix+': ':'')+((!i.match(/^[0-9]+$/))?i:'')) : undefined );102 } else {103 $(target).append(104 $('<div>').addClass('hline bmargin ui-state-'+type+' ui-corner-all').append(105 $('<label>').addClass('cell').html((prefix?prefix+': ':'')+msg+'.')));106 }107 };108 109 function checkInUse( o, n ) {110 if ( $('#radius-groups-'+(o.find('input').val().trim())).length > 0 ) {111 o.addClass( "ui-state-error" );112 updateTips( n );113 return false;114 }115 return true;116 };117 118 function checkLength( o, min, max, n ) {119 if ( o.find('input').val().trim().length > max || o.find('input').val().trim().length < min ) {120 o.addClass( "ui-state-error" );121 updateTips( n );122 return false;123 }124 return true;125 };126 127 function checkRegexp( o, expr, n ) {128 o.removeClass( "ui-state-error" );129 if ( !( expr.test( o.find('input').val().trim() ) ) ) {130 o.addClass( "ui-state-error" );131 updateTips( n );132 return false;133 }134 return true;135 };136 137 function checkInput( target, flags ) {138 var tplInput = $('#tpl-input').clone().attr('id',null);139 $(tplInput).find('label').html(name);140 $(tplInput).find('input').val(value).attr('name','profiles['+id+']['+name+']');141 $(target).find('.input-grp').append(tplInput);142 };143 144 function addInputField() {145 var tplInput = $(this).parents('div.hline:first').find('div.input-right');146 var newInput = $(tplInput).find('div.input-box:first').clone(true);147 $(newInput).find('button').next().val(null);148 $(tplInput).append(newInput);149 testShowInputField( tplInput );150 $('#radius-groups').accordion('refresh');151 };152 153 function remInputField() {154 var tplInput = $(this).parents('div.input-right:first');155 $(this).parent().remove();156 testShowInputField( tplInput );157 $('#radius-groups').accordion('refresh');158 };159 160 function testShowInputField( tplInput ) {161 var arrButtons = $(tplInput).find('.input-box button');162 if ( $(arrButtons).length > 1) $(arrButtons).parent().addClass('show');163 else $(arrButtons).parent().removeClass('show');164 };165 166 $('#tpl-input-box').find('button').button({ icons: { primary: 'ui-icon-minus' } }).click(remInputField);167 168 $.post( '/index.php?menuaction=expressoAdmin1_2.uiradius.config' )169 .done(function( response, message ) {170 171 $('#tpl-add-field').data({'schema':response.schema});172 173 if ( response && response.profiles ) {174 for ( var id in response.profiles ) {175 addRadiusProfile(id,response.profiles[id].description);176 for ( var field in response.profiles[id] )177 initAddField(id,field,response.profiles[id][field]);178 }179 }180 $('#radius-groups').accordion({ collapsible: true, active: false }).show(400).accordion('refresh');181 182 }).fail(function( response ) {183 184 var message = response? (( response.responseJSON && response.responseJSON.message)? response.responseJSON.message : response.statusText ) : Glang.get('unknown');185 alert( Glang.get('Error requesting page')+': '+message+' ('+response.status+')' );186 187 }).always(function() {188 189 $('form.ajax').submit(function( event ) {190 if ( $(this).data('inputHandlerEvent') == 'save' ) {191 192 $('#tpl-dialog-save').dialog( "open" );193 194 var data = $(this).serialize();195 $.post( '/index.php?menuaction=expressoAdmin1_2.uiradius.save', data )196 .done(function( response, message ) {197 198 $('#tpl-dialog-save').data({status:'success'});199 if ( response ) addMessage( $('#tpl-dialog-save'), response, 'highlight' );200 201 }).fail(function( response, h, x, y ) {202 203 $('#tpl-dialog-save').data({status:'error'});204 addMessage( $('#tpl-dialog-save'), response? (( response.responseJSON )? response.responseJSON : response.statusText ) : Glang.get('unknown'), 'error' ); 205 206 }).always(function() {207 var top = $('#tpl-dialog-save').parents('.ui-dialog');208 $(top).find('.loadgif').hide();209 $(top).find('.ui-dialog-buttonset button').prop('disabled', false).removeClass("ui-state-disabled");210 });211 } else if ( $(this).data('inputHandlerEvent') == 'cancel' ) {212 213 window.location = '/admin/index.php';214 215 }216 $(this).data({'inputHandlerEvent': 'none'});217 event.preventDefault();218 }).find('input[type=submit]').prop('disabled', false).button().click(function() {219 220 $('form.ajax').data({'inputHandlerEvent': this.name});221 222 });223 224 $('#tpl-dialog-save').dialog({225 width: 500,226 position: 'center',227 modal: true,228 autoOpen: false,229 draggable: false,230 resizable: false,231 closeOnEscape: false,232 open: function(event) {233 var top = $(this).parents('.ui-dialog');234 $(top).find('.ui-dialog-titlebar-close').hide();235 $(top).find('.loadgif').show();236 $(top).find('.ui-dialog-buttonset button').prop('disabled', true).addClass("ui-state-disabled");237 },238 close: function(event) {239 if ($(this).data().status == 'success' ) window.location = '/admin/index.php';240 else $(this).html('');241 },242 buttons: [243 {244 text: Glang.get('Close'),245 click: function() {246 $( this ).dialog( "close" );247 }248 }249 ]250 }).parents('.ui-dialog').find('.ui-dialog-titlebar').append('<img class="loadgif" src="./prototype/plugins/messenger/images/ajax-loader.gif">');251 252 $('#tpl-dialog-add').dialog({253 autoOpen: false,254 width: 500,255 draggable: false,256 resizable: false,257 position: 'center',258 modal: true,259 buttons: [ 260 {261 text: Glang.get('Add'),262 click: function() {263 var bValid = true;264 $('#tpl-dialog-add input[type=text]').parents('.ui-state-error').removeClass( "ui-state-error" );265 bValid = bValid && checkLength( $('#input-profile-name'), 1, 32, Glang.get('The name length must be between 1 and 32 characters')+'.' );266 bValid = bValid && checkRegexp( $('#input-profile-name'), /^[a-zA-Z]([0-9a-zA-Z\-_])*$/, Glang.get('The name must begin with a letter, without spaces')+'.' );267 bValid = bValid && checkInUse( $('#input-profile-name'), Glang.get('This name is in use')+'.' );268 bValid = bValid && checkLength( $('#input-profile-desc'), 1, 1024, Glang.get('Description must be non empty')+'.' );269 bValid = bValid && checkRegexp( $('#input-profile-desc'), /^[\w\d ÀÁÂÃÄÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜàáâãäçèéêëìíîïòóôõöùúûü]+$/i, Glang.get('Description has an invalid character')+'.' );270 if ( bValid ) {271 addRadiusProfile($('#input-profile-name').find('input').val().trim(),$('#input-profile-desc').find('input').val().trim());272 $('#radius-groups').accordion('refresh');273 $( this ).dialog( "close" );274 }275 }276 }277 ],278 close: function() {279 $('#tpl-dialog-add input[type=text]').val( "" ).parents('.ui-state-error').removeClass( "ui-state-error" );280 }281 });282 283 $('input[name=addProfileButton]').click(function() {284 $('#tpl-dialog-add').dialog( "open" );285 }).prop('disabled', false).button();286 287 $('input[name=remProfileButton]').click(function() {288 $(this).parents('.ui-accordion-content').prev().remove();289 $(this).parents('.ui-accordion-content').remove();290 }).button();291 292 $('#radius-groups').parents('.ui-dialog:first').find('.loadgif').hide();293 });294 ...

Full Screen

Full Screen

flight-js-core.js

Source:flight-js-core.js Github

copy

Full Screen

1var scraperjs = require('scraperjs'),2 dateFormat = require('dateformat'),3 _ = require('lodash'),4 Promise = require('bluebird'),5 debug = require('debug')('flight-js-core');6function scrapeDate(options, modules) {7 debug('scrapeDate()');8 var promises = [],9 carrierCt = options.carrier.length,10 fOptions = _.extend({}, options, { date: new Date(options.date) });11 // scraperjs.DynamicScraper.startFactory();12 _.each(fOptions.carrier, function(name, i, col) {13 if(modules[name] == null) {14 debug('ERROR 1: Carrier "' + name + '" not found in module set; continuing');15 return;16 }17 var fModule = _.extend({}, modules[name], { carrier: name }, modules._common),18 promise = scrapeCarrier(fOptions, fModule);19 promises = _.concat(promises, promise);20 });21 // TODO rotate old output file to history folder22 // TODO write results to output file: carrier-date-from-to.csv; include timestamp and23 // other meta-data in first data row as a header24 // close phantomjs25 // scraperjs.DynamicScraper.closeFactory();26 return Promise.all(promises);27}28function scrapeCarrier(options, module) {29 debug('scrapeCarrier()');30 var promises = [];31 _.each(options.from, function(fromAirport, i, col) {32 var filterBy = _.extend({}, options, {33 from: fromAirport,34 date: dateFormat(options.date, module.dateFormat)35 });36 // Unset special values37 delete filterBy.scraper;38 // Inject values39 var fOptions = _.extend({}, module, {40 uri: filter(module.url, filterBy),41 headers: filter(module.headers, filterBy),42 form: filter(module.form, filterBy)43 });44 var promise = scraperjs.StaticScraper.create().request(fOptions)45 .scrape(module.scraper)46 .then(function(feed) {47 debug('+++ Feed from %s: %s', options.carrier, feed);48 })49 .done(function() {50 debug('+++ Done');51 })52 .timeout(5000, function() {53 debug('!!! Timed out after 5s');54 })55 .catch(function(err) {56 debug("!!! Error", err);57 });58 promises = _.concat(promises, promise);59 });60 // debug('... scrapeCarrier promises: ', promises.length);61 return Promise.all(promises);62}63// Injects a string or an array with values from baseValues, optionally overridden64// with overrideValues.65function filter(tplInput, values) {66 var out = null;67 if(tplInput == null || tplInput == '') {68 debug('... empty, returning empty string');69 return '';70 }71 if(typeof tplInput == 'string') {72 out = filterString(tplInput, values);73 }74 else {75 out = JSON.parse(filterString(JSON.stringify(tplInput), values));76 }77 // debug('filterValues()', out);78 return out;79}80function filterString(input, values) {81 var out = input;82 _.each(values, function(value, key, col) {83 out = _.replace(out, '%' + key + '%', value);84 });85 // debug('filterString()', out);86 return out;87}88module.exports = {89 scrape: scrapeDate...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { tplInput } from 'ng-mocks';2import { TestComponent } from './test.component';3describe('TestComponent', () => {4 let component: TestComponent;5 beforeEach(() => {6 component = tplInput(TestComponent, {7 data: {8 }9 });10 });11 it('should create', () => {12 expect(component).toBeTruthy();13 });14});15import { Component, Input } from '@angular/core';16@Component({17})18export class TestComponent {19 @Input() name: string;20 @Input() data: any;21}22import { async, ComponentFixture, TestBed } from '@angular/core/testing';23import { TestComponent } from './test.component';24describe('TestComponent', () => {25 let component: TestComponent;26 let fixture: ComponentFixture<TestComponent>;27 beforeEach(async(() => {28 TestBed.configureTestingModule({29 }).compileComponents();30 }));31 beforeEach(() => {32 fixture = TestBed.createComponent(TestComponent);33 component = fixture.componentInstance;34 fixture.detectChanges();35 });36 it('should create', () => {37 expect(component).toBeTruthy();38 });39});40import { async, ComponentFixture, TestBed } from '@angular/core/testing';41import { TestComponent } from './test.component';42describe('TestComponent', () => {43 let component: TestComponent;44 let fixture: ComponentFixture<TestComponent>;45 beforeEach(async(() => {46 TestBed.configureTestingModule({47 }).compileComponents();48 }));49 beforeEach(() => {50 fixture = TestBed.createComponent(TestComponent);51 component = fixture.componentInstance;52 fixture.detectChanges();53 });54 it('should create', () => {55 expect(component).toBeTruthy();56 });57});58import { async, ComponentFixture, TestBed } from '@angular/core/testing';59import { TestComponent } from './test.component';60describe('TestComponent', () => {61 let component: TestComponent;62 let fixture: ComponentFixture<TestComponent>;63 beforeEach(async(()

Full Screen

Using AI Code Generation

copy

Full Screen

1import { tplInput } from 'ng-mocks';2import { MyComponent } from './my.component';3describe('MyComponent', () => {4 it('should work', () => {5 const fixture = MockRender(MyComponent);6 const input = tplInput(fixture.debugElement, 'input');7 expect(input).toBeDefined();8 });9});10import { Component } from '@angular/core';11@Component({12})13export class MyComponent {}14import { tplInput } from 'ng-mocks';15import { MyComponent } from './my.component';16describe('MyComponent', () => {17 it('should work', () => {18 const fixture = MockRender(MyComponent);19 const input = tplInput(fixture.debugElement, 'input');20 expect(input).toBeDefined();21 });22});23import { Component } from '@angular/core';24@Component({25})26export class MyComponent {}27import { tplInput } from 'ng-mocks';28import { MyComponent } from './my.component';29describe('MyComponent', () => {30 it('should work', () => {31 const fixture = MockRender(MyComponent);32 const input = tplInput(fixture.debugElement, 'input');33 expect(input).toBeDefined();34 });35});36import { Component } from '@angular/core';37@Component({38})39export class MyComponent {}40import { tplInput } from 'ng-mocks';41import { MyComponent } from './my.component';42describe('MyComponent', () => {43 it('should work', () => {44 const fixture = MockRender(MyComponent);45 const input = tplInput(fixture.debug

Full Screen

Using AI Code Generation

copy

Full Screen

1import { tplInput } from 'ng-mocks';2import { MyComponent } from './my.component';3describe('MyComponent', () => {4 it('should render', () => {5 const fixture = MockRender(MyComponent);6 const component = fixture.point.componentInstance;7 const input = tplInput(fixture.debugElement, 'input');8 expect(input).toBeDefined();9 expect(input.nativeElement.value).toEqual('test');10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { tplInput } from 'ng-mocks';2@Component({3 template: '<input type="text" [(ngModel)]="test" />',4})5export class TestComponent {6 public test: string;7}8describe('TestComponent', () => {9 let component: TestComponent;10 let fixture: ComponentFixture<TestComponent>;11 beforeEach(async(() => {12 TestBed.configureTestingModule({13 }).compileComponents();14 }));15 beforeEach(() => {16 fixture = TestBed.createComponent(TestComponent);17 component = fixture.componentInstance;18 fixture.detectChanges();19 });20 it('should create', () => {21 expect(component).toBeTruthy();22 });23 it('should have test value', () => {24 tplInput(fixture.debugElement, 'test', 'test value');25 expect(component.test).toEqual('test value');26 });27});28import { tplInput } from 'ng-mocks';29@Component({30 template: '<input type="text" [(ngModel)]="test" />',31})32export class TestComponent {33 public test: string;34}35describe('TestComponent', () => {36 let component: TestComponent;37 let fixture: ComponentFixture<TestComponent>;38 beforeEach(async(() => {39 TestBed.configureTestingModule({40 }).compileComponents();41 }));42 beforeEach(() => {43 fixture = TestBed.createComponent(TestComponent);44 component = fixture.componentInstance;45 fixture.detectChanges();46 });47 it('should create', () => {48 expect(component).toBeTruthy();49 });50 it('should have test value', () => {51 tplInput(fixture.debugElement, 'test', 'test value');52 expect(component.test).toEqual('test value');53 });54});55import { Component } from '@angular/core';56@Component({57 template: '<input type="text" [(ngModel)]="test" />',58})59export class TestComponent {60 public test: string;61}62import { ComponentFixture, TestBed, async } from '@angular/core/testing';63import { TestComponent } from './test.component';64import { tplInput } from 'ng-mocks';65describe('Test

Full Screen

Using AI Code Generation

copy

Full Screen

1import { tplInput } from 'ng-mocks';2const input = tplInput({3 template: '<input type="text" [(ngModel)]="name" />',4 context: {5 },6});7input.nativeElement.value = 'Johnny';8input.triggerEventHandler('input', {9});10import { tplInput } from 'ng-mocks';11const input = tplInput({12 template: '<input type="text" [(ngModel)]="name" />',13 context: {14 },15});16input.nativeElement.value = 'Johnny';17input.triggerEventHandler('input', {18});19import { tplInput } from 'ng-mocks';20const input = tplInput({21 template: '<input type="text" [(ngModel)]="name" />',22 context: {23 },24});25input.nativeElement.value = 'Johnny';26input.triggerEventHandler('input', {27});28import { tplInput } from 'ng-mocks';29const input = tplInput({30 template: '<input type="text" [(ngModel)]="name" />',31 context: {32 },33});34input.nativeElement.value = 'Johnny';35input.triggerEventHandler('input', {36});37import { tplInput } from 'ng-mocks';38const input = tplInput({39 template: '<input type="text" [(ngModel)]="name" />',40 context: {41 },42});43input.nativeElement.value = 'Johnny';44input.triggerEventHandler('input', {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { tplInput } from 'ng-mocks';2const component = tplInput({ selector: 'input', value: 'test' });3expect(component.value).toEqual('test');4import { tplInput } from 'ng-mocks';5const component = tplInput({ selector: 'input', value: 'test' });6expect(component.value).toEqual('test');7import { tplInput } from 'ng-mocks';8const component = tplInput({ selector: 'input', value: 'test' });9expect(component.value).toEqual('test');10import { tplInput } from 'ng-mocks';11const component = tplInput({ selector: 'input', value: 'test' });12expect(component.value).toEqual('test');13import { tplInput } from 'ng-mocks';14const component = tplInput({ selector: 'input', value: 'test' });15expect(component.value).toEqual('test');16import { tplInput } from 'ng-mocks';17const component = tplInput({ selector: 'input', value: 'test' });18expect(component.value).toEqual('test');19import { tplInput } from 'ng-mocks';20const component = tplInput({ selector: 'input', value: 'test' });21expect(component.value).toEqual('test');22import { tplInput } from 'ng-mocks';23const component = tplInput({ selector: 'input', value: 'test' });24expect(component.value).toEqual('test');25import { tplInput } from 'ng-mocks';26const component = tplInput({ selector: 'input', value: 'test' });27expect(component.value).toEqual('test');28import { tplInput } from 'ng-mocks';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { tplInput } from 'ng-mocks';2const fixture = MockRender(`3`);4tplInput(fixture, 'app-comp', 'input', 'value');5const input = tplInput(fixture, 'app-comp', 'input');6expect(input).toEqual('value');7import { tplOutput } from 'ng-mocks';8const fixture = MockRender(`9 <app-comp (output)="onOutput($event)"></app-comp>10`);11tplOutput(fixture, 'app-comp', 'output', 'value');12const output = tplOutput(fixture, 'app-comp', 'output');13expect(output).toEqual('value');14import { tplChange } from 'ng-mocks';15const fixture = MockRender(`16`);17tplChange(fixture, 'app-comp', 'input', 'value');18const input = tplChange(fixture, 'app-comp', 'input');19expect(input).toEqual('value');20import { tplClick } from 'ng-mocks';21const fixture = MockRender(`22 <app-comp (click)="onClick($event)"></app-comp>23`);24tplClick(fixture, 'app-comp');25const click = tplClick(fixture, 'app-comp');26expect(click).toEqual('value');27import { tplBlur } from 'ng-mocks';28const fixture = MockRender(`29 <app-comp (blur)="onBlur($event)"></app-comp>30`);31tplBlur(fixture, 'app-comp');32const blur = tplBlur(fixture, 'app-comp');33expect(blur).toEqual('value');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { tplInput } from 'ng-mocks';2const input = tplInput(fixture, 'input');3const input = tplInput(fixture, 'input', 0);4const input = tplInput(fixture, 'input', 1);5const input = tplInput(fixture, 'input', 2);6const input = tplInput(fixture, 'input', 3);7const input = tplInput(fixture, 'input', 4);8const input = tplInput(fixture, 'input', 5);9const input = tplInput(fixture, 'input', 6);10const input = tplInput(fixture, 'input', 7);11const input = tplInput(fixture, 'input', 8);12const input = tplInput(fixture, 'input', 9);13const input = tplInput(fixture, 'input', 10);14const input = tplInput(fixture, 'input

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ng-mocks automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful