Advertisement
Guest User

Untitled

a guest
May 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.18 KB | None | 0 0
  1. //Global vars
  2. var UtilisateursDataStore;
  3. var UtilisateursColumnModel;
  4. var UtilisateurListingEditorGrid;
  5. var UtilisateurListingWindow;
  6. //Our new vars
  7. var UtilisateurCreateForm;
  8. var UtilisateurCreateWindow;
  9. var PrenomField;
  10. var NomField;
  11. var TypeField;
  12. var Username;
  13. var Password;
  14. var PartyField;
  15. var viewport;
  16.  
  17. var layer,map;
  18.  
  19.  
  20. var currentFrame;
  21.  
  22.  
  23.  
  24.  
  25. Ext.onReady(function(){
  26.  
  27. Ext.QuickTips.init();
  28.  
  29.  
  30.  
  31. ///////////////////////////// grid user ////////////////////////////////:
  32. // This saves the utilisateur after a cell has been edited
  33. function saveTheUtilisateur(oGrid_event){
  34. Ext.Ajax.request({
  35. waitMsg: 'Please wait...',
  36. url: 'php/database_user.php',
  37. params: {
  38. task: "UPDATEPRES",
  39. ID_UTILISATEUR: oGrid_event.record.data.ID_UTILISATEUR,
  40. prenom: oGrid_event.record.data.Prenom,
  41. nom: oGrid_event.record.data.Nom,
  42. type: oGrid_event.record.data.Type,
  43. username: oGrid_event.record.data.Username,
  44. password: oGrid_event.record.data.Password
  45. },
  46. success: function(response){
  47. var result=eval(response.responseText);
  48. switch(result){
  49. case 1:
  50. UtilisateursDataStore.commitChanges();
  51. UtilisateursDataStore.reload();
  52. break;
  53. default:
  54. Ext.MessageBox.alert('Uh uh...','We couldn\'t save him...');
  55. break;
  56. }
  57. },
  58. failure: function(response){
  59. var result=response.responseText;
  60. Ext.MessageBox.alert('error','could not connect to the database. retry later');
  61. }
  62. });
  63. }
  64.  
  65. // this creates a new utilisateur
  66. function createTheUtilisateur(){
  67. if(isUtilisateurFormValid()){
  68. Ext.Ajax.request({
  69. waitMsg: 'Please wait...',
  70. url: 'php/database_user.php',
  71. params: {
  72. task: "CREATEPRES",
  73. prenom: PrenomField.getValue(),
  74. nom: NomField.getValue(),
  75. type: TypeField.getValue(),
  76. username: Username.getValue(),
  77. password: Password.getValue()
  78. },
  79. success: function(response){
  80. var result=eval(response.responseText);
  81. switch(result){
  82. case 1:
  83. Ext.MessageBox.alert('Creation OK','The utilisateur was created successfully.');
  84. UtilisateursDataStore.reload();
  85. UtilisateurCreateWindow.hide();
  86. break;
  87. default:
  88. Ext.MessageBox.alert('Warning','Could not create the utilisateur.');
  89. break;
  90. }
  91. },
  92. failure: function(response){
  93. var result=response.responseText;
  94. Ext.MessageBox.alert('error','could not connect to the database. retry later');
  95. }
  96. });
  97. } else {
  98. Ext.MessageBox.alert('Warning', 'Your Form is not valid!');
  99. }
  100. }
  101.  
  102. // reset the Form before opening it
  103. function resetUtilisateurForm(){
  104. PrenomField.setValue('');
  105. NomField.setValue('');
  106. TypeField.setValue('');
  107. Username.setValue('');
  108. Password.setValue('');
  109. }
  110.  
  111. // check if the form is valid
  112. function isUtilisateurFormValid(){
  113. return(PrenomField.isValid() && NomField.isValid() && TypeField.isValid() && Username.isValid() && Password.isValid() );
  114. }
  115.  
  116. // display or bring forth the form
  117. function displayFormWindow(){
  118. if(!UtilisateurCreateWindow.isVisible()){
  119. resetUtilisateurForm();
  120. UtilisateurCreateWindow.show();
  121. } else {
  122. UtilisateurCreateWindow.toFront();
  123. }
  124. }
  125.  
  126. // This was added in Tutorial 6
  127. function confirmDeleteUtilisateurs(){
  128. if(UtilisateurListingEditorGrid.selModel.getCount() == 1) // only one utilisateur is selected here
  129. {
  130. Ext.MessageBox.confirm('Confirmation','You are about to delete a utilisateur. Continue?', deleteUtilisateurs);
  131. } else if(UtilisateurListingEditorGrid.selModel.getCount() > 1){
  132. Ext.MessageBox.confirm('Confirmation','Delete those utilisateurs?', deleteUtilisateurs);
  133. } else {
  134. Ext.MessageBox.alert('Uh oh...','You can\'t really delete something you haven\'t selected huh?');
  135. }
  136. }
  137. // This was added in Tutorial 6
  138. function deleteUtilisateurs(btn){
  139. if(btn=='yes'){
  140. var selections = UtilisateurListingEditorGrid.selModel.getSelections();
  141. var prez = [];
  142. for(i = 0; i< UtilisateurListingEditorGrid.selModel.getCount(); i++)
  143. prez.push(selections[i].json.ID_UTILISATEUR);
  144.  
  145. var encoded_array = Ext.encode(prez);
  146. Ext.Ajax.request({
  147. waitMsg: 'Please Wait',
  148. url: 'php/database_user.php',
  149. params: {
  150. task: "DELETEPRES",
  151. ids: encoded_array
  152. },
  153. success: function(response){
  154. var result=eval(response.responseText);
  155. switch(result){
  156. case 1: // Success : simply reload
  157. UtilisateursDataStore.reload();
  158. break;
  159. default:
  160. Ext.MessageBox.alert('Warning','Could not delete the entire selection.');
  161. break;
  162. }
  163. },
  164. failure: function(response){
  165. var result=response.responseText;
  166. Ext.MessageBox.alert('error','could not connect to the database. retry later');
  167. }
  168. });
  169. }
  170. }
  171.  
  172.  
  173. // << CONFIG >>
  174. UtilisateursDataStore = new Ext.data.Store({
  175. id: 'UtilisateursDataStore',
  176. proxy: new Ext.data.HttpProxy({
  177. url: 'php/database_user.php',
  178. method: 'POST'
  179. }),
  180. baseParams:{task: "LISTING"}, // this parameter is passed for any HTTP request
  181. reader: new Ext.data.JsonReader({
  182. root: 'results',
  183. totalProperty: 'total',
  184. id: 'id'
  185. },[
  186. {name: 'ID_UTILISATEUR', type: 'int', mapping: 'ID_UTILISATEUR'},
  187. {name: 'Prenom', type: 'string', mapping: 'PRENOM'},
  188. {name: 'Nom', type: 'string', mapping: 'NOM'},
  189. {name: 'Type', type: 'string', mapping: 'TYPE'},
  190. {name: 'Username', type: 'string', mapping: 'USERNAME'},
  191. {name: 'Password', type: 'string', mapping: 'PASSWORD'}
  192. ]),
  193. sortInfo:{field: 'ID_UTILISATEUR', direction: "ASC"}
  194. });
  195.  
  196. UtilisateursColumnModel = new Ext.grid.ColumnModel(
  197. [{
  198. header: '#',
  199. readOnly: true,
  200. dataIndex: 'ID_UTILISATEUR',
  201. width: 40,
  202. hidden: false
  203. },{
  204. header: 'Prenom',
  205. dataIndex: 'Prenom',
  206. width: 60,
  207. editor: new Ext.form.TextField({
  208. allowBlank: false,
  209. maxLength: 20,
  210. maskRe: /([a-zA-Z0-9\s]+)$/
  211. })
  212. },{
  213. header: 'Nom',
  214. dataIndex: 'Nom',
  215. width: 80,
  216. editor: new Ext.form.TextField({
  217. allowBlank: false,
  218. maxLength: 20,
  219. maskRe: /([a-zA-Z0-9\s]+)$/
  220. })
  221. },{
  222. header: 'Accès',
  223. dataIndex: 'Type',
  224. width: 150,
  225. editor: new Ext.form.ComboBox({
  226. typeAhead: true,
  227. triggerAction: 'all',
  228. store:new Ext.data.SimpleStore({
  229. fields:['partyValue', 'partyName'],
  230. data: [['0','USER'],['1','ADMIN']]
  231. }),
  232. mode: 'local',
  233. displayField: 'partyName',
  234. lazyRender:true,
  235. listClass: 'x-combo-list-small'
  236. })
  237. },{
  238. header: 'Username',
  239. dataIndex: 'Username',
  240. width: 80,
  241. editor: new Ext.form.TextField({
  242. allowBlank: false,
  243. maxLength: 20,
  244. maskRe: /([a-zA-Z0-9\s]+)$/
  245. })
  246. },{
  247. header: 'Password',
  248. dataIndex: 'Password',
  249. width: 80,
  250. editor: new Ext.form.TextField({
  251. allowBlank: false,
  252. maxLength: 20,
  253. maskRe: /([a-zA-Z0-9\s]+)$/
  254. })
  255. }]
  256. );
  257. UtilisateursColumnModel.defaultSortable= true;
  258.  
  259. UtilisateurListingEditorGrid = new Ext.grid.EditorGridPanel({
  260. id: 'UtilisateurListingEditorGrid',
  261. store: UtilisateursDataStore,
  262. cm: UtilisateursColumnModel,
  263. enableColLock:false,
  264. region:'center',
  265. clicksToEdit:1,
  266. selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
  267. tbar: [
  268. {
  269. text: 'Ajouter un utilisateur',
  270. tooltip: 'Cliquez sur ce bouton',
  271. iconCls:'add', // reference to our css
  272. handler: displayFormWindow
  273. }, '-', { // Added in Tutorial 6
  274. text: 'Supprimer la selection',
  275. tooltip: 'Cliquez sur ce bouton',
  276. handler: confirmDeleteUtilisateurs, // Confirm before deleting
  277. iconCls:'remove'
  278. }]
  279. });
  280. UtilisateursDataStore.load();
  281. UtilisateurListingEditorGrid.on('afteredit', saveTheUtilisateur);
  282. //////////////////////////////////////////////////////////////////////////////
  283. //////////////////////////////////////////////////////////////////////////////
  284. // form
  285. PrenomField = new Ext.form.TextField({
  286. id: 'PrenomField',
  287. fieldLabel: 'Prenom',
  288. maxLength: 20,
  289. allowBlank: false,
  290. anchor : '95%',
  291. maskRe: /([a-zA-Z0-9\s]+)$/
  292. });
  293.  
  294. NomField = new Ext.form.TextField({
  295. id: 'NomField',
  296. fieldLabel: 'Nom',
  297. maxLength: 20,
  298. allowBlank: false,
  299. anchor : '95%',
  300. maskRe: /([a-zA-Z0-9\s]+)$/
  301. });
  302.  
  303. TypeField = new Ext.form.ComboBox({
  304. id:'TypeField',
  305. fieldLabel: 'Type',
  306. store:new Ext.data.SimpleStore({
  307. fields:['partyValue', 'partyName'],
  308. data: [['0','USER'],['1','ADMIN']]
  309. }),
  310. mode: 'local',
  311. displayField: 'partyName',
  312. allowBlank: false,
  313. anchor:'95%',
  314. triggerAction: 'all'
  315. });
  316.  
  317. Username = new Ext.form.TextField({
  318. id:'Username',
  319. fieldLabel: 'UserName',
  320. maxLength: 20,
  321. allowBlank: false,
  322. anchor : '95%',
  323. maskRe: /([a-zA-Z0-9\s]+)$/
  324. });
  325.  
  326. Password = new Ext.form.TextField({
  327. id:'password',
  328. fieldLabel: 'Password',
  329. allowNegative: false,
  330. allowBlank: false,
  331. anchor:'95%'
  332. });
  333.  
  334.  
  335.  
  336. UtilisateurCreateForm = new Ext.FormPanel({
  337. labelAlign: 'top',
  338. bodyStyle:'padding:5px',
  339. width: 600,
  340. items: [{
  341. layout:'column',
  342. border:false,
  343. items:[{
  344. columnWidth:0.5,
  345. layout: 'form',
  346. border:false,
  347. items: [PrenomField, NomField,TypeField]
  348. },{
  349. columnWidth:0.5,
  350. layout: 'form',
  351. border:false,
  352. items: [Username, Password]
  353. }]
  354. }],
  355. buttons: [{
  356. text: 'Save and Close',
  357. handler: createTheUtilisateur
  358. },{
  359. text: 'Cancel',
  360. handler: function(){
  361. // because of the global vars, we can only instantiate one window... so let's just hide it.
  362. UtilisateurCreateWindow.hide();
  363. }
  364. }]
  365. });
  366.  
  367. UtilisateurCreateWindow= new Ext.Window({
  368. id: 'UtilisateurCreateWindow',
  369. title: 'Creation d\'un nouveau utilisateur',
  370. closable:true,
  371. width: 610,
  372. height: 250,
  373. plain:true,
  374. layout: 'fit',
  375. items: UtilisateurCreateForm
  376. });
  377. ///////////////////////////////////////////////////////////////////////////
  378. ///////////////////////////////////////////////////////////////////////////
  379.  
  380. var options;
  381. //layer = ;
  382. layer = new OpenLayers.Layer.OSM("New Layer","tiles/${z}/${x}/${y}.png" );
  383. map = new OpenLayers.Map();
  384. map.addLayer(layer);
  385. map.setCenter(new OpenLayers.LonLat(7.01602,43.61125) // Center of the map
  386. .transform(
  387. new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
  388. new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
  389. ), 17 // Zoom level
  390. );
  391.  
  392. var mapPanel = new GeoExt.MapPanel({
  393. stateId: "mappanel",
  394. id: 'idmap',
  395. enableColLock:false,
  396. region:'center',
  397. map: map,
  398. center: new OpenLayers.LonLat(7.01602,43.61125) // Center of the map
  399. .transform(
  400. new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
  401. new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
  402. ),
  403. zoom:15
  404. });
  405.  
  406.  
  407.  
  408.  
  409.  
  410. ///////////////////////////////////////////////////////////////////////////
  411. ///////////////////////////////////////////////////////////////////////////
  412. /////// menu
  413. var taskActions = new Ext.Panel({
  414. frame:true,
  415. title: 'Utilisateurs',
  416. collapsible:true,
  417. contentEl:'task-actions',
  418. titleCollapse: true
  419. });
  420. var Cartographie = new Ext.Panel({
  421. frame:true,
  422. title: 'Cartographie',
  423. collapsible:true,
  424. contentEl:'carto-menu',
  425. titleCollapse: true
  426. });
  427. var actionPanel = new Ext.Panel({
  428. id:'action-panel',
  429. region:'west',
  430. split:true,
  431. collapsible: true,
  432. collapseMode: 'mini',
  433. header: false,
  434. width:200,
  435. minWidth: 150,
  436. border: false,
  437. baseCls:'x-plain',
  438. items: [taskActions,Cartographie]
  439. });
  440. ///////////////////////////////////////////////////////////////////////////
  441. ///////////////////////////////////////////////////////////////////////////
  442. //// final
  443. currentFrame="mappanel";
  444. viewport = new Ext.Viewport({
  445. layout:'border',
  446. id: 'mainViewTabs',
  447. // UtilisateurListingEditorGrid
  448. items: [ actionPanel,mapPanel ]
  449. });
  450.  
  451. //////////////////////////////////////////////////////////////////////////
  452. ///////////////////////////////////////////////////////////////////////////
  453. // event menu
  454. var actions_menu = {
  455. 'action-GUtilisateurs' : function(){
  456. viewport= Ext.getCmp('mainViewTabs');
  457. viewport.remove('idmap');
  458. viewport.add(UtilisateurListingEditorGrid);
  459. viewport.doLayout();
  460. },'carto-menu':function(){
  461. if(!currentFrame)
  462. viewport.remove(currentFrame,false);
  463. viewport.doLayout();
  464.  
  465. }
  466.  
  467. };
  468. var ab = actionPanel.body;
  469. ab.on('mousedown', doAction, null, {delegate:'a'});
  470. ab.on('click', Ext.emptyFn, null, {delegate:'a', preventDefault:true});
  471. function doAction(e, t){
  472. e.stopEvent();
  473. actions_menu[t.id]();
  474. }
  475. //////////////////////////////////////////////////////////////////////////
  476. //////////////////////////////////////////////////////////////////////////
  477.  
  478. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement