PDA

View Full Version : Help please



pav-pas
20 Sep 2009, 11:19 PM
Question 1:
Why variables assign values but are not assigned to appropriate fields: (All these variables in a code are selected (dark blue colour with underline), starting from the declaration of variables before usage) it where variables should be assigned to fields.

Question 2:
Why if in string 73 to remove {width: 140} in Firefox the design of the form will fail, and in Internet Explorer all works perfectly and if it is possible at once tell where still nuances of operation in Firefox and Explorer.

More low I result a code:

doc.html


<html>
<head>
<title>Getting Started Example</title>
<link rel="stylesheet" type="text/css"
href="ext/ext-3.0-rc2/resources/css/ext-all.css" />
<script src="ext-base.js"></script>
<script src="ext/ext-3.0-rc2/ext-all-debug.js"></script>
<script src="ext/ext-3.0-rc2/ext-all.js"></script>
<script src="question.js"></script>
</head>
<body>
<div id="grid" align="center"></div>
<!--<div id='my_id' style='width:200px;height:200px;'>test</div>
Nothing in the body -->
</body>
</html>data.php


<?php
$dblocation = "localhost";
$dbuser = "root";
$dbpasswd = "";
$db = "note";
$con = mysql_connect($dblocation, $dbuser, $dbpasswd);
if (!$con)
{
exit("<P> Can not connected </P>");
}
else
{
mysql_select_db($db, $con);
mysql_query("set names 'utf8'");
}

$res = mysql_query('select name, surname, lastname from employes');
while ($obj = mysql_fetch_array($res))
$arr[] = $obj;
echo '{rows:'.json_encode($arr).'}';
?>

question.js


Ext.onReady(function(){
var win;
var URL;
var mth;
var surname;
var name;
var lastname;
var SText;

var storegrid = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['id', 'surname', 'name', 'lastname'],
root: 'rows'
}),
proxy: new Ext.data.HttpProxy({
url: 'data.php'
}),
autoLoad: true
});

var LeftCol = {
xtype:'container',
region: 'west',
closable:true,
defaults: {xtype: 'container',style: {padding: '5px 0px 0px 0px'}},
items: [{
defaultType: 'textfield',
layout: 'form',
items: [{
fieldLabel: '<font color="red"><b>*</b></font>surname',
name: 'surname',
allowBlank:false,
maxLength: 50,
value: surname
},{
fieldLabel: '<font color="red"><b>*</b></font>name',
name: 'name',
allowBlank:false,
maxLength: 50,
value: name
},{
fieldLabel: '<font color="red"><b>*</b></font>lastname',
name: 'lastname',
allowBlank:false,
maxLength: 50,
value: lastname
}]
}]
}


var CenterCol = {
xtype:'tabpanel',
activeTab: 0,
region: 'center',
plain:true,
defaults:{bodyStyle:'padding:5px'},
items: [{
title: 'Tab 1',
html: 'A simple tab'
},{
title: 'Tab 2',
html: 'Another one'
}]
}

var form = {
xtype:'form',
id: 'simple',
labelAlign: 'top',
buttonAlign:'right',
frame:true,
defaults: {width: 140,style: {padding: '5px'}}, //Error design
region: 'center',
layout:'border',
width: 600,
method : mth,
items:[LeftCol,CenterCol],
buttons: [{
text: SText,
width:70,
type:'submit',
handler: function(){
if(Ext.getCmp('simple').getForm().isValid()) {
Ext.getCmp('simple').getForm().submit({
url: URL,
success: function(){
win.close();
win = null;
storegrid.reload();
}
});
}
}
},{
text: 'Cancel',
type: 'reset',
handler: function(){
Ext.getCmp('simple').getForm().reset();
}
},{
text: 'Close',
handler: function(){
win.close();
win = null;
}
}]
}

