Move to another View in DojoMobile - ibm-mobilefirst

i am developing a simple Hybrid application in IBM Worklight using DOJO.I have a Login Page and a Welcome Page. Once i press the login button it will go to function to check whether credentials are correct,if it is correct i want to mo to Welcome Page.
My code..
HTML
...
..
<button data-dojo-type="dojox.mobile.Button" id="loginBtn"
style="margin-left: 50%; margin-top: 3%"
data-dojo-props="label:'Login', onClick:function(e){loginCheck();}"></button>
...
..
.JS
.
..
function loginCheck()
{
var username = uname.value;
var password = pass.value;
if(username == "admin" && password == "admin")
{
//Move to another view
}
else
{
alert("Incorrect Username or Password");
}
}
..
..
Any help is appreciated..

I use this code and it works
var w = dijit.byId('currentView');
w.performTransition('newView',1,"slide",null); //or #newView
Don't use alert, use this :
WL.SimpleDialog.show(
"My Title", "My Text",
[{text: "First Button", handler: function() {WL.Logger.debug("First button pressed"); }
}]
)

You can use the performTransition method, see http://dojotoolkit.org/api/1.9/dojox/mobile/View
Hope this helps,
Damien

Related

Odoo 8 - How to create a button that contains a pop-up message with a refresh of the actual view?

I have a button, and I would like to implement a behavior that, when the user clicks on this button, a pop-up message appears with a refresh of the actual view.
I already have the refresh behavior, but I don't know how to create the pop-up message and how to implement it with the refresh.
To create the popup message you can assign a confirm attribute.
<button name="toggle_active" type="object" confirm="(Un)archiving a forum automatically (un)archives its posts. Do you want to proceed?" class="oe_stat_button" icon="fa-archive">
This will prompt the user with a confirm dialog which you can use to convey your message and then after they click 'ok' it will execute your action.
<button name="test_dialog_then_action" type="object" class="oe_stat_button" icon="fa-check">
PYTHON Function
#api.multi
def test_dialog_then_action(self):
return {
'type':'ir.action.act_client',
'tag': 'show_my_dialog'
}
JS Script
odoo.define('addon_name.my_dialog', function(require){
"user strict";
var core = require('web.core');
var session = require('web.session');
var qweb = core.qweb;
var mixins = core.mixins;
var Widget = require('web.Widget');
var Model = require('web.Model');
var Dialog = require('web.Dialog');
function ActionShowDialog(parent, action){
var dialog = new Dialog(document.body, {
title: "Dialog Title",
subtitle: "This is a subtitle!",
size: 'medium',
$content: "<div id='my_div'>Hello World!</div>",
buttons: []
});
dialog.open();
setTimeout(function(){
dialog.close();
new Model('your_addon.model_name')
.call('func_name',arguments)
}, 3000);
}
core.action_registry.add("show_my_dialog", ActionShowDialog);
});

What are payloads in facebook messenger bot and how to handle them?

I want to send a button template message from my messenger bot. For example: set up a flip coin button which when pressed flips coin.
The bot already takes "flip a coin" command but how do I set that up with the button template message?
"payload":{
"template_type":"button",
"text":"FLIP A COIN",
"buttons":[
{
"type":"postback",
"title":"flip A COIN",
"payload":"flip(sender)"
}
]
}
It would be better if you give a plain text such as FLIP_SENDER, then handle it accordingly.
You can get your payload from request.data.
Here is the sample code ( i have used Facebook's quick_reply button)
var quickReplyPayload =
data.entry[0].messaging[0].message.quick_reply.payload;
var senderId = data.entry[0].messaging[0].sender.id;
if(quickReplyPayload === 'FLIP_SENDER'){
console.log(quickReplyPayload);
sendMessageToFacebook(senderId, response);
});
}
else if(quickReplyPayload === 'SOMETHING ELSE'){
sendMessageToFacebook(senderId, 'Another text');
}
else{
sendMessageToFacebook(senderId, 'Generic Text');
}

Getting the text of first <p> tag and check for successful login in an automation test script in Mocha and Selenium

