Edit table content and save it to database - android

I have a HTML table that is editable. I already used contenteditable but after that I just have no idea how to save the changes. It only saves while I am on that page but after I reload it sets page to initial value. The table is project for school. Simple solution is much appreciated since I don't know much about android app development. Here is my code:
<head>
<style>
th{
background-color:lightblue;
font-weight:bold;
font-size:20p‌​t
}
.open{
color:black;
background-color:lightblue;
font-size:15pt
}
.chapel{
color:blue;
background-color:lightblue;
font-size:10pt‌​
}
</style>
</head>
<body>
<table border=7 width=10%>
<tr></tr>
<tr>
<td align=center rowspan=2 class="open"><td>
</tr>
</table>
<div id="example-one" contenteditable="true"></div>
</body>

jQuery(document).ready(function($) {
jQuery("#savebtn").click(function(){
$.ajax({
url: 'ajax_url_address',
type: "POST",
cache: false,
dataType: 'json',
data : {
information : jQuery('#content').html(),
},
success: function (response) {
if(response){
// jQuery('#UserCityId').html(response.content);
alert('save successfull');
}else{
alert('not save');
}
}
});
});
});
user ajax to post all content from DIV and save
<div id="content">
<table> {table content heare}</table>
</div>

Related

How to parse html tag from response of responsebody in retrofit