var tb1 = new Ext.Toolbar({
items: [{
xtype: 'tbbutton',
text: 'Append',
tooltip :'Append new record',
tooltipType : 'title',
handler: function (){

if(!win){
URL='php/add.php';
mth='POST';
SText='Append';
win = new Ext.Window({
title: 'Append new record',
width:600,
height:470,
plain:true,
layout: 'border',
closable: false,
resizable: false,
modal: true,
items: form
});
}
win.show();
}
},{
xtype: 'tbbutton',
text: 'Edit',
tooltip :'Edit current record',
tooltipType : 'title',
handler: function (){
var rec = grid.getSelectionModel().getSelected();
if (!rec){
Ext.Msg.alert('warning','not selected record');
return false;
}
else
{
surname = rec.get('surname');
name = rec.get('name');
lastname = rec.get('lastname');
idrec=rec.get('id');
SText='Save';

if(!win){
URL='php/edit.php?id='+idrec;
mth='GET';
win = new Ext.Window({
title: 'Edit current record',
width:600,
height:470,
plain:true,
layout: 'border',
closable: false,
resizable: false,
modal: true,
items: form
});
}
win.show();
}
}
},{
xtype: 'tbbutton',
text: 'Delete',
tooltip :'Delete current record',
tooltipType : 'title',
handler: function (){
var rec = grid.getSelectionModel().getSelected();

if (!rec){
Ext.Msg.alert('warning','not selected record');
return false;
} else {
Ext.Msg.show({
title: 'Warning',
msg: 'You really wish to delete record',
buttons: {
yes: 'Delete',
cancel: 'Cancel'
},
fn: function(btn) {
switch(btn){
case 'yes':

var idrec = rec.get('id');
var conn = new Ext.data.Connection();

conn.request({
url: 'php/delete.php?id='+idrec,
success: function(){
grid.store.remove(rec);
}
});

}
}
});
}
}
},{
xtype: 'tbbutton',
text: 'Report',
tooltip :'Generate report',
tooltipType : 'title'
},{
xtype: 'tbbutton',
text: 'Exit',
tooltip :'Exit from software',
tooltipType : 'title',
handler: function (){
top.location.href='exit.php';
}
}]
});

Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

var grid = new Ext.grid.GridPanel({
store: storegrid,
columns: [
{id:'id',dataIndex: 'id',hidden:true},
{id:'surname',header: "surname", width: 250, sortable: true, dataIndex: 'surname'},
{id:'name',header: "name", width: 250, sortable: true, dataIndex: 'name'},
{id:'lastname',header: "lastname", width: 250, sortable: true, dataIndex: 'lastname'}
],
stripeRows: true,
autoExpandColumn: 'surname',
height:document.body.clientHeight,
width:document.body.clientWidth,
tbar:tb1
});

grid.render('grid');
});I ask to explain in what for me errors

pav-pas
20 Sep 2009, 11:20 PM
question.js

Ext.onReady(function(){
var win;
var URL;
var mth;
var surname;
var name;
var lastname;
var SText;

var storegrid = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['id', 'surname', 'name', 'lastname'],
root: 'rows'
}),
proxy: new Ext.data.HttpProxy({
url: 'data.php'
}),
autoLoad: true
});

var LeftCol = {
xtype:'container',
region: 'west',
closable:true,
defaults: {xtype: 'container',style: {padding: '5px 0px 0px 0px'}},
items: [{
defaultType: 'textfield',
layout: 'form',
items: [{
fieldLabel: '<font color="red"><b>*</b></font>surname',
name: 'surname',
allowBlank:false,
maxLength: 50,
value: surname
},{
fieldLabel: '<font color="red"><b>*</b></font>name',
name: 'name',
allowBlank:false,
maxLength: 50,
value: name
},{
fieldLabel: '<font color="red"><b>*</b></font>lastname',
name: 'lastname',
allowBlank:false,
maxLength: 50,
value: lastname
}]
}]
}