I am having an automated testing script which I am trying to run using mocha on selenium environment.
The script first logs in, then checks the text of the all <p> tag.
If the text of any of the <p> tag matches the phrase ""Welcome to the admin page!"" then the login attempt will be considered successful. Else it's a failed attempt.
I want to change the code. Instead of iterating through all the tags, I just need to check with the first tag. How can I do that?
I want to record the details, whether the attempt is successful or failed one.
My code is given below.
var assert = require('assert');
var test = require('selenium-webdriver/testing');
var webdriver = require('selenium-webdriver');
var By = webdriver.By;
var until = webdriver.until;
var equals = webdriver.equals;
test.describe('TrackRevenue Test', function()
{
test.it('should work', function()
{
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.phantomjs())
.build();
var loginFlag = 0;
var baseUrl = 'http://saswatr3.ouh.co/login';
var expectedTitle = "Track Revenue";
var successMessage = "Welcome to the admin page!";
driver.get(baseUrl);
driver.getTitle().then(function(title)
{
if(expectedTitle === title)
{
console.log("Verification Successful - The correct title is displayed on the web page.");
}
else
{
console.log("Verification Failed - An incorrect title is displayed on the web page.");
}
});
driver.findElement(By.id('username')).sendKeys('saswat#matrixnmedia.com');
driver.findElement(By.id('password')).sendKeys('DarkPrince2012');
driver.findElement(By.id('_submit')).click();
driver.wait(until.titleIs('Track Revenue'), 1000);
driver.findElements(By.tagName('p')).then(function (pTag)
{
pTag.forEach(function(p) //I am iterating through all the <p>. I need to get only the first <p>
{
p.getText().then(function(text)
{
if(text.toLowerCase() === successMessage.toLowerCase())
{
loginFlag = 1;
}
//done(); //mocha async callback
});
});
if(loginFlag ==1)
console.log("Login Successful");
else
console.log("Login Unsuccessful");
});
driver.quit();
});
});
The html section of the <p> section having "Welcome to the admin page!"
<div class="wrapper wrapper-content animated fadeIn">
<div class="row">
<div class="col-centered col-xs-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Links</h5>
<div class="ibox-tools"> </div>
</div>
<div class="ibox-content">
<p>Welcome to the admin page!</p>
<p>Please use the menu on the left</p>
</div>
</div>
</div>
</div>
</div>
PS.
I need some more modification in the code. In any case, if the login fails, then the login page has div which displays the text : "Invalid credentials."
The html of the section is like this:
<div class="text-danger text-danger-orange">Invalid credentials.</div>
I want to have a check script which detects this section as well.
EDIT:
When I am putting this piece of script, then my script runs fine:
driver.findElements(By.xpath("//p[contains(text(), 'Welcome to the admin page!')]")).then(function()
{
loginFlag = 1;
if(loginFlag ==1)
console.log("Login Successful");
else
console.log("Login Unsuccessful");
});
But when I am putting this piece of script, I am getting an
Type Error: Undefined is not a function
if(driver.findElements(By.xpath("//p[contains(text(), 'Welcome to the admin page!')]")).size() != 0)
{
loginFlag = 1;
}
else
{
//"Welcome to the admin page" not found
if(driver.findElements(By.xpath("//div[contains(text(), 'Invalid Credentials!')]")).size() != 0)
{
//do what you have to do if "Invalid credentials" is found
}
else
{
// "Invalid credentials not found"
}
}
You could make your life easier with using XPATH. For example:
if(driver.findElements(By.xpath("//* [text()[contains(.,'Welcome to the admin page!')]]")).size() != 0){
//do what you have to do if "Welcome to the admin page" is found
}else{
//"Welcome to the admin page" not found
if(driver.findElements(By.xpath("//* [text()[contains(.,'Invalid credentials')]]")).size() != 0){
//do what you have to do if "Invalid credentials" is found
}else{
// "Invalid credentials not found"
}
}
I hope this helps.
EDIT:
As you wish a little elaboration:
With xpath you can simply just search for the desired text which should occur on your page. If you just want to look for the string "Welcome to the admin page" or "Invalid credentials" regardless of the position on the page you can easily search a text by:
//* [text()[contains(.,'<your string text here>')]]
It checks if the getText() method of a node contains the given text.
If you want to check the whole page if there is a result you can use findElements because it will return all found WebElements. If there is nothing found with the given xpath it return an empty "array" with size 0. So if you use
driver.findElements(By.xpath("//* [text()[contains(.,'Welcome to the admin page!')]]")).size() != 0
you can check if the method has found an element with the desired text.
That is all, the other stuff is just simple if/else.. you can use the above mentioned xpath and function as you like. So instead of iterating trough ALL you <p> tags you can simple just use the above mentioned xpath.
EDIT2:
with mocha you could try doing something like:
driver.findElements(By.xpath("//p[contains(text(), 'Welcome to the admin page!')]")).then(function(elements_arr)
{
if(elements_arr.length > 0){
//your element got found
console.log("Login Successful");
}else{
//your element was not found
console.log("Login Unsuccessful");
driver.findElements(By.xpath("//div[contains(text(), 'Invalid Credentials!')]")).then(function(elements_arr2)
{
if(elements_arr2.length > 0){
//your element invalid credentials got found
console.log("Login Unsuccessful, div invalid credentials found");
}else{
//your element was not found
console.log("Login Unsuccessful, div invalid credentials not found");
}
});
}
});

