Get page title in themeablebrowser Cordova/ Phonegap - javascript

Hi i'am working in Cordova v3.7 and themeablebrowser Cordova plugin
in want to get title of the page in themeablebrowser i can't get it. I have tried executeScript as specified in documentation but app crashes. here's what i have done so far.
function innAppInit(_url) {
app.Log('browser news link=' + _url);
if (_url == null) {
_url = 'http://apache.org';
}
var ref = cordova.ThemeableBrowser.open(_url, '_blank', {
backButtonCanClose: false,
hideForwardButton: true,
toolbarColor: '#239EC9',
titleColor: '#FFFFFF',
statusbarColor: '#239EC9',
navButtonAlign: 'left',
closeButtonAlign: 'right',
menuButtonAlign: 'right',
titleStaticText: 'Add New Web Page',
menuButtonImage: 'themeablebrowser_stub_menu',
menuButtonPressedImage: 'themeablebrowser_stub_menu_highlight',
closeButtonImage: 'themeablebrowser_stub_close',
closeButtonPressedImage: 'themeablebrowser_stub_close_highlight',
backButtonImage: 'themeablebrowser_stub_back',
backButtonPressedImage: 'themeablebrowser_stub_back_highlight',
// menuTitle: 'Add Url to list',
menuCancel: 'Cancel',
menuItems: [{
event: 'event_getURL',
label: 'Add'
}]
});
ref.addEventListener('loadstart', function(event) {
try {
app.Log('loadstart function');
$('.ui-loader').show();
} catch (e) {
app.ErrorLog(e);
}
});
ref.addEventListener('loadstop', function(event) {
try {
app.Log('loadstop function');
$('.ui-loader').hide();
ref.executeScript({
code: 'return document.title'
},
function(values) {
alert(values);
});
} catch (e) {
app.ErrorLog(e);
}
});
ref.addEventListener('event_getURL', function(event) {
try {
var url = event.url;
app.Log('get url=' + url);
ref.close();
} catch (e) {
app.ErrorLog(e);
}
});
ref.addEventListener('exit', function(event) {
try {
app.Log('exit function');
$('.ui-loader').hide();
} catch (e) {
app.ErrorLog(e);
}
});
}

This question has been raised and discussed on bug tracker.
https://github.com/initialxy/cordova-plugin-themeablebrowser/issues/8
The gist is that the script you execute should be
document.title
Not
return document.title

Related

XMLHttpRequest open() function is not working even I use a copy of the same code in another part of my system

