How to catch event of hyperlink in controller in extjs4? - hyperlink

I am working in extjs4 MVC.I am getting stuck at a point where I have to catch event click of hyperlink in extjs4.I want to catch that event in controllers 'control' method.I tried a lot but not get solved please some one give some suggestion to how to solve this problem.
1)Here is my some view code :--
Ext.define('AM.view.user.linkView', {
extend:'Ext.form.Panel',
alias:'widget.Link',
title:'hyper link',
items:[
{
xtype: 'box',
autoEl: {tag: 'a', href: '#', html: 'Click on this button',id:'link'}
}]
});// End of login class
2)Here is my controller code: ---
Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',
views: ['user.linkView'],
init: function() {
this.control({
'Link box[tag: a]':
click:this.linkClicked
});
},
linkClicked:function()
{
console.log("clicked on link");
}
});
I tried a lot on it.but not get solved this problem.How can I solve this this please give some suggestion...

Ext.define('AM.view.user.linkView', {
extend:'Ext.form.Panel',
alias:'widget.Link',
name:'linkPanel',
title:'hyper link',
items:[
{
xtype: 'box',
autoEl: {tag: 'a', href: '#', html: 'Click on this button',id:'link'}
}]
});// End of login class
Use below code in controller
var controller = this;
controller.control({
'linkPanel': {
afterrender: function() {
Ext.get('link').on('click', function() {
controller.linkClicked();
});
}
}
});
This will work !!!!
Thanks

Related

How can I prevent the browser screen from scolling to the top when I do an ajax request?