How To Count Views On Click Of A Button Or Web Page Is There Any Extension

I am a newbie interested to know are there any extension to count views on click of a button as to know no. of registered users or visiters to web page to know the view count on click of a image is there any extension.
Plz let me know if any
thanx :)
I think , there is no need of any extension. Make a Ajax call on click button or image you are interested.
Improved:
I supposed you have Site as controller and index as action. then, please keep this code on views/site/index.php .
Yii::app()->clientScript->registerScript('logo_as_image_script', '$(document).ready(function() {
$("#logo_as_image").click(function() {
$.post("'.Yii::app()->createAbsoluteUrl('site/index').'",
{
clicked: "1"
},
function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});');
Yii::app()->clientScript->registerCoreScript('jquery');
echo CHtml::image(Yii::app()->baseUrl . '/images/logo.png', 'Logo as Image', array('id' => 'logo_as_image'));
And, keep this code on SiteController.php .
public function actionIndex()
{
// keep record of data ; do more filtering ; other manupulation
if(isset($_POST['clicked'])){
$nextCount = Yii::app()->user->getState('clickCount')+1;
Yii::app()->user->setState('clickCount',$nextCount );
echo $nextCount;
Yii::app()->end();
}
#other codes here.
$this->render('index');
}
Lets assume that you want to store how many registered users have accessed the page at :
www.something.com/something/someaction
then visit the controller and add the code like so :
public function actionSomeAction()
{
$model = new CountDbModel();
if(!Yii::app()->user->isGuest){
$model->page = 'This page name here.';
$model->user_id = Yii::app()->user->id;
$model->count = #Add the value here.
#You other code here....
$this->render('whateverView',array('model'=>$blah));
}
}
I hope it helped.

how to invoke onclick function in html from vb.net or C#

I am trying to invoke the onclick function in an html page that displays content. I am using the httpwebreqest control and not a browser control. I have traced the function and tried to find the link it calls but looking at the code below I tried inserting the link into the browser with the main url but it does not work.
<div style="position:relative;" id="column_container">
<a href="#" onclick="
if (! loading_next_page) {
loading_next_page = true;
$('loading_recs_spinner').style.visibility = 'visible';
**new Ajax.Request('/recommendations?directory=non-profit&page=**' + next_page, {
onComplete: function(transport) {
if (200 == transport.status){
$('column_container').insert({ bottom: transport.responseText });
loading_next_page = false;
$('loading_recs_spinner').style.visibility = 'hidden';
next_page += 1;
if (transport.responseText.blank()) $('show_more_recs').hide();
}
}
});
}
return false;
Any ideas would be deeply appreciated.
Thanks anyone who has viewed...but I resolved the issue. The link after the ajax request was actually correct and it just was not showing anything in the browser but the source contains all the links I need.