Best JavaScript code snippet using wpt
EditRealmView.js
Source:EditRealmView.js
1/**2 * The contents of this file are subject to the terms of the Common Development and3 * Distribution License (the License). You may not use this file except in compliance with the4 * License.5 *6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the7 * specific language governing permission and limitations under the License.8 *9 * When distributing Covered Software, include this CDDL Header Notice in each file and include10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL11 * Header, with the fields enclosed by brackets [] replaced by your own identifying12 * information: "Portions copyright [year] [name of copyright owner]".13 *14 * Copyright 2016 ForgeRock AS.15 */16define([17 "jquery",18 "lodash",19 "handlebars",20 "org/forgerock/commons/ui/common/components/Messages",21 "org/forgerock/commons/ui/common/main/AbstractView",22 "org/forgerock/commons/ui/common/main/EventManager",23 "org/forgerock/commons/ui/common/main/Router",24 "org/forgerock/commons/ui/common/util/Constants",25 "org/forgerock/openam/ui/admin/services/global/RealmsService",26 "org/forgerock/openam/ui/admin/services/global/AuthenticationService",27 "org/forgerock/openam/ui/admin/services/realm/AuthenticationService",28 "org/forgerock/openam/ui/admin/utils/FormHelper",29 "org/forgerock/openam/ui/admin/views/common/Backlink",30 "org/forgerock/openam/ui/common/models/JSONSchema",31 "org/forgerock/openam/ui/common/models/JSONValues",32 "org/forgerock/openam/ui/common/views/jsonSchema/FlatJSONSchemaView",33 "org/forgerock/openam/ui/common/util/Promise",34 "bootstrap-tabdrop",35 "popoverclickaway",36 "selectize"37], ($, _, Handlebars, Messages, AbstractView, EventManager, Router, Constants, RealmsService,38 GlobalAuthenticationService, RealmAuthenticationService, FormHelper, Backlink, JSONSchema, JSONValues,39 FlatJSONSchemaView, Promise) => {40 function setAutofocus () {41 $("input[type=\"text\"]:not(:disabled):first").prop("autofocus", true);42 }43 function checkPattern (string) {44 // "Characters $, &, +, \, ", comma, /, :, ;, =, ?, @, space, #, %, <, > are not allowed in a realm's name."45 const specialChars = " @#$%&+?:;,/=\\<>\"";46 for (let i = 0; i < specialChars.length; i++) {47 if (string.indexOf(specialChars[i]) > -1) {48 return true;49 }50 }51 return false;52 }53 function isTopLevelRealm (name) {54 return name === "/";55 }56 function validateRealmName () {57 let valid = false;58 const realmName = $("input[name=\"root[name]\"]").val();59 let alert = "";60 if (realmName.length > 0) {61 if (checkPattern(realmName)) {62 alert = Handlebars.compile("{{> alerts/_Alert type='warning' " +63 "text='console.realms.realmNameValidationError'}}");64 } else {65 valid = true;66 }67 }68 $("[data-realm-alert]").html(alert);69 return valid;70 }71 const EditRealmView = AbstractView.extend({72 template: "templates/admin/views/realms/EditRealmTemplate.html",73 partials: [74 "partials/alerts/_Alert.html"75 ],76 events: {77 "click [data-save]": "handleSave",78 "click [data-cancel]": "returnBack",79 "click [data-delete]": "onDeleteClick",80 "keyup input[name=\"root[name]\"]": "onDataChange",81 "change input[name=\"root[name]\"]": "onDataChange"82 },83 render (args) {84 let realmPromise;85 let authenticationPromise;86 this.realmPath = args[0];87 if (args[0]) {88 this.data.realmPath = args[0];89 this.data.realmName = args[0] === "/" ? $.t("console.common.topLevelRealm") : args[0].split("/").pop();90 this.data.newEntity = false;91 this.data.headerActions = [{92 actionPartial: "form/_Button",93 data:"delete",94 title:"common.form.delete",95 icon:"fa-times",96 disabled: !this.canRealmBeDeleted(this.data.realmPath)97 }];98 } else {99 this.data.newEntity = true;100 this.data.headerActions = null;101 }102 if (this.data.newEntity) {103 realmPromise = RealmsService.realms.schema();104 authenticationPromise = GlobalAuthenticationService.authentication.schema();105 } else {106 realmPromise = RealmsService.realms.get(this.data.realmPath);107 authenticationPromise = RealmAuthenticationService.authentication.get(this.data.realmPath);108 }109 this.parentRender(function () {110 Promise.all([realmPromise, RealmsService.realms.all(), authenticationPromise]).then((response) => {111 const data = response[0];112 const allRealmPaths = _.map(response[1][0].result, "path");113 if (this.data.newEntity) {114 // Only create dropdowns if the field is editable115 data.schema.properties.parentPath["enum"] = allRealmPaths;116 data.schema.properties.parentPath.options = { "enum_titles": allRealmPaths };117 data.schema.properties.name.pattern = "^[^ @#$%&+?:;,/=\\<>\"]+$";118 } else {119 // Once created, it should not be possible to edit a realm's name or who it's parent is.120 data.schema.properties.name.readonly = true;121 data.schema.properties.parentPath.readonly = true;122 if (isTopLevelRealm(data.values.name)) {123 data.schema.properties.active.readonly = true;124 }125 this.toggleSubmitButton(true);126 }127 const generalPropertyPath = this.data.newEntity ? "schema.properties.defaults.properties.general"128 : "schema.properties.general";129 this.subviews = [130 new FlatJSONSchemaView({131 schema: new JSONSchema(data.schema),132 values: new JSONValues(data.values)133 }),134 new FlatJSONSchemaView({135 schema: new JSONSchema(_.get(response[2], generalPropertyPath))136 .addDefaultProperties(["statelessSessionsEnabled"]),137 values: new JSONValues(_.get(response[2], "values.general"))138 })139 ];140 this.subviews[0].render().$el.appendTo(this.$el.find("[data-realm-form]"));141 // Turn off inline error messages as we display our own help on errors on this page142 this.subviews[0].subview.jsonEditor.options["show_errors"] = "never";143 this.subviews[1].render().$el.appendTo(this.$el.find("[data-realm-stateless-session-form]"));144 new Backlink().render(0);145 setAutofocus();146 }, (response) => {147 Messages.addMessage({ type: Messages.TYPE_DANGER, response });148 });149 });150 },151 returnBack () {152 if (this.data.newEntity) {153 Router.routeTo(Router.configuration.routes.realms, { args: [], trigger: true });154 } else {155 Router.routeTo(Router.configuration.routes.realmDefault, {156 args: [encodeURIComponent(this.data.realmPath)],157 trigger: true158 });159 }160 },161 onDataChange () {162 this.toggleSubmitButton(validateRealmName());163 },164 handleSave (event) {165 event.preventDefault();166 this.toggleSubmitButton(false);167 const failCallback = (response) => { Messages.addMessage({ type: Messages.TYPE_DANGER, response }); };168 const values = this.subviews[0].getData();169 const statelessSessionsValues = this.subviews[1].getData();170 const savePromise = this.data.newEntity ? RealmsService.realms.create(values)171 : RealmsService.realms.update(values);172 savePromise.then((realm) => {173 const isRootRealm = realm.name === "/";174 const hasRootRealmAsParent = realm.parentPath === "/";175 let realmPath;176 if (isRootRealm) {177 realmPath = "/";178 } else if (hasRootRealmAsParent) {179 realmPath = `/${realm.name}`;180 } else {181 realmPath = `${realm.parentPath}/${realm.name}`;182 }183 RealmAuthenticationService.authentication.update(realmPath, statelessSessionsValues).then(() => {184 if (this.data.newEntity) {185 this.data.newEntity = false;186 Router.routeTo(Router.configuration.routes.realmDefault, {187 args: [encodeURIComponent(realmPath)],188 trigger: true189 });190 } else {191 EventManager.sendEvent(Constants.EVENT_DISPLAY_MESSAGE_REQUEST, "changesSaved");192 }193 }, failCallback);194 }, failCallback).always(() => {195 this.toggleSubmitButton(true);196 });197 },198 onDeleteClick (event) {199 event.preventDefault();200 FormHelper.showConfirmationBeforeDeleting({ type: $.t("console.realms.edit.realm") },201 _.bind(this.deleteRealm, this));202 },203 deleteRealm () {204 RealmsService.realms.remove(this.realmPath).then(() => {205 Router.routeTo(Router.configuration.routes.realms, { args: [], trigger: true });206 EventManager.sendEvent(Constants.EVENT_DISPLAY_MESSAGE_REQUEST, "changesSaved");207 }, (response) => {208 if (response && response.status === 409) {209 Messages.addMessage({210 message: $.t("console.realms.parentRealmCannotDeleted"),211 type: Messages.TYPE_DANGER212 });213 } else {214 Messages.addMessage({ response, type: Messages.TYPE_DANGER });215 }216 });217 },218 canRealmBeDeleted (realmPath) {219 return realmPath === "/" ? false : true;220 },221 toggleSubmitButton (flag) {222 this.$el.find("[data-save]").prop("disabled", !flag);223 }224 });225 return new EditRealmView();...
DashboardView.js
Source:DashboardView.js
1/**2 * The contents of this file are subject to the terms of the Common Development and3 * Distribution License (the License). You may not use this file except in compliance with the4 * License.5 *6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the7 * specific language governing permission and limitations under the License.8 *9 * When distributing Covered Software, include this CDDL Header Notice in each file and include10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL11 * Header, with the fields enclosed by brackets [] replaced by your own identifying12 * information: "Portions copyright [year] [name of copyright owner]".13 *14 * Copyright 2015 ForgeRock AS.15 */16define("org/forgerock/openam/ui/admin/views/realms/dashboard/DashboardView", [17 "jquery",18 "underscore",19 "org/forgerock/commons/ui/common/main/AbstractView",20 "org/forgerock/openam/ui/admin/views/realms/CreateUpdateRealmDialog",21 "org/forgerock/openam/ui/admin/views/realms/dashboard/DashboardTasksView",22 "org/forgerock/commons/ui/common/components/Messages",23 "org/forgerock/openam/ui/admin/delegates/SMSGlobalDelegate",24 "org/forgerock/openam/ui/admin/delegates/SMSRealmDelegate"25], function ($, _, AbstractView, CreateUpdateRealmDialog, DashboardTasksView, Messages, SMSGlobalDelegate,26 SMSRealmDelegate) {27 var DashboardView = AbstractView.extend({28 template: "templates/admin/views/realms/dashboard/DashboardTemplate.html",29 events: {30 "click #editProperties" : "editProperties"31 },32 editProperties: function (event) {33 event.preventDefault();34 var self = this;35 CreateUpdateRealmDialog.show({36 realmPath : this.data.realmPath,37 callback : function () {38 self.render([self.data.realmPath]);39 }40 });41 },42 render: function (args, callback) {43 var self = this,44 realmPromise = SMSGlobalDelegate.realms.get(args[0]),45 tasksPromise = SMSRealmDelegate.dashboard.commonTasks.all(args[0]);46 this.data.realmPath = args[0];47 $.when(realmPromise, tasksPromise).then(function (realmData, tasksData) {48 self.data.realm = {49 status: realmData.values.active ? $.t("common.form.active") : $.t("common.form.inactive"),50 active: realmData.values.active,51 aliases: realmData.values.aliases52 };53 self.parentRender(function () {54 var dashboardTasks = new DashboardTasksView();55 dashboardTasks.data.allTasks = tasksData[0].result;56 dashboardTasks.data.taskGroup = { tasks: tasksData[0].result };57 dashboardTasks.render(args, callback);58 }, callback);59 }, function (errorRealm, errorTasks) {60 Messages.addMessage({61 type: Messages.TYPE_DANGER,62 response: errorRealm ? errorRealm : errorTasks63 });64 });65 }66 });67 return DashboardView;...
Using AI Code Generation
1const wptoolbox = require('wptoolbox');2const path = require('path');3const realmPromise = wptoolbox.realmPromise;4realmPromise(path.join(__dirname, 'test.realm')).then((realm) => {5 console.log(realm);6}).catch((err) => {7 console.log(err);8});
Using AI Code Generation
1var wptoolbox = require('wptoolbox');2realmPromise.then(function(realm) {3 console.log(realm);4});5var wptoolbox = require('wptoolbox');6 console.log(realm);7});8var wptoolbox = require('wptoolbox');9realmPromise.then(function(realm) {10 console.log(realm);11});12var wptoolbox = require('wptoolbox');13 console.log(realm);14});15var wptoolbox = require('wptoolbox');16realmPromise.then(function(realm) {17 console.log(realm);18});19var wptoolbox = require('wptoolbox');20 console.log(realm);21});22var wptoolbox = require('wptoolbox');23realmPromise.then(function(realm) {24 console.log(realm);25});26var wptoolbox = require('wptoolbox');27 console.log(realm);28});29var wptoolbox = require('wptoolbox');
Using AI Code Generation
1var wptools = require('wptools');2var realmPromise = wptools.realmPromise;3var realm = realmPromise('Barack Obama');4realm.then(function(realm) {5 console.log(realm);6});7var wptools = require('wptools');8var realm = wptools.realm('Barack Obama');9console.log(realm);10var wptools = require('wptools');11var realmPromise = wptools.realmPromise;12var realm = realmPromise('Barack Obama');13realm.then(function(realm) {14 console.log(realm);15});16var wptools = require('wptools');17var realm = wptools.realm('Barack Obama');18console.log(realm);19var wptools = require('wptools');20var realmPromise = wptools.realmPromise;21var realm = realmPromise('Barack Obama');22realm.then(function(realm) {23 console.log(realm);24});25var wptools = require('wptools');26var realm = wptools.realm('Barack Obama');27console.log(realm);28var wptools = require('wptools');29var realmPromise = wptools.realmPromise;30var realm = realmPromise('Barack Obama');31realm.then(function(realm) {32 console.log(realm);33});34var wptools = require('wptools');35var realm = wptools.realm('Barack Obama');36console.log(realm);37var wptools = require('wptools');38var realmPromise = wptools.realmPromise;39var realm = realmPromise('Barack Obama');40realm.then(function(realm) {41 console.log(realm);42});43var wptools = require('wptools');44var realm = wptools.realm('Barack Obama');45console.log(realm);
Using AI Code Generation
1var wpt = require("./wpt.js");2wpt.realmPromise(testUrl)3.then(function(result) {4 console.log(result);5})6.catch(function(err) {7 console.log(err);8});9var request = require('request');10var wpt = require('webpagetest');11var wptPromise = require('webpagetest-promise');12var wpt = new wptPromise('www.webpagetest.org');13var realmPromise = function(url) {14 return new Promise(function(resolve, reject) {15 wpt.runTest(url, {16 })17 .then(function(result) {18 var testId = result.data.testId;19 wpt.getTestResults(testId)20 .then(function(result) {21 resolve(result.data.average.firstView);22 })23 .catch(function(err) {24 reject(err);25 });26 })27 .catch(function(err) {28 reject(err);29 });30 });31};32module.exports = {33};34{ TTFB: 425,
Using AI Code Generation
1var wptools = require('wptools');2wptools.realm('en.wikipedia.org', function (err, realm) {3 console.log(realm);4});5### `wptools.realm(domain, callback)`6### `wptools.realmPromise(domain)`7### `wptools.page(domain, title, callback)`8### `wptools.pagePromise(domain, title)`9### `wptools.pageid(domain, pageid, callback)`10### `wptools.pageidPromise(domain, pageid)`11### `wptools.revisions(domain, title, callback)`
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2wptoolkit.realmPromise('test').then(function(realm){3 console.log('realm', realm);4});5var wptoolkit = require('wptoolkit');6wptoolkit.realm('test', function(realm){7 console.log('realm', realm);8});9var wptoolkit = require('wptoolkit');10var realm = wptoolkit.realm('test');11console.log('realm', realm);12var wptoolkit = require('wptoolkit');13var realm = wptoolkit.realm();14console.log('realm', realm);15var wptoolkit = require('wptoolkit');16var realm = wptoolkit.realm('test', function(realm){17 console.log('realm', realm);18});19var wptoolkit = require('wptoolkit');20var realm = wptoolkit.realm('test', function(realm){21 console.log('realm', realm);22}).then(function(realm){23 console.log('realm', realm);24});25var wptoolkit = require('wptoolkit');26var realm = wptoolkit.realm('test', function(error, realm){27 console.log('realm', realm);28});29var wptoolkit = require('wptoolkit');30var realm = wptoolkit.realm('test', function(error, realm){31 console.log('realm', realm);32}).then(function(realm){
Using AI Code Generation
1const realmPromise = require('wptoolkit').realmPromise;2const realmPromise = require('wptoolkit').realmPromise;3realmPromise(realm => {4})5realmPromise(realm => {6})7realmPromise(realm => {8})9realmPromise(realm => {10})11realmPromise(realm => {12})13realmPromise(realm => {14})15realmPromise(realm => {16})17realmPromise(realm => {18})19realmPromise(realm => {20})21realmPromise(realm => {22})23realmPromise(realm => {
Using AI Code Generation
1var wptools = require('wptools');2var realmPromise = wptools.realmPromise;3var realm = wptools.realm;4realmPromise('United States').then(function(result) {5 console.log(result);6});7realm('United States', function(result) {8 console.log(result);9});10realm('United States', {debug: true}, function(result) {11 console.log(result);12});13realm('United States', {debug: true, lang: 'fr'}, function(result) {14 console.log(result);15});16realm('United States', {debug: true, lang: 'fr', format: 'json'}, function(result) {17 console.log(result);18});19realm('United States', {debug: true, lang: 'fr', format: 'xml'}, function(result) {20 console.log(result);21});22 console.log(result);23});24 console.log(result);25});26 console.log(result);27});28 console.log(result);29});30 console.log(result);31});32realm('United States', {debug: true, lang: 'fr', format: '
Using AI Code Generation
1var realmPromise = wpt.realmPromise;2realmPromise.then(function(realm) {3 var obj = realm.eval('new Object()');4 obj.foo = 'bar';5 console.log(obj.foo);6});73. Inspect the results in Firefox (the test fails) and in Chrome (the test passes)
Using AI Code Generation
1const wptApi = require("wpt-api");2realm.then(function (data) {3 console.log(data);4});5const wptApi = require("wpt-api");6 console.log(data);7});8const wptApi = require("wpt-api");9 console.log(data);10});11const wptApi = require("wpt-api");12 console.log(data);13});14const wptApi = require("wpt-api");15 console.log(data);16});17const wptApi = require("wpt-api");18 console.log(data);19});20const wptApi = require("wpt-api");21 console.log(data);22});23const wptApi = require("wpt-api");24 console.log(data);25});26const wptApi = require("wpt-api");27 console.log(data);28});
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.
Get 100 minutes of automation test minutes FREE!!