how to convert following yii js code to yii2 version someone please help…
i have changed small thing but it couldn’t work in my page.
<?php
$this->registerJs(‘formscript’, <<<JAVASCRIPT
var oTable;
$(document).ready(function(){
oTable = $(’#entry_dt’).dataTable({
"sScrollX": "100%",
// "sScrollXInner": "800%",
"bScrollCollapse": true,
"sScrollY": "200px",
});
oTable.fnSetColumnVis( 1, false );
oTable.fnSetColumnVis( 0, false );
/* Add a click handler for the delete row */
$('#entry_dt tr').live('click', function(i) {
var rowindex = oTable.fnGetPosition($(this).closest('tr')[0]);
fnGetSelected( oTable ,rowindex);
});
});
function fnShowHide( iCol )
{
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var oTable = $('#entry_dt').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
if(bVis){ $("#toggle_column_"+iCol).removeClass("selected"); }
else { $("#toggle_column_"+iCol).addClass("selected"); }
}
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal,rindex )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
//alert(rindex);
aData=oTableLocal.fnGetData(rindex);
//alert(aData[1]);
var f_id = aData[0].replace(/<\/?[^>]+(>|$)/g, "");
var e_id = aData[1].replace(/<\/?[^>]+(>|$)/g, "");
$.ajax({
type: "POST",
async: true,
url: entries_view_url,
data: {
id: f_id,
eid: e_id,
},
cache: false,
global: true,
dataType: "html",
error: function (h, f, g) {
},
success: function (e) {
$("#entry_detail").empty();
$("#entry_detail").append(e);
}
})
}
function deleteEntry(f_id,e_id) {
jConfirm(“This action cannot be undone.<br/><strong>All data collected by the form will be deleted as well.</strong><br/><br/>If you are sure with this, you can continue deleting this field.<br /><br />”, ‘Are you sure you want to delete this field?"’, function® {
if®{
$.ajax({
type: "POST",
async: true,
url: entries_delete_url,
data: {
id: f_id,
eid: e_id,
},
cache: false,
global: true,
dataType: "json",
error: function (h, f, g) {
},
success: function (e) {
if(e.status == "ok"){
document.location.reload(true);
}
else {
jAlert("Please try again within few minutes.<br/>unable to reach the server!");
return false;
}
}
})
}
})
}
function emailEntry(f_id,e_id){
$("#fid").val(f_id);
$("#eid").val(e_id);
$( "#dialog-form" ).dialog( "open" );
}
var frm_address = $( "#frm_address" ),
to_address = $( "#to_address" ),
subject = $( "#subject" ),
allFields = $( [] ).add( frm_address ).add( to_address ).add( subject ),
tips = $( ".validateTips" );
function updateTips( t ) {
tips
.text( t )
.addClass( "ui-state-highlight" );
setTimeout(function() {
tips.removeClass( "ui-state-highlight", 1500 );
}, 500 );
}
function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
updateTips( "Length of " + n + " must be between " +
min + " and " + max + "." );
return false;
} else {
return true;
}
}
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/);
bool = pattern.test(emailAddress.val());
if(!bool) return false;
else return true;
}
function checkRegexp( o, regexp, n ) {
if ( !( regexp.test( o.val() ) ) ) {
o.addClass( "ui-state-error" );
updateTips( n );
return false;
} else {
return true;
}
}
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"sendMail": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
bValid = bValid && checkLength( frm_address, "From Address", 2, 80 );
bValid = bValid && checkLength( to_address, "To Address", 2, 80 );
bValid = bValid && checkLength( subject, "Subject", 2, 30 );
bValid = bValid && isValidEmailAddress(frm_address);
bValid = bValid && isValidEmailAddress(to_address);
bValid = bValid && checkRegexp( subject, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
if ( bValid ) {
$.ajax({
type: "POST",
async: true,
url: email_url,
data: {
from_address: $("#frm_address").val(),
to_address: $("#to_address").val(),
subject: $("#subject").val(),
id: $("#fid").val(),
eid: $("#eid").val()
},
cache: false,
global: true,
dataType: "json",
error: function (h, f, g) {
},
success: function (e) {
}
})
$( this ).dialog( "close" );
}
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
function showColumnTitle(){
if($("#showColumn").is(":visible")){
$("#showColumn").hide();
}
else {
$("#showColumn").show();
}
}
function columnTitle() {
$("#showColumn").hide();
}
function showEntryView(f_id,e_id){
$.ajax({
type: "POST",
async: true,
url: entries_view_url,
data: {
id: f_id,
eid: e_id,
},
cache: false,
global: true,
dataType: "html",
error: function (h, f, g) {
},
success: function (e) {
$("#entry_detail").empty();
$("#entry_detail").append(e);
}
})
}
JAVASCRIPT
, View::POS_END);
?>