I am currently trying to call the PHP script upon clicking OK button on EXTJS message alert box.
For some reason it doesn't even display the Alert box when I use handler. However when I used Listener it displays the Alert box but doesn't call the php script upon clicking OK button. I read on different blogs and come to know Handler is the best way to go forward
I will appreciate if somebody can help me or point me to the right direction. I am using the latest release of EXTJS4
Below is the EXTJS tree panel code I've written using handler;
var treePanel = Ext.create('Ext.tree.Panel', {
id: 'tree-panel',
title: 'Available Database',
region: 'north',
split: true,
height: 360,
minSize: 150,
rootVisible: false,
autoScroll: true,
store: store,
handler: function() {
if (treePanel.getSelectionModel().hasSelection()) {
var selValue = treePanel.getSelectionModel().getSelection();
Ext.MessageBox.alert('Press OK to confirm your subscription <br>' + selValue[0].data.text,
function(btn, text) {
if (btn == 'ok') {
Ext.Ajax.request({
url: 'addSubscription.php',
params: {
nodetext: text,
parentid: selectedNode[0].data.id
},
success: function(response) {
var id = response.responseText;
grid.getView().refresh();
}
})
} else {
Ext.MessageBox.alert('Record already subscribed');
}
});
}
}
});
Ext.tree.Panel have not 'handler' property in config.
Handler is a function that is executed when you click on some of the components - such as buttons.
You can add button on your treePanel toolbar, and use button handler:
...
tbar: [{
xtype: 'button',
text: 'Subscribe',
handler: function(button) {
...
}
}],
...
See on jsfiddle: http://jsfiddle.net/FFvLa/
but doesn't call the php script upon clicking OK button.
The function must be passed as the third argument in Ext.Msg.alert:
http://jsfiddle.net/FFvLa/2/
Related
I have a problem with PayPal Express Checkout integration : https://developer.paypal.com/docs/classic/express-checkout/in-context/javascript_advanced_settings/#color
If I close the pop-up before it loads completely, the pop-up won't show up anymore until I refresh!
This does occur on all browsers. The error on Chrome console is:
ppxo_paypal_legacy_gettoken_initxo Object
print # logger.js:65
Here is my code :
window.paypalCheckoutReady = function() {
paypal.checkout.setup("{$PayPal_in_context_checkout_merchant_id}", {
environment: {if $PAYPAL_SANDBOX}"sandbox"{else}"production"{/if},
click: function(event) {
event.preventDefault();
paypal.checkout.initXO();
updateFormDatas();
var str = '';
if($('.paypal_payment_form input[name="id_product"]').length > 0)
str += '&id_product='+$('.paypal_payment_form input[name="id_product"]').val();
if($('.paypal_payment_form input[name="quantity"]').length > 0)
str += '&quantity='+$('.paypal_payment_form input[name="quantity"]').val();
if($('.paypal_payment_form input[name="id_p_attr"]').length > 0)
str += '&id_p_attr='+$('.paypal_payment_form input[name="id_p_attr"]').val();
$.support.cors = true;
$.ajax({
url: "{$base_dir_ssl}modules/paypal/express_checkout/payment.php",
type: "GET",
data: '&ajax=1&onlytoken=1&express_checkout='+$('input[name="express_checkout"]').val()+'¤t_shop_url='+$('input[name="current_shop_url"]').val()+'&bn='+$('input[name="bn"]').val()+str,
async: true,
crossDomain: true,
success: function (token) {
var url = paypal.checkout.urlPrefix +token;
paypal.checkout.startFlow(url);
},
error: function (responseData, textStatus, errorThrown) {
alert("Error in ajax post"+responseData.statusText);
paypal.checkout.closeFlow();
}
});
},
buttons: [
{
container: 'paypal_process_payment',
type: 'checkout',
color: 'blue',
size: 'small',
shape: 'pill'
},
{
container: 'payment_paypal_express_checkout',
type: 'checkout',
color: 'gold',
size: 'small',
shape: 'pill'
}
]
});
};
I ran into the same issue,
After looking into the source code, it turns out that when paypal.checkout.initXO(); the paypal.checkout.startFlow function is wrapped in a once function, which means you can only call startFlow once. and paypal.checkout.initXO is overwritten to show a warning in the console.
Inside, paypal.checkout.closeFlow there is a call to paypal.checkout.reset which is important to resetting these functions.
The problem was happening when the user clicks the close button too early, where the startFlow promise wasn't being resolved (which means when the user closes the modal it will redirect to the canceled url) nor the paypal.checkout.closeFlow catch wasn't being hit either.
I was able to resolve the issue, by keeping track of how many times the user clicked the button, if it was more than once, I called paypal.checkout.closeFlow (which will reset) beforepaypal.checkout.initXO();
Dear fellow EXT enthusiasts,
I'm working on a project where I need an admin panel to edit job functions.
The grid is communicating to a MySQL database using Ext.Direct. It loads the data fine.
The grid shows the id and the function name
I added a RowEditing plugin to my grid for editting the function settings.
The problem is, when I try to commit the changes I get a tiny red triangle in the upper left corner of the grid without any error code in the console. The changes don't commit to the MySQL database.
The way my program works and loads the data:
This is my functionStore:
Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
Ext.define("MCS.store.FunctionStore",
{
extend: "Ext.data.Store",
requires: "MCS.model.Functions",
model: "MCS.model.Functions",
id: "FunctionStore",
proxy:
{
type: "direct",
api:
{
read: QueryDatabase.getFunctions,
create: QueryDatabase.createFunction,
update: QueryDatabase.updateFunction,
destroy: QueryDatabase.removeFunction,
}
},
});
In the controller: when the admin panel is rendered, the store gets loaded with the following function:
loadStore: function()
{
functionStore.load();
}
This is the grid where the functions are displayed:
var rowEditingFunctions = Ext.create("Ext.grid.plugin.RowEditing",
{
clicksToMoveEditor: 1,
autoCancel: false,
listeners: {
edit: function(editor,e,opt)
{
var grid = e.grid;
var record = e.record;
console.log(record.data.functionName);
var editedrecords = grid.getStore().getUpdatedRecords();
console.log(editedrecords);
}
}
});
var functionGrid = Ext.create("Ext.grid.Panel",
{
height: 500,
width: 800,
store: functionStore,
title:"List of Job Functions - double click to edit",
columns: [
{
dataIndex: "id",
width: 50,
text: "ID"
},{
dataIndex: "functionName",
flex: 1,
text: "Function",
field:
{
type: "textfield",
allowBlank: false
}
}],
plugins: [
rowEditingFunctions
],
dockedItems: [
{
xtype: "toolbar",
store: functionStore,
dock: "bottom",
items: [
{
iconCls: "add",
text: "Add",
handler: function()
{
rowEditingFunctions.cancelEdit();
var newRecord = Ext.create("App.model.Functions");
functionStore.insert(0, newRecord);
rowEditingFunctions.startEdit(0, 0);
var sm = functionGrid.getSelectionModel();
functionGrid.on("edit", function() {
var record = sm.getSelection()
functionStore.sync();
functionStore.remove(record);
functionStore.load();
});
}
}, {
iconCls: "delete",
text: "Delete",
handler: function()
{
rowEditingFunctions.cancelEdit();
var sm = functionGrid.getSelectionModel();
Ext.Msg.show(
{
title:"Delete Record?",
msg: "You are deleting a function permanently, this cannot be undone. Proceed?",
buttons: Ext.Msg.YESNO,
icon: Ext.Msg.QUESTION,
fn: function(btn)
{
if(btn === "yes")
{
functionStore.remove(sm.getSelection());
functionStore.sync();
}
}
});
}
}]
}]
});
As u can see I added a listener to the edit event of the RowEditing plugin, this displays the array of the edited record in console like it should.
4. And finally, this is the PHP code that updates the database:
public function updateFunction(stdClass $params)
{
$db = $this->__construct();
if ($stmt = $db->prepare("UPDATE functions SET functionName=? WHERE id=?"))
{
$stmt->bind_param('si', $functionName, $id);
$functionName = $params->functionName;
$id = (int) $params->id;
$stmt->execute();
$stmt->close();
}
return $this;
}
5. The weird part: once I've added one job function, I can edit all the other functions and those changes are committed to the database...
As a side note: I'm just a beginner in EXT, trying to learn it on my own, but I have been breaking my head on this issue for the last few days so I decided to ask you guys.
Thanks for your answers in advance!
I left the bug for what it was for a few weeks and started to look into it again this week.
I found a work around solution.
I've added the following code to my controller that controls the grids:
functionGrid.on('edit', function(editor, e)
{
e.store.sync();
});
Now when I update a record, the tiny red triangle still appears but after the e.store.sync() function is completed it disappears and the database table is updated.
Not a 100% clean solution, but it does the trick
If anyone has a better solution, please let me know
I have developed an facebook app which is using ajax request/response each 3secs. and also there are menu items which are loading content in main div. Every ajax request is going to common.php. Few ajax are very slow. I want to know that using a single file for all request is slowing performance?
Here is ajax request which is slow:
function FetchMore()
{
document.getElementById("debugger").innerHTML = "Fetch more called";
attempt++;
/*********proccessing ajax***********/
document.getElementById("bldr").style.display="";
var urlp="https://www.shopinion.net/facebook/common.php?FBUID="+fbuid+"&action=more&attempt="+attempt+"&what="+lstevt;
if(lstevt == "home" || lstevt == "rec")
{
if(complete==false)
{
complete=true;
setTimeout("Watcher()",10000);
document.getElementById("debugger").innerHTML = "Reqest send Fetch more called";
MoreAjaxReq = $.ajax({
async: true,
url: urlp,
cache: true,
success: function(data) {
complete=false;
document.getElementById("debugger").innerHTML = "Data received Fetch more";
setTimeout("getScroll()",3000);
document.getElementById("content").innerHTML +=data;
document.getElementById("content").style.opacity="1";
Tip();
$('a[rel*=facebox]').facebox({
loadingImage : 'facebox/loading.gif',
closeImage : 'facebox/closelabel.png'
})
var handler = null;
// Prepare layout options.
var options = {
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: $('#content'), // Optional, used for some extra CSS styling
offset: 6, // Optional, the distance between grid items
itemWidth: 210 // Optional, the width of a grid item
};
$(document).bind('scroll', onScroll);
// Call the layout function.
handler = $('#tiles li');
handler.wookmark(options);
$('a[rel*=facebox]').facebox({
loadingImage : 'facebox/loading.gif',
closeImage : 'facebox/closelabel.png'
})
document.getElementById("bldr").style.display="none";
//FB.Canvas.scrollTo(0,400);
setTimeout("Trick87()",3000);
}
});
}
//
Please help me how to improve response time?
Thanks in advanced.
Oh, there are lots of ways to improve performence. I will list a few
Cache data on server side
Minimize the content in the response
Maybe you don't have to fetch more data if the first request hasn't success yet.
Use as few database calls as possible
As you can see i am noob at jquery / javascript, i need to pass variable to GET or POST written in form and the result from php need to be passed to jquery, i started to write smthing as below, but it doesnt work.
anyone help me out please
// id and settings for msg box
$("#registerin").click(function() {
$.msgbox("<p>In order to process your request you must provide the following:</p>", {
type : "prompt",
inputs : [
{type: "text",label: "Insert your Name:", value: "George", required: true},
],
buttons : [
{type: "submit", value: "OK"},
{type: "cancel", value: "Exit"}
]
}, // id and settings for msg box - end
function(name) {
// checking if name field has been set
if(name) {
// pass from field to php $_GET['name_php'] variable
$.get("form.php", {name_php: name },
**// rewriten**
function(data) {
if (data){
// inline the data creation/insertion
$.msgbox($('#textbox').html(data), {type: "info"});
} // if data end
}); // function data end
**// rewriten**
} // if name end
}); // function name end
}); // registerin click
$.get is an asynchronous function call, so that means that code below it is not garunteed to be run AFTER it has been proccessed. your callback function inside the $.get call should look like this:
function(data) {
if (data){
// inline the data creation/insertion
$.msgbox($('#textbox').html(data), {type: "info"});
}
}
I m using FB.ui method in facebook to show stream publish box as follows:
function showfeed()
{
var publish = {
method: 'stream.publish',
attachment: {
name: 'XYZ',
caption: 'caption here',
description: ('description'),
href: 'url',
media: [{
type: 'image',
href: 'url',
src: 'xyz.gif'
}]
},
action_links: [{ text: 'XYZ', href: 'url' }]
};
FB.ui(publish,null);
}
This works fine but my page is very long in height so when i click button to show this dialog it appears at center of page not at top so even dialog is display at center it's not display to me as i m at top. Is there any away to position dialog at top so any one can see it.
add the code below to <style>. [got that from other forums) hope that helps
div.fb_dialog_advanced+div.fb_dialog_advanced {
top:50px !important;
}
div.fb_dialog_advanced+div.fb_dialog_advanced { top:50px !important; } does not work any longer. See this:
1:
But I've worked around the issue with jQuery. It's kinda hacky but it works:
function move_to_top( value )
{
$(".fb_dialog").each(function(index) {
if($(this).css("top")!='-10000px') {
$(this).css("top", value + 'px' );
}
});
setTimeout( ('move_to_top("'+value+'");'), 1250);
}
function send_request()
{
FB.Canvas.scrollTo(0,0);
FB.ui({method: 'apprequests', message: 'Press accept to see this request.', data: 'tracking information for the user'},
function(response) {
if(response!=null)
{
alert('You are boss')
}
});
$(".fbProfileBrowserResult").ready( function(){
t = setTimeout ( ('move_to_top("'+50+'")'), 1250 );
});
}