var CenterCol = {
xtype:'tabpanel',
activeTab: 0,
region: 'center',
plain:true,
defaults:{bodyStyle:'padding:5px'},
items: [{
title: 'Tab 1',
html: 'A simple tab'
},{
title: 'Tab 2',
html: 'Another one'
}]
}

var form = {
xtype:'form',
id: 'simple',
labelAlign: 'top',
buttonAlign:'right',
frame:true,
defaults: {width: 140,style: {padding: '5px'}},
region: 'center',
layout:'border',
width: 600,
method : mth,
items:[LeftCol,CenterCol],
buttons: [{
text: SText,
width:70,
type:'submit',
handler: function(){
if(Ext.getCmp('simple').getForm().isValid()) {
Ext.getCmp('simple').getForm().submit({
url: URL,
success: function(){
win.close();
win = null;
storegrid.reload();
}
});
}
}
},{
text: 'Cancel',
type: 'reset',
handler: function(){
Ext.getCmp('simple').getForm().reset();
}
},{
text: 'Close',
handler: function(){
win.close();
win = null;
}
}]
}

var tb1 = new Ext.Toolbar({
items: [{
xtype: 'tbbutton',
text: 'Append',
tooltip :'Append new record',
tooltipType : 'title',
handler: function (){

if(!win){
URL='php/add.php';
mth='POST';
SText='Append';
win = new Ext.Window({
title: 'Append new record',
width:600,
height:470,
plain:true,
layout: 'border',
closable: false,
resizable: false,
modal: true,
items: form
});
}
win.show();
}
},{
xtype: 'tbbutton',
text: 'Edit',
tooltip :'Edit current record',
tooltipType : 'title',
handler: function (){
var rec = grid.getSelectionModel().getSelected();
if (!rec){
Ext.Msg.alert('warning','not selected record');
return false;
}
else
{
surname = rec.get('surname');
name = rec.get('name');
lastname = rec.get('lastname');
idrec=rec.get('id');
SText='Save';

if(!win){
URL='php/edit.php?id='+idrec;
mth='GET';
win = new Ext.Window({
title: 'Edit current record',
width:600,
height:470,
plain:true,
layout: 'border',
closable: false,
resizable: false,
modal: true,
items: form
});
}
win.show();
}
}
},{
xtype: 'tbbutton',
text: 'Delete',
tooltip :'Delete current record',
tooltipType : 'title',
handler: function (){
var rec = grid.getSelectionModel().getSelected();

if (!rec){
Ext.Msg.alert('warning','not selected record');
return false;
} else {
Ext.Msg.show({
title: 'Warning',
msg: 'You really wish to delete record',
buttons: {
yes: 'Delete',
cancel: 'Cancel'
},
fn: function(btn) {
switch(btn){
case 'yes':

var idrec = rec.get('id');
var conn = new Ext.data.Connection();

conn.request({
url: 'php/delete.php?id='+idrec,
success: function(){
grid.store.remove(rec);
}
});

}
}
});
}
}
},{
xtype: 'tbbutton',
text: 'Report',
tooltip :'Generate report',
tooltipType : 'title'
},{
xtype: 'tbbutton',
text: 'Exit',
tooltip :'Exit from software',
tooltipType : 'title',
handler: function (){
top.location.href='exit.php';
}
}]
});

Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

var grid = new Ext.grid.GridPanel({
store: storegrid,
columns: [
{id:'id',dataIndex: 'id',hidden:true},
{id:'surname',header: "surname", width: 250, sortable: true, dataIndex: 'surname'},
{id:'name',header: "name", width: 250, sortable: true, dataIndex: 'name'},
{id:'lastname',header: "lastname", width: 250, sortable: true, dataIndex: 'lastname'}
],
stripeRows: true,
autoExpandColumn: 'surname',
height:document.body.clientHeight,
width:document.body.clientWidth,
tbar:tb1
});

grid.render('grid');
});

I ask to explain in what for me errors