I´m going to try to explain what my problem is.
I have this code
const deleted = document.querySelector('form#delete');
const edited = document.querySelector('form#edit');
eventListeners();
function eventListeners() {
deleted.addEventListener('submit', markDeleted);
edited.addEventListener('submit', userEdit);
}
function markDeleted(event) {
event.preventDefault();
console.log('^*^*^ delete *^*^*');
var xhr = new XMLHttpRequest();
xhr.open('POST', '/models/comm.model.php', true);
console.log('^*^*^ after xhr.open *^*^*');
// SOME MORE CODE ...
My problem is where I open the communication
xhr.open('POST', '/models/comm.model.php', true);
because never executes comm.model.php file even I use the same file
to login and register new users
this is my comm.model.php file
include_once $_SERVER['DOCUMENT_ROOT'] . '/config/constants.php';
print_r("inside comm model");
$accion = filter_var($_POST['tipoAccion'], FILTER_SANITIZE_STRING);
if ($accion === 'login') {
// some code ...
}
if ($accion === 'register') {
// some code ...
}
if ($accion === 'userDelete') {
print_r($accion);
}
Here is the browser console image
So you can see there is no problem with comm.model.php file
thank you for any help
#epascarello
here is the complete code you asked for
function markDeleted(event) {
event.preventDefault();
console.log('^*^*^ delete *^*^*');
var xhr = new XMLHttpRequest();
xhr.open('POST', '/models/comm.model.php', true);
console.log('^*^*^ after xhr.open *^*^*');
xhr.onload = function () {
console.log('^*^*^ inside onload *^*^*');
if (this.status === 200) {
console.log('^*^*^ responseText no parse *^*^*');
console.log(xhr.responseText);
respuesta = JSON.parse(xhr.responseText);
switch (respuesta[0]) {
case 'nok':
Swal.fire({
title: 'Error',
text: 'El usuario NO pudo ser eliminado',
icon: 'error',
showClass: {
popup: 'animate__animated animate__zoomIn'
},
hideClass: {
popup: 'animate__animated animate__zoomOut'
}
})
break;
case 'ok':
if (respuesta[2] === 'userDelete') {
Swal.fire({
title: 'Usuario eliminado correctamente',
icon: 'success',
showClass: {
popup: 'animate__animated animate__zoomIn'
},
hideClass: {
popup: 'animate__animated animate__zoomOut'
}
}).then((resultado) => {
console.log(resultado.value);
if (resultado.value) {
window.location.href = '/master.php';
}
})
} else {
Swal.fire({
title: 'Error',
text: 'El usuario NO pudo ser eliminado',
icon: 'error',
showClass: {
popup: 'animate__animated animate__rotateIn'
},
hideClass: {
popup: 'animate__animated animate__rotateOut'
},
showConfirmButton: false,
timer: 2500
})
}
break;
// default:
// break;
}
xhr.send(usuario);
}
}
}

odoo js error Cannot read property 'include' of undefined while include function to base calendar

i want modification the base_calendar.js with new custom function like below
CalendarNotification = require('base_calendar.base_calendar');
console.log("Masuk sini bawah");
CalendarNotification.include({
'click .link2showed': function() {
console.log("ndak yo mlebu kene to");
var action = {
type: 'ir.actions.act_window',
res_model: 'crm.lead',
view_mode: 'form',
view_type: 'form',
views: [[false, 'form']],
res_id: 16644
};
this.do_action(action);
},
});
and this a base_calendar.js odoo addons
var Notification = require('web.notification').Notification;
var CalendarNotification = Notification.extend({
template: "CalendarNotification",
init: function(parent, title, text, eid) {
this._super(parent, title, text, true);
this.eid = eid;
this.events = _.extend(this.events || {}, {
'click .link2event': function() {
var self = this;
this.rpc("/web/action/load", {
action_id: "calendar.action_calendar_event_notify",
}).then(function(r) {
r.res_id = self.eid;
return self.do_action(r);
});
},
'click .link2recall': function() {
this.destroy(true);
},
'click .link2showed2': function() {
this.destroy(true);
this.rpc("/calendar/notify_ack");
},
});
},
});
How do I fix that and what causes it? I've been several times custom function JS like that and it worked well.
Thank in advance for any pointers.

localstorage value is changed on page refresh

I am creating an welcomescreen for my html app. and im using a welcomescreen plugin from github. you can check it here https://github.com/valnub/welcomescreen.js
now i want to show welcome screen when localstorage value is 0. and when close button of welcomescreen is clicked i am changing the localstorage value to 1. but on page refresh the localstorage value is again set to 0.
how to do that this is my js file.
/*jslint browser: true*/
/*global console, Welcomescreen, $*/
// Init method
$(document).ready(function () {
localStorage.setItem("welscreen", "0");
var welcomeTour = localStorage.getItem("welscreen");
if (welcomeTour == 0) {
$(document).ready(function () {
var options = {
'bgcolor': '#0da6ec',
'fontcolor': '#fff',
'onOpened': function () {
console.log("welcome screen opened");
console.log(welcomeTour);
},
'onClosed': function () {
localStorage.setItem("welscreen","1");
var welcomeTour = localStorage.getItem("welscreen");
console.log("welcome screen closed");
console.log(welcomeTour);
}
},
welcomescreen_slides,
welcomescreen;
welcomescreen_slides = [
{
id: 'slide0',
picture: '<div class="tutorialicon">♥</div>',
text: 'Welcome to this tutorial. In the <a class="tutorial-next-
link" href="#">next steps</a> we will guide you through a manual that will teach you how to use this app.'
},
{
id: 'slide1',
picture: '<div class="tutorialicon">✲</div>',
text: 'This is slide 2'
},
{
id: 'slide2',
picture: '<div class="tutorialicon">♫</div>',
text: 'This is slide 3'
},
{
id: 'slide3',
picture: '<div class="tutorialicon">☆</div>',
text: 'Thanks for reading! Enjoy this app or go to <a class="tutorial-previous-slide" href="#">previous slide</a>.<br><br><a class="tutorial-close-btn" href="#">End Tutorial</a>'
}
];
welcomescreen = new Welcomescreen(welcomescreen_slides, options);
$(document).on('click', '.tutorial-close-btn', function () {
welcomescreen.close();
});
$('.tutorial-open-btn').click(function () {
welcomescreen.open();
});
$(document).on('click', '.tutorial-next-link', function (e) {
welcomescreen.next();
});
$(document).on('click', '.tutorial-previous-slide', function (e) {
welcomescreen.previous();
});
});
};
});
Change this:
localStorage.setItem("welscreen", "0");
var welcomeTour = localStorage.getItem("welscreen");
to this:
var welcomeTour = localStorage.getItem("welscreen");
if(welcomeTour === undefined || welcomeTour === null) {
localStorage.setItem("welscreen", "0");
welcomeTour = "0";
}

post callback function synchronization

I'm using datatables and after post I want to refresh the page after changes in the database are done. But for now it's pretty much random if the page refreshes before or after the database is updated. I also tried to add 'success:' to the callback function but this doesn't help.
Script for datatables projects.php:
<script> $(document).ready( function () {
var projects = $('#projects').DataTable({
paging:true, dom: 'Blfrtip', colReorder: true, select: {style: 'single'},
buttons: [
{
text: 'Edit',
action: function () {
$projectID = $(projects.row('.selected').node()).data('id');
if ($projectID === undefined)
{
alert("Please select a project.");
} else {
window.location.href = "../projects/editProject.php?projectID=" + $projectID;
}
}
},
{
text: 'Add',
action: function () {
window.location.href = "../projects/addProject.php";
}
},
{
text: 'Delete',
action: function () {
$projectID = $(projects.row('.selected').node()).data('id');
if ($projectID === undefined)
{
alert("Please select a project.");
} else {
$.post("../projects/deleteProject.php",
{
projectID: $projectID,
function() {
window.location.reload(true);
}
}
);
}
}
}
] }); } ); </script>
deleteProject.php:
<?php
require("../database/dbService.php");
require("../projects/deleteProjectService.php");
session_start();
$connection = connectToDB();
// check if input data is set
if (!isset($_POST['projectID'])){
header("Location: ../projects/projects.php");
exit;
}
// input data
$projectID = $_POST['projectID'];
deleteProject($connection, $projectID);
$_SESSION['message'] = "The project has been deleted!";
?>
You placed callback function in the wrong place, it should have been:
$.post(
"../projects/deleteProject.php",
{ projectID: $projectID },
function(){ window.location.reload(true); }
);

Handling FilePathResult return values using filedownload jquery plugin

I am using fileDownload jQuery plugin to download a file which is served using ASP.NET MVC. The action is decorated with HttpGet and returns a FilePathResult. It works when a file is found. If a file is not found, I am not sure what to return in the action?
JavaScript:
function showMessageCancelDialog(message, request, titleValue) {
'use strict';
$('#messageDialog').html(message);
$('#messageDialog').dialog({
resizable: false,
width: '320px',
modal: true,
title: titleValue,
dialogClass: 'no-close',
buttons: {
Cancel: function () {
request.abort();
$(this).dialog("close");
}
}
});
}
function hideMessageDialog() {
'use strict';
$('#messageDialog').dialog("close");
}
function DownloadAttachment(itemId) {
'use strict';
var getAttachmentFileUrl = "/App/Download/GetAttachmentFile?ItemId=" + itemId;
var ajaxRequest = $.fileDownload(getAttachmentFileUrl, {
successCallback: function (message) {
hideMessageDialog();
},
failCallback: function (errorMessage) {
hideMessageDialog();
showMessageDialog("Download request failed:" + errorMessage, "Download attachment");
}
});
showMessageCancelDialog("Download in progress... , ajaxRequest, "Download attachment");
}
ASP.NET:
if(errorMessage == string.Empty)
{
this.Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadFile);
return new FilePathResult(downloadFile, "application/octet-stream");
}
else
{
// WHAT DO I RETURN HERE?
}
You could throw an error with your errorMessage and the jquery function failCallback() should catch that.
else {
throw new HttpException(404, errorMessage);
}
this.Response.Clear();
this.Response.StatusCode = 500;
this.Response.ContentType = "text/html";
this.Response.Write(errorMessage);
throw new Exception(errorMessage);
The above code called the failCallback on javascript

Categories