Best JavaScript code snippet using wpt
dashboard.js
Source:dashboard.js
1odoo.define('web_settings_dashboard', function (require) {2"use strict";3var core = require('web.core');4var framework = require('web.framework');5var Widget = require('web.Widget');6var QWeb = core.qweb;7var _t = core._t;8var Dashboard = Widget.extend({9 template: 'DashboardMain',10 init: function(){11 this.all_dashboards = ['apps', 'invitations', 'share', 'translations', 'company'];12 return this._super.apply(this, arguments);13 },14 start: function(){15 return this.load(this.all_dashboards);16 },17 load: function(dashboards){18 var self = this;19 var loading_done = new $.Deferred();20 this._rpc({route: '/web_settings_dashboard/data'})21 .then(function (data) {22 // Load each dashboard23 var all_dashboards_defs = [];24 _.each(dashboards, function(dashboard) {25 var dashboard_def = self['load_' + dashboard](data);26 if (dashboard_def) {27 all_dashboards_defs.push(dashboard_def);28 }29 });30 // Resolve loading_done when all dashboards defs are resolved31 $.when.apply($, all_dashboards_defs).then(function() {32 loading_done.resolve();33 });34 });35 return loading_done;36 },37 load_apps: function(data){38 return new DashboardApps(this, data.apps).replace(this.$('.o_web_settings_dashboard_apps'));39 },40 load_share: function(data){41 return new DashboardShare(this, data.share).replace(this.$('.o_web_settings_dashboard_share'));42 },43 load_invitations: function(data){44 return new DashboardInvitations(this, data.users_info).replace(this.$('.o_web_settings_dashboard_invitations'));45 },46 load_translations: function (data) {47 return new DashboardTranslations(this, data.translations).replace(this.$('.o_web_settings_dashboard_translations'));48 },49 load_company: function (data) {50 return new DashboardCompany(this, data.company).replace(this.$('.o_web_settings_dashboard_company'));51 }52});53var DashboardInvitations = Widget.extend({54 template: 'DashboardInvitations',55 events: {56 'click .o_web_settings_dashboard_invitations': 'send_invitations',57 'click .o_web_settings_dashboard_access_rights': 'on_access_rights_clicked',58 'click .o_web_settings_dashboard_user': 'on_user_clicked',59 'click .o_web_settings_dashboard_more': 'on_more',60 },61 init: function(parent, data){62 this.data = data;63 this.parent = parent;64 return this._super.apply(this, arguments);65 },66 send_invitations: function(e){67 var self = this;68 var $target = $(e.currentTarget);69 var user_emails = _.filter($(e.delegateTarget).find('#user_emails').val().split(/[\n, ]/), function(email){70 return email !== "";71 });72 var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,63}(?:\.[a-z]{2})?)$/i;73 var is_valid_emails = _.every(user_emails, function(email) {74 return re.test(email);75 });76 if (is_valid_emails) {77 // Disable button78 $target.prop('disabled', true);79 $target.find('i.fa-cog').removeClass('hidden');80 // Try to create user accountst81 this._rpc({82 model: 'res.users',83 method: 'web_dashboard_create_users',84 args: [user_emails],85 })86 .then(function() {87 self.reload();88 })89 .always(function() {90 // Re-enable button91 $(e.delegateTarget).find('.o_web_settings_dashboard_invitations').prop('disabled', false);92 $(e.delegateTarget).find('i.fa-cog').addClass('hidden');93 });94 }95 else {96 this.do_warn(_t("Please provide valid email addresses"), "");97 }98 },99 on_access_rights_clicked: function (e) {100 var self = this;101 e.preventDefault();102 this.do_action('base.action_res_users', {103 on_reverse_breadcrumb: function(){ return self.reload();}104 });105 },106 on_user_clicked: function (e) {107 var self = this;108 e.preventDefault();109 var user_id = $(e.currentTarget).data('user-id');110 var action = {111 type: 'ir.actions.act_window',112 view_type: 'form',113 view_mode: 'form',114 res_model: 'res.users',115 views: [[this.data.user_form_view_id, 'form']],116 res_id: user_id,117 };118 this.do_action(action,{119 on_reverse_breadcrumb: function(){ return self.reload();}120 });121 },122 on_more: function(e) {123 var self = this;124 e.preventDefault();125 var action = {126 type: 'ir.actions.act_window',127 view_type: 'form',128 view_mode: 'tree,form',129 res_model: 'res.users',130 domain: [['log_ids', '=', false]],131 views: [[false, 'list'], [false, 'form']],132 };133 this.do_action(action,{134 on_reverse_breadcrumb: function(){ return self.reload();}135 });136 },137 reload:function(){138 return this.parent.load(['invitations']);139 },140});141var DashboardApps = Widget.extend({142 template: 'DashboardApps',143 events: {144 'click .o_browse_apps': 'on_new_apps',145 'click .o_confirm_upgrade': 'confirm_upgrade',146 },147 init: function(parent, data){148 this.data = data;149 this.parent = parent;150 return this._super.apply(this, arguments);151 },152 start: function() {153 this._super.apply(this, arguments);154 if (odoo.db_info && _.last(odoo.db_info.server_version_info) !== 'e') {155 $(QWeb.render("DashboardEnterprise")).appendTo(this.$el);156 }157 },158 on_new_apps: function(){159 this.do_action('base.open_module_tree');160 },161 confirm_upgrade: function() {162 framework.redirect("https://www.odoo.com/odoo-enterprise/upgrade?num_users=" + (this.data.enterprise_users || 1));163 },164});165var DashboardShare = Widget.extend({166 template: 'DashboardShare',167 events: {168 'click .tw_share': 'share_twitter',169 'click .fb_share': 'share_facebook',170 'click .li_share': 'share_linkedin',171 },172 init: function(parent, data){173 this.data = data;174 this.parent = parent;175 this.share_url = 'https://www.odoo.com';176 this.share_text = encodeURIComponent("I am using #Odoo - Awesome open source business apps.");177 },178 share_twitter: function(){179 var popup_url = _.str.sprintf( 'https://twitter.com/intent/tweet?tw_p=tweetbutton&text=%s %s',this.share_text,this.share_url);180 this.sharer(popup_url);181 },182 share_facebook: function(){183 var popup_url = _.str.sprintf('https://www.facebook.com/sharer/sharer.php?u=%s', encodeURIComponent(this.share_url));184 this.sharer(popup_url);185 },186 share_linkedin: function(){187 var popup_url = _.str.sprintf('http://www.linkedin.com/shareArticle?mini=true&url=%s&title=I am using odoo&summary=%s&source=www.odoo.com', encodeURIComponent(this.share_url), this.share_text);188 this.sharer(popup_url);189 },190 sharer: function(popup_url){191 window.open(192 popup_url,193 'Share Dialog',194 'width=600,height=400'); // We have to add a size otherwise the window pops in a new tab195 }196});197var DashboardTranslations = Widget.extend({198 template: 'DashboardTranslations',199 events: {200 'click .o_load_translations': 'on_load_translations'201 },202 on_load_translations: function () {203 this.do_action('base.action_view_base_language_install');204 }205});206var DashboardCompany = Widget.extend({207 template: 'DashboardCompany',208 events: {209 'click .o_setup_company': 'on_setup_company'210 },211 init: function (parent, data) {212 this.data = data;213 this.parent = parent;214 this._super.apply(this, arguments);215 },216 on_setup_company: function () {217 var self = this;218 var action = {219 type: 'ir.actions.act_window',220 res_model: 'res.company',221 view_mode: 'form',222 view_type: 'form',223 views: [[false, 'form']],224 res_id: this.data.company_id225 };226 this.do_action(action, {227 on_reverse_breadcrumb: function () { return self.reload(); }228 });229 },230 reload: function () {231 return this.parent.load(['company']);232 }233});234core.action_registry.add('web_settings_dashboard.main', Dashboard);235return {236 Dashboard: Dashboard,237 DashboardApps: DashboardApps,238 DashboardInvitations: DashboardInvitations,239 DashboardShare: DashboardShare,240 DashboardTranslations: DashboardTranslations,241 DashboardCompany: DashboardCompany242};...
browser_dbg-breakpoints-popup.js
Source:browser_dbg-breakpoints-popup.js
1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */4// Verify that we hit breakpoints on popups5"use strict";6const TEST_URI = "https://example.org/document-builder.sjs?html=main page";7const POPUP_URL = `https://example.com/document-builder.sjs?html=${escape(`popup for breakpoints8 <script>9 var paused = true;10 console.log('popup');11 paused = false;12 </script>13`)}`;14const POPUP_DEBUGGER_STATEMENT_URL = `https://example.com/document-builder.sjs?html=${escape(`popup with debugger;15 <script>16 var paused = true;17 debugger;18 paused = false;19 </script>20`)}`;21function isPopupPaused(popupBrowsingContext) {22 return SpecialPowers.spawn(popupBrowsingContext, [], function(url) {23 return content.wrappedJSObject.paused;24 });25}26async function openPopup(popupUrl, browser = gBrowser.selectedBrowser) {27 const onPopupTabSelected = BrowserTestUtils.waitForEvent(28 gBrowser.tabContainer,29 "TabSelect"30 );31 const popupBrowsingContext = await SpecialPowers.spawn(32 browser,33 [popupUrl],34 function(url) {35 const popup = content.open(url);36 return popup.browsingContext;37 }38 );39 await onPopupTabSelected;40 is(41 gBrowser.selectedBrowser.browsingContext,42 popupBrowsingContext,43 "The popup is the selected tab"44 );45 return popupBrowsingContext;46}47async function closePopup(browsingContext) {48 const onPreviousTabSelected = BrowserTestUtils.waitForEvent(49 gBrowser.tabContainer,50 "TabSelect"51 );52 await SpecialPowers.spawn(browsingContext, [], function() {53 content.close();54 });55 await onPreviousTabSelected;56}57add_task(async function testPausedByBreakpoint() {58 await pushPref("devtools.popups.debug", true);59 info("Test breakpoints set in popup scripts");60 const dbg = await initDebuggerWithAbsoluteURL(TEST_URI);61 info("Open the popup in order to be able to set a breakpoint");62 const firstPopupBrowsingContext = await openPopup(POPUP_URL);63 await waitForSource(dbg, POPUP_URL);64 const source = findSource(dbg, POPUP_URL);65 await selectSource(dbg, source);66 await addBreakpoint(dbg, source, 4);67 info("Now close and reopen the popup");68 await closePopup(firstPopupBrowsingContext);69 info("Re-open the popup");70 const popupBrowsingContext = await openPopup(POPUP_URL);71 await waitForPaused(dbg);72 is(73 await isPopupPaused(popupBrowsingContext),74 true,75 "The popup is really paused"76 );77 await waitForSource(dbg, POPUP_URL);78 const newSource = findSource(dbg, POPUP_URL);79 isnot(80 source,81 newSource,82 "The second one is related to the new popup and is different"83 );84 isnot(source.id, newSource.id, "The source IDs are different");85 assertPausedAtSourceAndLine(dbg, newSource.id, 4);86 await resume(dbg);87 is(88 await isPopupPaused(popupBrowsingContext),89 false,90 "The popup resumed its execution"91 );92});93add_task(async function testPausedByDebuggerStatement() {94 info("Test debugger statements in popup scripts");95 const dbg = await initDebuggerWithAbsoluteURL(TEST_URI);96 info("Open a popup with a debugger statement");97 const popupBrowsingContext = await openPopup(POPUP_DEBUGGER_STATEMENT_URL);98 await waitForPaused(dbg);99 is(100 await isPopupPaused(popupBrowsingContext),101 true,102 "The popup is really paused"103 );104 const source = findSource(dbg, POPUP_DEBUGGER_STATEMENT_URL);105 assertPausedAtSourceAndLine(dbg, source.id, 4);106 await resume(dbg);107 is(108 await isPopupPaused(popupBrowsingContext),109 false,110 "The popup resumed its execution"111 );112});113add_task(async function testPausedInTwoPopups() {114 info("Test being paused in two popup at the same time");115 const dbg = await initDebuggerWithAbsoluteURL(TEST_URI);116 info("Open the popup in order to be able to set a breakpoint");117 const browser = gBrowser.selectedBrowser;118 const popupBrowsingContext = await openPopup(POPUP_URL);119 await waitForSource(dbg, POPUP_URL);120 const source = findSource(dbg, POPUP_URL);121 await selectSource(dbg, source);122 await addBreakpoint(dbg, source, 4);123 info("Now close and reopen the popup");124 await closePopup(popupBrowsingContext);125 info("Open a first popup which will hit the breakpoint");126 const firstPopupBrowsingContext = await openPopup(POPUP_URL);127 await waitForPaused(dbg);128 const { targetCommand } = dbg.commands;129 const firstTarget = targetCommand130 .getAllTargets([targetCommand.TYPES.FRAME])131 .find(targetFront => targetFront.url == POPUP_URL);132 is(133 firstTarget.browsingContextID,134 firstPopupBrowsingContext.id,135 "The popup target matches the popup BrowsingContext"136 );137 const firstThread = (await firstTarget.getFront("thread")).actorID;138 is(139 dbg.selectors.getCurrentThread(),140 firstThread,141 "The popup thread is automatically selected on pause"142 );143 is(144 await isPopupPaused(firstPopupBrowsingContext),145 true,146 "The first popup is really paused"147 );148 info("Open a second popup which will also hit the breakpoint");149 let onAvailable;150 const onNewTarget = new Promise(resolve => {151 onAvailable = ({ targetFront }) => {152 if (153 targetFront.url == POPUP_URL &&154 targetFront.browsingContextID != firstPopupBrowsingContext.id155 ) {156 targetCommand.unwatchTargets({157 types: [targetCommand.TYPES.FRAME],158 onAvailable,159 });160 resolve(targetFront);161 }162 };163 });164 await targetCommand.watchTargets({165 types: [targetCommand.TYPES.FRAME],166 onAvailable,167 });168 const secondPopupBrowsingContext = await openPopup(POPUP_URL, browser);169 info("Wait for second popup's target");170 const popupTarget = await onNewTarget;171 is(172 popupTarget.browsingContextID,173 secondPopupBrowsingContext.id,174 "The new target matches the popup WindowGlobal"175 );176 const secondThread = (await popupTarget.getFront("thread")).actorID;177 await waitForPausedThread(dbg, secondThread);178 is(179 dbg.selectors.getCurrentThread(),180 secondThread,181 "The second popup thread is automatically selected on pause"182 );183 is(184 await isPopupPaused(secondPopupBrowsingContext),185 true,186 "The second popup is really paused"187 );188 info("Resume the execution of the second popup");189 await resume(dbg);190 is(191 await isPopupPaused(secondPopupBrowsingContext),192 false,193 "The second popup resumed its execution"194 );195 is(196 await isPopupPaused(firstPopupBrowsingContext),197 true,198 "The first popup is still paused"199 );200 info("Resume the execution of the first popup");201 await dbg.actions.selectThread(getContext(dbg), firstThread);202 await resume(dbg);203 is(204 await isPopupPaused(firstPopupBrowsingContext),205 false,206 "The first popup resumed its execution"207 );208});209add_task(async function testClosingOriginalTab() {210 info(211 "Test closing the toolbox on the original tab while the popup is kept open"212 );213 const dbg = await initDebuggerWithAbsoluteURL(TEST_URI);214 await dbg.toolbox.selectTool("webconsole");215 info("Open a popup");216 const originalTab = gBrowser.selectedTab;217 await openPopup("about:blank");218 await wait(1000);219 const popupTab = gBrowser.selectedTab;220 gBrowser.selectedTab = originalTab;221 info("Close the toolbox from the original tab");222 await dbg.toolbox.closeToolbox();223 await wait(1000);224 info("Re-select the popup");225 gBrowser.selectedTab = popupTab;226 await wait(1000);...
Using AI Code Generation
1var wptools = require('wptools');2wptools.page(url).then(function(page) {3 page.popup_url().then(function(url) {4 console.log(url);5 });6});
Using AI Code Generation
1var wptools = require('wptools');2var wiki = new wptools('Barack Obama');3wiki.popup_url(function(url) {4});5var wptools = require('wptools');6var wiki = new wptools('Barack Obama');7wiki.get_url(function(url) {8});9var wptools = require('wptools');10var wiki = new wptools('Barack Obama');11wiki.get_langlinks(function(links) {12});13var wptools = require('wptools');14var wiki = new wptools('Barack Obama');15wiki.get_categories(function(categories) {
Using AI Code Generation
1var wptools = require('wptools');2wptools.page(url).then(function(page) {3 page.popup_url().then(function(popup_url) {4 console.log(popup_url);5 });6});7var wptools = require('wptools');8wptools.page(url).then(function(page) {9 page.popup_url().then(function(popup_url) {10 console.log(popup_url);11 });12});13var wptools = require('wptools');14wptools.page(url).then(function(page) {15 page.popup_url().then(function(popup_url) {16 console.log(popup_url);17 });18});19var wptools = require('wptools');20wptools.page(url).then(function(page) {21 page.popup_url().then(function(popup_url) {22 console.log(popup_url);23 });24});25var wptools = require('wptools');26wptools.page(url).then(function(page) {27 page.popup_url().then(function(popup_url) {28 console.log(popup_url);29 });30});
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Barack Obama');8page.get(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Barack Obama');13page.get(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Barack Obama');18page.get(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Barack Obama');23page.get(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Barack Obama');28page.get(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var page = wptools.page('Barack Obama');33page.get(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var page = wptools.page('Barack Obama');38page.get(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var page = wptools.page('Barack Obama');43page.get(function(err, resp) {44 console.log(resp);45});
Using AI Code Generation
1function popup_url(url) {2 var wptoolbar = document.getElementById("wptoolbar");3 wptoolbar.popup_url(url);4}5function popup_url(url) {6 var wptoolbar = document.getElementById("wptoolbar");7 wptoolbar.popup_url(url);8}9function popup_url(url) {10 var wptoolbar = document.getElementById("wptoolbar");11 wptoolbar.popup_url(url);12}13function popup_url(url) {14 var wptoolbar = document.getElementById("wptoolbar");15 wptoolbar.popup_url(url);16}17function popup_url(url) {18 var wptoolbar = document.getElementById("wptoolbar");19 wptoolbar.popup_url(url);20}21function popup_url(url) {22 var wptoolbar = document.getElementById("wptoolbar");23 wptoolbar.popup_url(url);24}25function popup_url(url) {26 var wptoolbar = document.getElementById("wptoolbar");27 wptoolbar.popup_url(url);28}29function popup_url(url) {30 var wptoolbar = document.getElementById("wptoolbar");31 wptoolbar.popup_url(url);32}33function popup_url(url) {34 var wptoolbar = document.getElementById("wptoolbar");
Using AI Code Generation
1var wptb = require('wptb');2wptb.popup_url(url, function(err, stdout, stderr){3 console.log(stdout);4});5var wptb = require('wptb');6wptb.popup_url(url, function(err, stdout, stderr){7 console.log(stdout);8});9var wptb = require('wptb');10wptb.popup_url(url, function(err, stdout, stderr){11 console.log(stdout);12});13var wptb = require('wptb');14wptb.popup_url(url, function(err, stdout, stderr){15 console.log(stdout);16});17var wptb = require('wptb');18wptb.popup_url(url, function(err, stdout, stderr){19 console.log(stdout);20});21var wptb = require('wptb');22wptb.popup_url(url, function(err, stdout, stderr){23 console.log(stdout);24});25var wptb = require('wptb');26wptb.popup_url(url, function(err, stdout, stderr){27 console.log(stdout);28});29var wptb = require('wptb');30wptb.popup_url(url, function(err, stdout, stderr){31 console.log(stdout);32});
Using AI Code Generation
1var wptb = Components.classes["@mozilla.org/wptoolbar;1"].getService(Components.interfaces.nsIWebpagetestToolbar);2<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>3var WPTOOLBAR = {4popup_url : function(url) {5var wptb = Components.classes["@mozilla.org/wptoolbar;1"].getService(Components.interfaces.nsIWebpagetestToolbar);6wptb.popup_url(url);7}8};
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.5c5b5d5a5d5d5d5d5d5d5d5d5d5d5d5');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org', 'A.5c5b5d5a5d5d5d5d5d5d5d5d5d5d5d5');8 if (err) return console.error(err);9 console.log(data);10 wpt.getScreenshot(data.data.median.firstView, function(err, data) {11 if (err) return console.error(err);12 console.log(data);13 });14});15{ statusCode: 400,16 data: 'Missing required parameter: testId' }
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!!