My ajax is working nicely.
I have a big table of bookmarks (http://www.railslinks.com) and I can verify an individual link. When I do that I put a spinner up and then I replace it with Verified or Unverified. This is working well.
The only downside is that when I click on verify for one of my links that is "3 pages down", the screen element is updated correctly - but then the screen scrolls back up to the top of the page. How could I have the screen not scroll and just keep the focus where it is?
My js is:
$(function(){
$("a[data-verifying-link]='yes'").click(function(){
// spinner here
a=$(this).parent();
a.html('verifying...');
var id= $(this).data("id");
var row = $(this).data("tableRow");
$.ajax({
url: "/verify_link/"+id+"&table_row="+row,
type: 'GET',
success: function(r) {
$("span#verify_link_"+row).html('<span class="done">Verified</span>');
},
error: function(r) {
$("span#verify_link_"+row).html('<span class="undone">Unverified</span>');
}
});
});
});
Could the issue possibly be related to js I have which puts me on the search field at the top of the page when I visit it?
That is:
$(function(){
$("input[type='text']:first").focus();
});
which is referenced in my manifest:
app/assets/javascripts/application.js://= require default_on_first_input_field
My controller has the following method used by the ajax call.
def verify_link
#link = Link.find(params[:id])
if #link.valid_get?
if #link.update_attribute(:verified_date, Time.now)
render nothing: true, status: 200
else
render nothing: true, status: 422
end
else
render nothing: true, status: 422
end
end
You need to cancel the event:
$(function(){
$("a[data-verifying-link]='yes'").click(function(event){
event.preventDefault();
// spinner here
a=$(this).parent();
a.html('verifying...');
var id= $(this).data("id");
var row = $(this).data("tableRow");
$.ajax({
url: "/verify_link/"+id+"&table_row="+row,
type: 'GET',
success: function(r) {
$("span#verify_link_"+row).html('<span class="done">Verified</span>');
},
error: function(r) {
$("span#verify_link_"+row).html('<span class="undone">Unverified</span>');
}
});
});
});
event.preventDefault is your friend in this case:
$(function(){
$("a[data-verifying-link]='yes'").click(function(){
event.preventDefault();
.........

issue using simpleDialogue2

I'm trying to create a simpleDialog2 using the code below:
function deleteItem(itemID) {
$('<div>').simpledialog2({
mode: 'button',
headerText: 'Are you sure?',
headerClose: true,
// buttonPrompt: 'Please Choose One',
buttons : {
'Delete': {
click: function () {
//$('#buttonoutput').text('OK');
}
},
icon: "delete",
'Cancel': {
click: function () {
// $('#buttonoutput').text('Cancel');
},
theme: "c"
}
}
})
}
And I get this error every time TypeError: 'undefined' is not a function (evaluating '$('<div>').simpledialog2') And help you can provide would be most appreciated.
My issue was actually that I hadn't imported the simpleDialog2 statements in the correct order, as this page outlines.

Zend Framework Ajax Link to work with jQuery Dialog Box

I have tried now the last 3 weeks to get a ajaxLink to work with a jQuery Dialog Box. I have a delete Bookmark Function and want that a dialog Box appears, where you have to confirm that you want to delete the Bookmark, before the Ajax Request is fired and deletes the Bookmark.
I assume that I have to add something to the beforeSend function, but I can not figure out what needs to be written in it. Could someone advice what I need to do? I hope someone knows the answer, I run out of ideas. Thank you very much in advance !
Here my sourcecode so far:
echo $this->ajaxLink("Remove Bookmark","/bookmark/remove/article ".$this->escape($entry->id),
array(
'id' => '',
'class' => 'btn orange delete dialog-confirm',
'dataType'=>'JSON',
'method' => 'post',
'update' => '.bookmark',
'beforeSend' => '????',
'complete' => '$("."+data+"").remove();if ($(".watchlist").length == 0){$(".watch").append("<p>No items watched</p>")}'
));
And my jQuery Dialog Box:
$('.dialog-confirm').click(function(e){
e.preventDefault();
var URL = $(this).attr("href");
$(this).css('display','block');
$('#dialogbox').dialog({
resizable: false,
height:180,
width:350,
modal: true,
closeOnEscape: true,
buttons: {
"Yes, delete bookmark": function() {
window.location.href = URL;
return true;
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
Your Ajax request must be triggered only if a user click on the "Yes, delete bookmark" button. Therefore, you need to add to this button function a jQuery ajax function and remove your first ajaxLink().
//in your view.phtml
<div id="dialogbox" style="display:none">Do you really want to remove this bookmark?</div>
<span style="cursor:pointer" class="btn orange delete dialog-confirm" id="1">Remove Bookmark</span>
<?php $this->jQuery()->addOnload('
$(function() {
var id;
$("#dialogbox").dialog({
resizable: false,
height:180,
width:350,
modal: true,
buttons: {
"Yes, delete bookmark": function() {
$.ajax({
type: "POST",
url: "/bookmark/remove/article",
dataType: "json",
data: "id="+id,
success: function(data, textStatus, jqXHR) {
$("."+data+"").remove();
if ($(".watchlist").length == 0) {
$(".watch").append("<p>No items watched</p>")
}
}
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
});
$(".delete").click(function(e) {
id = this.id;
console.log(id);
$( "#dialogbox" ).dialog( "open" );
});
});
'); ?>
Now, if you click on Remove Bookmark, it displays a jQuery Dialog with two buttons: Cancel and "Yes, delete bookmark", and once you click on yes, it calls an jQuery.ajax function and send the id to /bookmark/remove/article as a parameter.

Remove all gmaps marker on jquery remove button

I use jquery-UI-map for gmaps, and i want to make popup when i click the maps on Gmaps.
$(function() {
$('#map_canvas').gmap( {'center': new google.maps.LatLng(-0.789275, 113.921327), 'callback': function(map) {
$(map).click( function(event) {
$('#map_canvas').gmap('addMarker', {'position': event.latLng, 'title': '', 'draggable': true, 'bound': false}, function(map, marker) {
$('#test').dialog({'modal':true, 'title': 'Edit and save point', 'buttons': {
"Remove": function() {
$(this).dialog( "close" );
$(map).setMap(null);
},
"Save": function() {
$(this).dialog( "close" );
}
}});
findLocation(marker.getPosition(), marker);
}).dragend( function(event) {
var self = this;
findLocation(event.latLng, this);
}).click( function() {
openDialog(this);
})
});
}});
I want to remove all marker when i click remove button in this code :
"Remove": function() {
$(this).dialog( "close" );
$(map).setMap(null);}
But the marker still remain, someone please help me. Thank you
in plugin version 3 one should use:
$('#map_canvas').gmap('clear', 'markers');
You should call
$('#map_canvas').gmap('clearMarkers');
Haven't worked with that plugin before but a quick glance at the API docs seems to suggest that this might work:
"Remove": function() {
$(this).dialog( "close" );
$(map).clearMarkers();
}

Update another control after successful jeditable submit

I am using jEditable to update a value on my MVC model and back to the database successfully. The updated value appears on the webpage which is exactly what I want. I also want to update another control on the page (as it is a calculated value using the updated field). What is the best way to do this? Is there a hook into a successful jEditable update that I can add some jQuery into to refresh the other control?
My jEditable call :
$(function () {
$(".editable_textarea").editable("#Url.Action("UpdateSharePrice","Home")", {
indicator: "<span style='color:#FF0000;'>Saving...</span>",
type: 'text',
submitdata: { _method: "put" },
select: true,
submit: 'OK',
cancel: 'X',
width: '40',
cssclass: "editable",
tooltip: 'click to edit...',
onblur: "submit"
});
});
Thanks
Colin.
Well, I figured it out in the end
You can use the JEditable callback method to get the parameters used to call the controller method:
$(function () {
$(".editable_textarea").editable("#Url.Action("UpdateSharePrice","Home")", {
indicator: "<span style='color:#FF0000;'>Saving...</span>",
type: 'text',
select: true,
submit: 'OK',
cancel: 'X',
width: '40',
cssclass: "editable",
tooltip: 'click to edit...',
onblur: "submit",
callback: function(value, settings)
{
var fundId = this.id;
$.ajax({
url: '#Url.Action("GetMarketValue", "Home")',
type: 'POST',
data: { id : fundId },
success: function (data) {
$('#marketValueDiv_' + fundId).html(data);
}
});
}
});
});
This parameter can then be used to do an ajax post to another action method that returns the calculated field from the model:
public ActionResult GetMarketValue(int id)
{
if (ModelState.IsValid && id > 0)
{
BaseFund targetFund = _context.Funds.Find(id);
return PartialView("GetMarketValue", targetFund);
}
else
{
return PartialView("0.00");
}
}
The success callback on the ajax call is then used to update the appropriate div html content

Resources