My code is as shown below:
private void testInfo() {
if (InternetConnection.checkConnection(LogInActivity.this)) {
Observable<ResponseBody> results = RetroClient.getApiService()
.testInfo("Basic NTcyODQ4MDc0NzEzNTIwOToxMjhiNTNkMS1iMTc2LTQxOTEtYWJmYS1hN2RhYjIzYmFjMzk=", "application/x-www-form-urlencoded",
"John Q. Test", "Visa", "4747474747474747", 12, 25, 999, "123 A. Street",
"Orem", "UT", "84058", "USA", "4355824", "ACkwlGTtMOGNlwtLY2GIsi/MgC5bgDOQIVzPFKzapIEcnUR7XEvTfeYLeVswApKH+vW+1rgO7PwJahABSrtYgC6ZmkOTxywIb24mdyefTZpOu+h9iDdu/SYcDnBcwf/sjcntYBLPCL5+gPLCpu9YpItDhb055zf9bNDWEGdoLRbl6BPVPbYCEQH9et72KxgnPZHA3Oe05IrRiy22pP8HAzpzss8c37MjEOQB5tbfkuDUCj1pfCohsQ74JBDgc0ntG+rpv7ljFElCxO95FyVYkGhIwaMQWaplwhpWqJIIw9JRL0IRTZG+ml1QzJBgdNHyKJXJmH9Gh/yVzXU4U9gyY6d3ObUYT0ODjNwnEIAc1XSOFd+WE5XklitZynuo4MgghWfZpMl0ChofstLS5e/Np7RF0xJe8WGAAV4Jdku84mnrt/42YRW2yzpUOpKI8+VddlRDKRsmvkei8gY4yjxINocMUfnzPBmsecgW8EVO1nIBpKLW36wLJ7Bawy6MA7wULO5TyP5j9ksdn6Y5IOOT+rpiJc6+OUJZZ0I7ef6qWuE=");
// showProgressBar();
results.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ResponseBody>() {
#Override
public void onCompleted() {
unsubscribe();
}
#Override
public void onError(Throwable e) {
// hideProgressBar();
Toast.makeText(LogInActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
#Override
public void onNext(ResponseBody response) {
Log.d(TAG, "onNext: " + response.string());
}
});
} else {
Toast.makeText(LogInActivity.this, R.string.string_internet_connection_warning, Toast.LENGTH_LONG).show();
}
}
Now for this, I get the following as my response:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
</title></head>
<body>
<form method="post" action="./spr.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="k2sKy+QLc68jCgZVuadfy2ONS4SO3c0" />
<div>
<div id="PanelPleaseWait">
<div style="min-height: 10em; display: block; vertical-align: middle; text-align: center; padding-top: 100px;">
<h3>
Processing, please wait...</h3>
Please wait, your transaction is processing. Please don't hit back or stop.<br />
<img src="images/bigrotation.gif" />
</div>
</div>
</div>
<input name="ResponseCipher" type="hidden" id="ResponseCipher" value="6s31abi0RZUSAw3Iwk0db9irVWKTi2+UtpSVTUE7DKlhWqLd1WBlQ==" /></form>
</body>
</html>
<script type="text/javascript">
document.forms[0].action='http://krl.in/';
document.forms[0].submit();
</script>
Here, what I want is , I want to access value of input with id ResponseCipher. What should I do to achieve that?
Jsoup is a library lets you parse numerous HTML tags/attributes off String.
Just parse your desire input Id and you should access the value as well.
Take a look at the following sources.
Parsing HTML in Android with Jsoup
Parsing input element using JSoup

ionic2: facebook album cover photo

I am able to fetch all the albums from Facebook User's account. I am trying to show it in Grid but I need cover photo of Album as well. I tried below code:
<ion-grid>
<div *ngFor="let album of albums; let i = index;">
<ion-row *ngIf="i % 3 === 0">
<ion-col col-4 *ngIf="i < albums.length">
<ion-card>
<img src="https://graph.facebook.com/{{albums[i].id}}/picture?type=album" />
<div class="card-title">{{ albums[i].name }}</div>
</ion-card>
</ion-col>
<ion-col col-4 *ngIf="i+1 < albums.length">
<ion-card (click)="albumClicked(album)">
<img src="https://graph.facebook.com/{{albums[i+1].id}}/picture?type=album" />
<div class="card-title">{{ albums[i+1].name }}</div>
</ion-card>
</ion-col>
<ion-col col-4 *ngIf="i+2 < albums.length">
<ion-card (click)="albumClicked(album)">
<img src="https://graph.facebook.com/{{albums[i+2].id}}/picture?type=album" />
<div class="card-title">{{ albums[i+2].name }}</div>
</ion-card>
</ion-col>
</ion-row>
</div>
</ion-grid>
This is how I get albums:
FacebookService.ts:
...
getUserAlbums(userID) {
return this.facebook.api("/v2.9/" + userID + "/albums", []);
}
...
FacebookAlbumsPage.ts:
...
getUserAlbums(facebookUserId) {
this.showLoading();
this.facebookUserDetails.getUserAlbums(facebookUserId).then((res) => {
this.albums = res.data;
this.hideLoading();
});
}
...
While getting image I get below error:
Failed to load resource: the server responded with a status of 400 ()
Does anyone know how to get facebook albums with their cover photos using Ionic2 ?
Edit:
This is the url that is passed in img src:
https://graph.facebook.com/186028675250734/picture?type=album
But when I opened the link directly into browser, it returned below error:
{
"error": {
"message": "Unsupported get request. Object with ID '186028675250734' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"fbtrace_id": "BtQDS1csSgu"
}
}

Write a java script for doing the following. 1. Create a Cookie and add these four user id’s and passwords to this Cookie

User Authentication:
Assume four users
user1, user2, user3 and user4
having the passwords
pwd1, pwd2, pwd3, and pwd4
respectively. Write a java script for doing the following.
Create a Cookie and add these four user id’s and passwords to this Cookie.
Read the user id and passwords entered in the Login form (week1) and authenticate with the values (user id and passwords ) available in the cookies. If he is a valid user(i.e., user-name and password match) you should welcome him by name(user-name) else you should display “You are not an authenticated user“
<html>
<head>
<title> login Page </title>
<script type="text/javascript">
function setusercookies()
{
var user1 ={};
user1.user1 = "user1";
user1.pwd1 = "user1123";
jsonString=JSON.stringify(user1);
document.cookie ="cookieObject="+jsonString;
var user2 ={};
user2.user2="user2";
user2.pwd2="user2123";
jsonString=JSON.stringify(user2);
document.cookie ="cookieObject1="+jsonString;
var user3 ={};
user3.user3="user3";
user3.pwd3="user3123";
jsonString=JSON.stringify(user3);
document.cookie ="cookieObject2="+jsonString;
var user4 ={};
user4.user4="user4";
user4.pwd4="user4123";
jsonString=JSON.stringify(user4);
document.cookie ="cookieObject3="+jsonString;
alert("User id and password of four users are set as cookie successfully \n"+document.cookie);
}
function cleartextboxes()
{
document.getElementById("usr").value="";
document.getElementById("pwd").value="";
}
function getCookie()
{
var nameValueArray = document.cookie.split("=");
var user=document.getElementById("usr").value;
var pass=document.getElementById("pwd").value;
for(var j=0;j<4;j++)
{
var namesplit=nameValueArray[j];
for(var i=0;i<namesplit.length;i++)
{
var n=namesplit.indexOf(":");
var cuser=namesplit.substring(namesplit.indexOf(":")+2,namesplit.indexOf(",")-1);
var cpass=namesplit.substring(namesplit.indexOf(":",parseInt(n+1))+2,namesplit.indexOf(";")-2);
}
if(user==cuser)
{
break;
}
}
if(user!="" && pass!="")
{
if(user==cuser && pass==cpass)
{
alert("Welcome "+cuser);
}
else
{
alert("You are not a authorised person");
}
}
else
alert("Please enter required fields...");
}
</script>
</head>
<body onload="setusercookies()">
<table border="1" size="50%">
<tr>
<td>User Name:</td>
<td><input type="text" id="usr" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" id="pwd" /></td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="Clear" onclick="cleartextboxes()"/>
<input type="button" value="Login" onclick="getCookie()"/>
</td>
</tr>
</table>
</body>
</html>

JSON load issue with angular.js in phonegap

I'm trying to load JSON from my wordpress-based website. I'm using phonegap to create an app on android, ios and windows. I'm using this js for the JSON, calling for business hours (shours1, shours2, shours3):
(function(){
'use strict';
var app = angular.module('app', ['onsen', 'angular-images-loaded', 'ngMap', 'angular-carousel']);
app.controller('restaurantController', function($http, $scope, $compile, $sce){
$scope.getHours = function(){
$scope.isFetching = true;
$scope.shours1 = '';
$scope.shours2 = '';
$scope.shours3 = '';
$http.jsonp('http://signsrestaurant.ca/api/get_posts/?post_type=restaurant&posts_per_page=-1&callback=JSON_CALLBACK').success(function(response) {
// Get's the first restaurant
$scope.restaurantJson = response.posts[0];
$scope.isFetching = false;
console.log( $scope.restaurantJson.custom_fields.shours1[0] );
$scope.shours1 = $scope.restaurantJson.custom_fields.shours1[0];
$scope.shours2 = $scope.restaurantJson.custom_fields.shours2[0];
$scope.shours3 = $scope.restaurantJson.custom_fields.shours3[0];
});
}
});
})();
Here is my html:
<ons-page ng-controller="restaurantController" ng-init="getHours()">
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="menu.toggle()"><ons-icon icon="ion-navicon-round" fixed-width="false"></ons-icon></ons-toolbar-button>
</div>
<div class="center">Location</div>
<div class="right" ng-show="isFetching">
<ons-toolbar-button><ons-icon icon="ion-loading-c" fixed-width="false" ></ons-icon></ons-toolbar-button>
</div>
</ons-toolbar>
<div class="app-page">
<div class="app-page-photo">
<ons-row class="app-map">
<ons-col>
<map center="[43.664639, -79.384649]">
<marker
position="[43.664639, -79.384649]"
title="Signs Restaurant & Bar"
animation="Animation.BOUNCE"
visible="true" ></marker>
</map>
</ons-col>
</ons-row>
<ons-list class="app-photo-buttons">
<ons-list-item modifier="action-buttons">
<ons-row class="action">
<ons-col class="action-col">
<div class="action-icon"><ons-icon icon="ion-ios-star-half"></ons-icon></div>
<div class="action-label">Rate</div>
</ons-col>
<ons-col class="action-col">
<div class="action-icon"><ons-icon icon="ion-bookmark"></ons-icon></div>
<div class="action-label">Favorite</div>
</ons-col>
<ons-col class="action-col">
<div class="action-icon" onclick="window.open('tel:647-428-3076', '_system', 'location=yes')"><ons-icon icon="ion-ios-telephone"></ons-icon></div>
<div class="action-label" onclick="window.open('tel:647-428-3076', '_system', 'location=yes')">Call</div>
</ons-col>
<ons-col class="action-col">
<div class="action-icon" onclick="window.open('http://maps.google.com/maps?q=43.664639,-79.384649', '_system', 'location=yes'), window.location('maps://maps.apple.com/?q=43.664639,-79.384649')"><ons-icon icon="ion-map"></ons-icon></div>
<div class="action-label" onclick="window.open('http://maps.google.com/maps?q=43.664639,-79.384649', '_system', 'location=yes'), window.location('maps://maps.apple.com/?q=43.664639,-79.384649')">Directions</div>
</ons-col>
</ons-row>
</ons-list-item>
</ons-list>
<ons-list modifier="inset" style="margin-top: 10px">
<ons-list-item>
<div class="app-open-desc">
<ons-icon icon="ion-android-clock"></ons-icon>
Monday <span class="label label-danger">{{ shours1 }}</span>
</div>
</ons-list-item>
<ons-list-item>
<div class="app-open-desc">
<ons-icon icon="ion-android-clock"></ons-icon>
Tuesday-Thursday <span class="label label-default">{{ shours2 }}</span>
</div>
</ons-list-item>
<ons-list-item>
<div class="app-open-desc">
<ons-icon icon="ion-android-clock"></ons-icon>
Friday-Sunday <span class="label label-default">{{ shours3 }}</span>
</div>
</ons-list-item>
</ons-list>
</div>
</div>
</ons-page>
It seems to be working partially. The shours do load, but only after I rotate my android or click on the menu. It doesn't load off-hand immediately. It basically needs some sort of a refresh to get it to load. I would appreciate it if someone can help me out with this.
Thanks a lot to Andreas Argelius. I wrapped the
$scope.shoursX
in
$scope.$evalAsync(function() { ... })
and that did it.
EDIT: I spoke too soon. It worked and it didn't. The issue still persists.

WebView blocking pop up windows?

I'm using WebView to browse pesopay.com and it works properly, except when I pressed the submit button. Using internet browsers like Google Chrome will show a pop up window, it confirms the information you filled. But in my Android WebView nothing happened when I pressed the submit button. I think because WebView is not enabled to display a pop up window.
Can anyone point me what is wrong?
Here is my activity:
public class PaymentActivity extends Activity {
String amount1;
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.payment);
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
amount1 = extras.getString("amount1");
}
WebView web = (WebView) findViewById(R.id.web1);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("javascript:window.onload = function(){setValue(\""+ amount1 +"\");};");
web.loadUrl("file:///android_asset/www/index.html");
}
}
My web page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function setValue(amount1) {
myValue = amount1;
document.getElementById("amount").value = myValue;
}
</script>
<script type="text/javascript">
function rand ( n )
{
document.getElementById("orderRefId").value = ( Math.floor ( Math.random ( ) * n + 1 ) );
}
</script>
</head>
<body onLoad="rand(200000)">
<!--
Note: https://www.pesopay.com/b2c2/eng/payment/payForm.jsp for live payment URL
https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp for test payment URL
-->
<form method="POST" name="frmPayment" action="https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp">
<table>
<tbody>
<tr>
<td>Order Reference No. (your reference number for every transaction that has transpired):</td>
<td><input type="text" id="orderRefId" name="orderRef" value="Test-001"/></td>
</tr>
<tr>
<td>Amount:</td>
<td><input type="text" name="amount" id="amount" value=""/></td>
</tr>
<tr>
<td>Currency Code - "608" for Philippine Peso, "840" for US Dollar:</td>
<td><input type="text" name="currCode" value="608"/></td>
</tr>
<tr>
<td>Language:</td>
<td><input type="text" name="lang" value="E"/></td>
</tr>
<tr>
<td>Merchant ID (the merchant identification number that was issued to you - merchant IDs between test account and live account are not the same):</td>
<td><input type="text" name="merchantId" value="18056869"/></td>
</tr>
<tr>
<td>Redirect to a URL upon failed transaction:</td>
<td><input type="text" name="failUrl" value="http://www.yahoo.com?flag=failed"/></td>
</tr>
<tr>
<td>Redirect to a URL upon successful transaction:</td>
<td><input type="text" name="successUrl" value="http://www.google.com?flag=success"/></td>
</tr>
<tr>
<td>Redirect to a URL upon canceled transaction:</td>
<td><input type="text" name="cancelUrl" value="http://www.altavista.com?flag=cancel"/></td>
</tr>
<tr>
<td>Type of payment (normal sales or authorized i.e. hold payment):</td>
<td><input type="text" name="payType" value="N"/></td>
</tr>
<tr>
<td>Payment Method - Change to "ALL" for all the activated payment methods in the account, Change to "BancNet" for BancNet debit card payments only, Change to "GCASH" for GCash mobile payments only, Change to "CC" for credit card payments only:</td>
<td><input type="text" name="payMethod" value="ALL"/></td>
</tr>
<tr>
<td>Remark:</td>
<td><input type="text" name="remark" value="Asiapay Test"/></td>
</tr>
<!--<tr>
<td>Redirect:</td>
<td><input type="text" name="redirect" value="1"/></td>
</tr>-->
<tr>
<td></td>
</tr>
<input type="submit" value="Submit">
</tbody>
</table>
</form>
</body>
</html>
If i am getting right , you need to use JavaScriptInterface for calling JavaScript function from Android.
Check this link which may help you :
http://www.codeproject.com/Articles/392603/Android-addJavaScriptInterface
Or check some websettings :
http://developer.android.com/reference/android/webkit/WebSettings.html#setSupportMultipleWindows%28boolean
try to put this code in onCreate()
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
The function which is responsible for dialogs in Webview is onJsAlert of WebChromeClient.
Here is sample code
public class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onJsAlert(WebView view, String url, String message, JsResult jsResult) {
// you can create your own dialog here or just return true for no pop up.
return true;
}
}
and add this to your webview:
MyWebChromeClient myWebChromeClient = new MyWebChromeClient();
webView.setWebChromeClient(myWebChromeClient);

Categories

Resources