1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
| /**
* @author renoultg
*/
Ext.onReady(function() {
var HTTPProxy = new Ext.data.HttpProxy({
prettyUrls:false,
api:{
create:{url:'data/personnes_save.php',method:'GET'},
read: {url : 'data/personnes.php', method:'GET'},
destroy: {url : 'data/personnes_delete.php', method:'GET'},
update: {url : 'data/personnes_update.php', method:'GET'}
}
});
// Remplissage du storage
var stockage = new Ext.data.Store({
proxy: HTTPProxy,
autoSave: true,
paramsAsHash: true,
reader : new Ext.data.JsonReader({
root:'items',
fields:[
{name:'stk_nom',mapping:'nom'},
{name:'stk_prenom',mapping:'prenom'},
{name:'stk_telephone',mapping:'telephone'}
]
}),
writer : new Ext.data.JsonWriter({
encode:true,
writeAllFields:true
}),
listeners:{
exception:function(dataproxy,type,action,option,response,mix){
//alert(listObj(mix));
alert("dataproxy : "+dataproxy+"\ntype : "+type+"\naction : "+action+"\noption : "+option+"\nresponse : "+response+"\nmix : "+mix);
}
}
});
stockage.load();
var PersonnesGrid = new Ext.grid.EditorGridPanel({
store: stockage,
renderTo: 'contenu',
width: 355,
height: 400,
title: 'Annuaire',
stripeRows: true,
autoExpand: true,
autoExpandColumn: 'col_nom',
columns : [
{ header:'Nom',
dataIndex:'stk_nom',
sortable: true,
id:'col_nom',
editor: new Ext.form.TextField({
allowBlank:false,
maxLength: 32
})
},
{ header:'Prénom',
dataIndex:'stk_prenom',
sortable: true,
width:120,
editor: new Ext.form.TextField({
allowBlank:false,
maxLength: 32
})
},
{ header:'Numéro',
dataIndex:'stk_telephone',
sortable: true,
width:120,
editor : new Ext.form.TextField ({
allowBlank:false,
maxLength:10
})
},
{
header: 'Supprimer',
sortable: false,
xtype: 'actioncolumn',
icon: 'images/delete.png',
width: 60,
align: 'center',
handler: function(grid, rowIndex, colIdex, item, e) {
Ext.MessageBox.show({
title:'Confirmation',
msg: 'Souhaitez-vous supprimer cette personne de l\'annuaire ?',
buttons: Ext.MessageBox.YESNO,
icon: Ext.MessageBox.QUESTION,
fn: function(boutton){
if (boutton == "yes") {
stockage.removeAt(rowIndex);
PersonnesGrid.syncSize();
}
}
});
}
}
],
tbar:[{
text: 'Ajouter un concact',
icon: 'images/add.png',
handler: Nouveau,
scope: this
}]
});
var winForm;
function Nouveau() {
if (!winForm){
winForm = new Ext.Window({
applyTo:'boite',
layout:'fit',
width:500,
heigh:300,
closeAction:'hide',
plain:true,
items:contactForm,
buttons:[{
text:'Ajouter',
handler:function(){
var rec = new stockage.recordType();
rec.set('stk_nom',Ext.get('nom').getValue());
rec.set('stk_prenom',Ext.get('prenom').getValue());
rec.set('stk_telephone',Ext.get('telephone').getValue());
stockage.add(rec);
PersonnesGrid.syncSize();
contactForm.getForm().reset();
winForm.hide(); }
},{
text:'Annuler',
handler:function(){
winForm.hide();
}
}]
})
} winForm.show(this);
};
var contactForm = new Ext.FormPanel({
labelWidth: 75,
frame: true,
title: 'Ajouter un contact',
bodyStyle: 'padding: 5px 5px 0',
width: 350,
height:200,
defaults:{width: 230},
defaultType: 'textfield',
items:[{
fieldLabel: 'Nom',
id:'nom',
allowBlank: false
},{
fieldLabel: 'Prenom',
id:'prenom',
allowBlank: false
},{
fieldLabel: 'Téléphone',
id:'telephone',
allowBlank: false
}]
});
var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Chargement en cours...", store:stockage});
myMask.show();
});// Fin du onReady |
Partager