Commit d29ffebdfd065cb088b2d3c504a0d68d9096717c
1 parent
a743e591
Exists in
master
and in
2 other branches
user add optimisation (moins de ldap...)
Showing
3 changed files
with
82 additions
and
379 deletions
Show diff stats
src/Controller/MaterielsController.php
... | ... | @@ -1056,166 +1056,7 @@ class MaterielsController extends AppController |
1056 | 1056 | * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. |
1057 | 1057 | */ |
1058 | 1058 | public function add($valeurs = null, $erreurs = null) { $this->add_or_edit(TRUE, null, $valeurs, $erreurs); } |
1059 | - /* | |
1060 | - { | |
1061 | - $usersTable = TableRegistry::getTableLocator()->get('Users'); | |
1062 | - $materiel = $this->Materiels->newEntity(); | |
1063 | - | |
1064 | - // Nouveau materiel saisi et posted | |
1065 | - if ($this->request->is('post')) { | |
1066 | - // (1) On rempli $materiel avec les données de ce materiel | |
1067 | - $materiel = $this->Materiels->patchEntity($materiel, $this->request->getData()); | |
1068 | - // (2) Si l'utilisateur courant est un "administratif" => le mettre comme gestionnaire du materiel | |
1069 | - // (tout ça pour ça !!! Faudra réduire ce bazarre) | |
1070 | - $current_user_name = $_SESSION['Auth']['User']['sn'][0]; | |
1071 | - if (in_array( | |
1072 | - $current_user_name, | |
1073 | - $usersTable | |
1074 | - ->find('list', [ | |
1075 | - 'keyField' => 'id', | |
1076 | - 'valueField' => 'nom' | |
1077 | - ]) | |
1078 | - ->where([ | |
1079 | - 'role =' => 'Administration' | |
1080 | - ]) | |
1081 | - ->toArray() | |
1082 | - )) { | |
1083 | - $materiel->gestionnaire_id = $usersTable | |
1084 | - ->find() | |
1085 | - ->where([ | |
1086 | - 'nom' => $current_user_name | |
1087 | - ]) | |
1088 | - ->first()->id; | |
1089 | - } | |
1090 | - // (3) On l'ajoute en BD | |
1091 | - if ($this->Materiels->save($materiel)) { | |
1092 | - $this->Flash->success(__('Le matériel a bien été ajouté.')); | |
1093 | - $this->sendEmail($materiel); | |
1094 | - return $this->redirect([ | |
1095 | - 'action' => 'view', | |
1096 | - $materiel->id | |
1097 | - ]); | |
1098 | - } else | |
1099 | - $this->Flash->error(__('Le matériel n\'a pas pu être ajouté.')); | |
1100 | - } | |
1101 | - | |
1102 | - // Dans tous les cas (posted ou pas) | |
1103 | - $surCategories = $this->Materiels->SurCategories->find('list', [ | |
1104 | - 'keyField' => 'id', | |
1105 | - 'valueField' => 'nom', | |
1106 | - 'order' => 'SurCategories.nom', | |
1107 | - 'conditions' => array( | |
1108 | - 'nom !=' => 'N/A' | |
1109 | - ) | |
1110 | - ]); | |
1111 | - $categories = $this->Materiels->Categories->find('list', [ | |
1112 | - 'keyField' => 'id', | |
1113 | - 'valueField' => 'nom', | |
1114 | - 'order' => 'Categories.nom' | |
1115 | - ]); | |
1116 | - $sousCategories = $this->Materiels->SousCategories->find('list', [ | |
1117 | - 'keyField' => 'id', | |
1118 | - 'valueField' => 'nom', | |
1119 | - 'order' => 'SousCategories.nom' | |
1120 | - ]); | |
1121 | - $groupesThematiques = $this->Materiels->GroupesThematiques->find('list', [ | |
1122 | - 'keyField' => 'id', | |
1123 | - 'valueField' => 'nom', | |
1124 | - 'order' => 'GroupesThematiques.nom' | |
1125 | - ]); | |
1126 | - $groupesMetiers = $this->Materiels->GroupesMetiers->find('list', [ | |
1127 | - 'keyField' => 'id', | |
1128 | - 'valueField' => 'nom', | |
1129 | - 'order' => 'GroupesMetiers.nom' | |
1130 | - ]); | |
1131 | - $organismes = $this->Materiels->Organismes->find('list', [ | |
1132 | - 'keyField' => 'id', | |
1133 | - 'valueField' => 'nom', | |
1134 | - 'order' => 'Organismes.nom' | |
1135 | - ]); | |
1136 | - $sites = $this->Materiels->Sites->find('list', [ | |
1137 | - 'keyField' => 'id', | |
1138 | - 'valueField' => 'nom', | |
1139 | - 'order' => 'Sites.nom' | |
1140 | - ]); | |
1141 | - $fournisseurs = $this->Materiels->Fournisseurs->find('list', [ | |
1142 | - 'keyField' => 'id', | |
1143 | - 'valueField' => 'nom', | |
1144 | - 'order' => 'Fournisseurs.nom' | |
1145 | - ]); | |
1146 | - $lieu_detail = $this->Materiels->find('list', [ | |
1147 | - 'keyField' => 'lieu_detail', | |
1148 | - 'valueField' => 'lieu_detail', | |
1149 | - 'conditions' => array( | |
1150 | - 'lieu_detail !=' => '' | |
1151 | - ), | |
1152 | - 'order' => 'lieu_detail', | |
1153 | - 'group' => 'lieu_detail' | |
1154 | - ]); | |
1155 | - $designation = $this->Materiels->find('list', [ | |
1156 | - 'keyField' => 'designation', | |
1157 | - 'valueField' => 'designation', | |
1158 | - 'conditions' => array( | |
1159 | - 'designation !=' => '' | |
1160 | - ), | |
1161 | - 'order' => 'designation', | |
1162 | - 'group' => 'designation' | |
1163 | - ]); | |
1164 | - $domaineresp = $usersTable->find() | |
1165 | - ->select('sur_categorie_id') | |
1166 | - ->where([ | |
1167 | - 'username =' => $this->LdapAuth->user($this->request->getSession() | |
1168 | - ->read('authType'))[0] | |
1169 | - ]) | |
1170 | - ->first()['sur_categorie_id']; | |
1171 | - if ($domaineresp == null) | |
1172 | - $domaineresp = false; | |
1173 | - $utilisateurconnect = $usersTable->find('all')->toArray(); | |
1174 | - | |
1175 | - // TODO: code redondant avec edit(), à factoriser | |
1176 | - // HOWTO: https://book.cakephp.org/3.0/en/orm.html | |
1177 | - //$users = TableRegistry::get('LdapConnections')->getListUsers(); | |
1178 | - //$users = TableRegistry::get('LdapConnections')->getUsersWithNameAndEmail(); | |
1179 | - $users_name_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
1180 | - $users_name = array_keys($users_name_and_email); | |
1181 | - $users_option_list = []; | |
1182 | - for ($i = 0; $i < sizeof($users_name); $i ++) { | |
1183 | - // $users_option_list["Etienne Pallier"] = "Etienne Pallier" | |
1184 | - $users_option_list[$users_name[$i]] = $users_name[$i]; | |
1185 | - } | |
1186 | - // no more needed | |
1187 | - $users_name = NULL; //unset($users_name); | |
1188 | - | |
1189 | - // Ne pas commenter la ligne suivante, on en a besoin dans add.cpt | |
1190 | - $mail_responsable = $usersTable->find() | |
1191 | - ->select('email') | |
1192 | - ->where([ | |
1193 | - 'username =' => $this->LdapAuth->user($this->request->getSession() | |
1194 | - ->read('authType'))[0] | |
1195 | - ]) | |
1196 | - ->first()['email']; | |
1197 | - | |
1198 | - if (isset($this->request->getAttribute('params')['pass'][0])) { | |
1199 | - $cpMateriel = $this->Materiels->get($this->request->getAttribute('params')['pass'][0]); | |
1200 | - $this->set('cpMateriel', $cpMateriel); | |
1201 | - } | |
1202 | - | |
1203 | - //$this->set(compact('designation', 'utilisateurconnect', 'users', 'materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable', 'domaineresp', 'lieu_detail', 'fournisseurs')); | |
1204 | - $this->set(compact( | |
1205 | - 'materiel', | |
1206 | - 'utilisateurconnect', | |
1207 | - 'designation', | |
1208 | - 'surCategories', 'categories', 'sousCategories', | |
1209 | - 'groupesThematiques', 'groupesMetiers', | |
1210 | - 'organismes', 'sites', | |
1211 | - 'mail_responsable', 'domaineresp', 'lieu_detail', 'fournisseurs', | |
1212 | - 'users_name_and_email', 'users_option_list' | |
1213 | - )); | |
1214 | - $this->set('_serialize', [ | |
1215 | - 'materiel' | |
1216 | - ]); | |
1217 | - } // add() | |
1218 | - */ | |
1059 | + | |
1219 | 1060 | |
1220 | 1061 | /** |
1221 | 1062 | * Edit method |
... | ... | @@ -1226,209 +1067,6 @@ class MaterielsController extends AppController |
1226 | 1067 | * @throws \Cake\Network\Exception\NotFoundException When record not found. |
1227 | 1068 | */ |
1228 | 1069 | public function edit($id = null) { $this->add_or_edit(FALSE, $id); } |
1229 | - /* | |
1230 | - { | |
1231 | - $materiel = $this->Materiels->get($id, [ | |
1232 | - 'contain' => [] | |
1233 | - ]); | |
1234 | - if ($this->request->is([ | |
1235 | - 'patch', | |
1236 | - 'post', | |
1237 | - 'put' | |
1238 | - ])) { | |
1239 | - $materiel = $this->Materiels->patchEntity($materiel, $this->request->getData()); | |
1240 | - if (in_array($_SESSION['Auth']['User']['sn'][0], TableRegistry::get('Users')->find('list', [ | |
1241 | - 'keyField' => 'id', | |
1242 | - 'valueField' => 'nom' | |
1243 | - ]) | |
1244 | - ->where([ | |
1245 | - 'role =' => 'Administration' | |
1246 | - ]) | |
1247 | - ->toArray())) { | |
1248 | - $gestionnaireID = TableRegistry::get('Users')->find() | |
1249 | - ->where([ | |
1250 | - 'nom' => $_SESSION['Auth']['User']['sn'][0] | |
1251 | - ]) | |
1252 | - ->first()->id; | |
1253 | - $materiel->gestionnaire_id = $gestionnaireID; | |
1254 | - } | |
1255 | - if ($this->Materiels->save($materiel)) { | |
1256 | - $this->Flash->success(__('Le matériel a bien été édité.')); | |
1257 | - //En attendant un remaniement complet de la fonction | |
1258 | - //1 = img, doc = 2, mail normal = tout autre argument | |
1259 | - //$this->sendmail($materiel,5); | |
1260 | - return $this->redirect([ | |
1261 | - 'action' => 'view', | |
1262 | - $id | |
1263 | - ]); | |
1264 | - } else | |
1265 | - $this->Flash->error(__('Le matériel n\'a pas pu être édité.')); | |
1266 | - } | |
1267 | - | |
1268 | - $surCategories = $this->Materiels->SurCategories->find('list', [ | |
1269 | - 'keyField' => 'id', | |
1270 | - 'valueField' => 'nom', | |
1271 | - 'order' => 'SurCategories.nom' | |
1272 | - ]); | |
1273 | - $categories = $this->Materiels->Categories->find('list', [ | |
1274 | - 'keyField' => 'id', | |
1275 | - 'valueField' => 'nom', | |
1276 | - 'order' => 'Categories.nom' | |
1277 | - ]); | |
1278 | - $sousCategories = $this->Materiels->SousCategories->find('list', [ | |
1279 | - 'keyField' => 'id', | |
1280 | - 'valueField' => 'nom', | |
1281 | - 'order' => 'SousCategories.nom' | |
1282 | - ]); | |
1283 | - $groupesThematiques = $this->Materiels->GroupesThematiques->find('list', [ | |
1284 | - 'keyField' => 'id', | |
1285 | - 'valueField' => 'nom', | |
1286 | - 'order' => 'GroupesThematiques.nom' | |
1287 | - ]); | |
1288 | - $groupesMetiers = $this->Materiels->GroupesMetiers->find('list', [ | |
1289 | - 'keyField' => 'id', | |
1290 | - 'valueField' => 'nom', | |
1291 | - 'order' => 'GroupesMetiers.nom' | |
1292 | - ]); | |
1293 | - $organismes = $this->Materiels->Organismes->find('list', [ | |
1294 | - 'keyField' => 'id', | |
1295 | - 'valueField' => 'nom', | |
1296 | - 'order' => 'Organismes.nom' | |
1297 | - ]); | |
1298 | - $sites = $this->Materiels->Sites->find('list', [ | |
1299 | - 'keyField' => 'id', | |
1300 | - 'valueField' => 'nom', | |
1301 | - 'order' => 'Sites.nom' | |
1302 | - ]); | |
1303 | - $designation = $this->Materiels->find('list', [ | |
1304 | - 'keyField' => 'designation', | |
1305 | - 'valueField' => 'designation', | |
1306 | - 'conditions' => array( | |
1307 | - 'designation !=' => '' | |
1308 | - ), | |
1309 | - 'order' => 'designation', | |
1310 | - 'group' => 'designation' | |
1311 | - ]); | |
1312 | - $designation_edit = $this->Materiels->find('list', [ | |
1313 | - 'keyField' => 'id', | |
1314 | - 'valueField' => 'designation', | |
1315 | - 'conditions' => array( | |
1316 | - 'id =' => $materiel->id | |
1317 | - ) | |
1318 | - ]); | |
1319 | - $designation_edit = $designation_edit->toArray(); | |
1320 | - | |
1321 | - // autocomplete + saisie sites | |
1322 | - $lieu_detail = $this->Materiels->find('list', [ | |
1323 | - 'keyField' => 'lieu_detail', | |
1324 | - 'valueField' => 'lieu_detail', | |
1325 | - 'conditions' => array( | |
1326 | - 'lieu_detail !=' => '' | |
1327 | - ), | |
1328 | - 'order' => 'lieu_detail' | |
1329 | - ]); | |
1330 | - $lieu_detail_edit = $this->Materiels->find('list', [ | |
1331 | - 'keyField' => 'id', | |
1332 | - 'valueField' => 'lieu_detail', | |
1333 | - 'conditions' => array( | |
1334 | - 'id =' => $materiel->id | |
1335 | - ) | |
1336 | - ]); | |
1337 | - $lieu_detail_edit = $lieu_detail_edit->toArray(); | |
1338 | - | |
1339 | - // liste fournisseur | |
1340 | - $fournisseurs = $this->Materiels->Fournisseurs->find('list', [ | |
1341 | - 'keyField' => 'id', | |
1342 | - 'valueField' => 'nom', | |
1343 | - 'order' => 'Fournisseurs.nom' | |
1344 | - ]); | |
1345 | - $dom = TableRegistry::get('Materiels')->find() | |
1346 | - ->select('sur_categorie_id') | |
1347 | - ->where([ | |
1348 | - 'id =' => $materiel->id | |
1349 | - ]) | |
1350 | - ->first()['sur_categorie_id']; | |
1351 | - $domaines = TableRegistry::get('Users')->find() | |
1352 | - ->select('sur_categorie_id') | |
1353 | - ->where([ | |
1354 | - 'username =' => $this->LdapAuth->user($this->request->getSession() | |
1355 | - ->read('authType'))[0] | |
1356 | - ]) | |
1357 | - ->first()['sur_categorie_id']; | |
1358 | - $role = TableRegistry::get('Users')->find() | |
1359 | - ->select('role') | |
1360 | - ->where([ | |
1361 | - 'username =' => $this->LdapAuth->user($this->request->getSession() | |
1362 | - ->read('authType'))[0] | |
1363 | - ]) | |
1364 | - ->first()['role']; | |
1365 | - | |
1366 | - // NUL, franchement faudrait reflechir un peu quand meme, ya des limites !!! | |
1367 | - //if ($dom == $domaines) | |
1368 | - // $domaineresp = true; | |
1369 | - //else | |
1370 | - // $domaineresp = false; | |
1371 | - $domaineresp = ($dom == $domaines); | |
1372 | - | |
1373 | - // TODO: code redondant avec add(), à factoriser | |
1374 | - // HOWTO: https://book.cakephp.org/3.0/en/orm.html | |
1375 | - //$users = TableRegistry::get('LdapConnections')->getListUsers(); | |
1376 | - //$users = TableRegistry::get('LdapConnections')->getUsersWithNameAndEmail(); | |
1377 | - $users_name_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
1378 | - $users_name = array_keys($users_name_and_email); | |
1379 | - $users_option_list = []; | |
1380 | - for ($i = 0; $i < sizeof($users_name); $i ++) { | |
1381 | - // $users_option_list["Etienne Pallier"] = "Etienne Pallier" | |
1382 | - $users_option_list[$users_name[$i]] = $users_name[$i]; | |
1383 | - } | |
1384 | - | |
1385 | - if (! empty($materiel->get('nom_responsable'))) { | |
1386 | - //if (! in_array($materiel->get('nom_responsable'), $utilisateurs)) { | |
1387 | - if (! in_array($materiel->get('nom_responsable'), $users_name)) { | |
1388 | - $nom_ancien_responsable = $materiel->get('nom_responsable'); | |
1389 | - $this->set(compact('nom_ancien_responsable')); | |
1390 | - } | |
1391 | - } | |
1392 | - //$mail_responsable = TableRegistry::get('Users')->find() | |
1393 | - $mail_responsable = TableRegistry::getTableLocator()->get('Users')->find() | |
1394 | - ->select('email') | |
1395 | - ->where([ | |
1396 | - 'username =' => $this->LdapAuth->user($this->request->getSession() | |
1397 | - ->read('authType'))[0] | |
1398 | - ]) | |
1399 | - ->first()['email']; | |
1400 | - | |
1401 | - // Fonction utilisée dans la vue, déclarée ici pour éviter les problèmes de tests | |
1402 | - $isReadonlyField = function ($fieldName, $myReadonlyFields) { | |
1403 | - if (! empty($myReadonlyFields) && $myReadonlyFields[0] == '*') { | |
1404 | - $modifiableFields = $myReadonlyFields; | |
1405 | - array_shift($modifiableFields); | |
1406 | - return ! in_array($fieldName, $modifiableFields); | |
1407 | - } | |
1408 | - return in_array($fieldName, $myReadonlyFields); | |
1409 | - }; | |
1410 | - | |
1411 | - $this->set('isReadonlyField', $isReadonlyField); | |
1412 | - $this->set('IS_CREATED', $materiel->status == 'CREATED'); | |
1413 | - $this->set('IS_VALIDATED', $materiel->status == 'VALIDATED'); | |
1414 | - $this->set('IS_ARCHIVED_OR_TOBE', in_array($materiel->status, [ | |
1415 | - 'TOBEARCHIVED', | |
1416 | - 'ARCHIVED' | |
1417 | - ])); | |
1418 | - $this->set(compact( | |
1419 | - 'materiel', | |
1420 | - 'surCategories', 'categories', 'sousCategories', | |
1421 | - 'groupesThematiques', 'groupesMetiers', | |
1422 | - 'organismes', 'sites', | |
1423 | - 'mail_responsable', 'role', 'domaineresp', 'designation_edit', 'designation', 'lieu_detail', 'lieu_detail_edit', 'fournisseurs', | |
1424 | - //'utilisateurs', | |
1425 | - 'users_name_and_email', 'users_option_list' | |
1426 | - )); | |
1427 | - $this->set('_serialize', [ | |
1428 | - 'materiel' | |
1429 | - ]); | |
1430 | - } // edit() | |
1431 | - */ | |
1432 | 1070 | |
1433 | 1071 | /** |
1434 | 1072 | * Administrer method | ... | ... |
src/Controller/UsersController.php
... | ... | @@ -215,23 +215,31 @@ class UsersController extends AppController |
215 | 215 | 'keyField' => 'id', |
216 | 216 | 'valueField' => 'nom' |
217 | 217 | ]); |
218 | - // TODO: remplacer getListUsers() par getUsersWithNameAndEmail() | |
219 | - // TODO: idem pour add() et edit() | |
218 | + | |
219 | + // TODO: Refactoriser: idem pour add() et edit() (ainsi que leurs pendants dans MaterielsController) | |
220 | 220 | // On recup tous les users du LDAP (ou fakeLDAP si on n'est pas en mode LDAP) |
221 | - $users = TableRegistry::get('LdapConnections')->getListUsers(); | |
222 | - // Tri des utilisateurs par nom | |
223 | - sort($users); | |
224 | - // Formatage en $utilisateurs["Etienne Pallier"] = "Etienne Pallier" ... | |
225 | - $utilisateurs = []; | |
226 | - for ($i = 0; $i < sizeof($users); $i ++) { | |
227 | - $utilisateurs[$users[$i]] = $users[$i]; | |
221 | + //$users = TableRegistry::get('LdapConnections')->getListUsers(); | |
222 | + //sort($users); | |
223 | + $users_name_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
224 | + $users_name = array_keys($users_name_and_email); | |
225 | + // Formatage en $users_option_list["Etienne Pallier"] = "Etienne Pallier" ... | |
226 | + $users_option_list = []; | |
227 | + for ($i = 0; $i < sizeof($users_name); $i ++) { | |
228 | + $users_option_list[$users_name[$i]] = $users_name[$i]; | |
228 | 229 | } |
230 | + | |
231 | + | |
232 | + | |
229 | 233 | //debug($users); |
230 | 234 | //debug($utilisateurs); |
231 | 235 | |
232 | 236 | // On passe à la vue add.ctp toutes les variables créés ci-dessus |
233 | 237 | // "user" est l'utilisateur $user créé au début, et qui est vide |
234 | - $this->set(compact('user', 'groupesMetiers', 'utilisateurs', 'groupesThematiques', 'sur_categorie')); | |
238 | + $this->set(compact('user', | |
239 | + 'groupesMetiers', | |
240 | + 'users_option_list', 'users_name_and_email', | |
241 | + 'groupesThematiques', 'sur_categorie') | |
242 | + ); | |
235 | 243 | $this->set('_serialize', [ |
236 | 244 | 'user' |
237 | 245 | ]); | ... | ... |
src/Template/Users/add.ctp
1 | 1 | |
2 | 2 | <?php |
3 | -//var_dump($utilisateurs); | |
3 | +//var_dump($users_option_list); | |
4 | +//var_dump($users_name_and_email); | |
5 | + | |
6 | +/* | |
7 | + * (EP) | |
8 | + * Variables passed to this view by the Controller : | |
9 | + */ | |
10 | +$users_option_list = $users_option_list; | |
11 | +$users_name_and_email = $users_name_and_email; | |
12 | +// TODO: yena d'autres... il faut les lister toutes ici, pour plus de clarté | |
13 | + | |
14 | + | |
4 | 15 | ?> |
5 | 16 | |
6 | 17 | <div class="utilisateurs form"> |
... | ... | @@ -15,7 +26,7 @@ |
15 | 26 | // LDAP |
16 | 27 | if ($LDAP_USED) { |
17 | 28 | echo $this->Form->control('nom', [ |
18 | - 'options' => $utilisateurs, | |
29 | + 'options' => $users_option_list, | |
19 | 30 | 'empty' => 'Choisir un utilisateur', |
20 | 31 | 'label' => 'Nom (LDAP)', |
21 | 32 | 'div' => 'input required' |
... | ... | @@ -100,8 +111,50 @@ if ($LDAP_USED) { |
100 | 111 | |
101 | 112 | <script type="text/javascript"> |
102 | 113 | |
103 | -/* Quand on selectionne un utilisateur dans la liste => on met à jour son login et son email (en readonly) */ | |
114 | +/** | |
115 | + * Quand on selectionne un utilisateur dans la liste => on met à jour son login et son email (en readonly) | |
116 | + | |
117 | + * (EP 6/5/19) New method, quicker, get email directly from PHP $users_name_and_email array | |
118 | + * (OLD code is at end of file) | |
119 | + * | |
120 | + * Event "Nom utilisateur" change => "login" and "email" change | |
121 | + * | |
122 | + * TODO: Code commun avec edit.ctp => factoriser quelque part, mais comment, vu qu'on a besoin du tableau users_name_and_email ??? | |
123 | + */ | |
124 | + | |
104 | 125 | $(document).ready(function () { |
126 | + | |
127 | + // Convert (once for all) PHP $users_name_and_email array to JAVASCRIPT array | |
128 | + //Implode Method | |
129 | + //var array = [INF?php echo implode($array, ","); ?SUP]; | |
130 | + //JSON Method | |
131 | + var users_name_and_email = <?php echo json_encode($users_name_and_email); ?>; | |
132 | + | |
133 | + | |
134 | + $("#nom").bind("change", function(event) { | |
135 | + | |
136 | + if ( $("#nom").val() == "" ) return false; | |
137 | + var user_name = $("#nom").val(); | |
138 | + | |
139 | + /* Mise a jour du login */ | |
140 | + var url = document.URL; | |
141 | + var loginUrl = url.replace("add", "getLdapLogin/"); | |
142 | + $.ajax({ | |
143 | + url: loginUrl + $("#nom").val() | |
144 | + }).done(function(data) { | |
145 | + $("#username").val(data) | |
146 | + }); | |
147 | + | |
148 | + /* Mise a jour du mail */ | |
149 | + var new_email = users_name_and_email[user_name]; | |
150 | + $("#email").val(new_email); | |
151 | + | |
152 | + }); // ON "nom" field change | |
153 | + | |
154 | +}); // ON document.ready() | |
155 | + | |
156 | +/* | |
157 | +//OLD method, fetch login and email via AJAX request to UsersController.getLdapLogin and getLdapEmail() | |
105 | 158 | $("#nom").bind("change", function (event) { |
106 | 159 | if ( $("#nom").val() == "" ) return false; |
107 | 160 | var url = document.URL; |
... | ... | @@ -111,6 +164,7 @@ $(document).ready(function () { |
111 | 164 | Quand on est sur la page d'ajout d'un utilisateur, |
112 | 165 | remplacer dans l'url "/users/add" par "/users/getLdapLogin/Pallier Etienne" par exemple |
113 | 166 | */ |
167 | + /* | |
114 | 168 | var loginUrl = url.replace("add", "getLdapLogin/"); |
115 | 169 | $.ajax({ |
116 | 170 | url: loginUrl + $("#nom").val() |
... | ... | @@ -120,6 +174,7 @@ $(document).ready(function () { |
120 | 174 | |
121 | 175 | /* Mise a jour du mail */ |
122 | 176 | /* Pour tester manuellement : Voir exemple precedent, c'est le meme principe */ |
177 | + /* | |
123 | 178 | var emailUrl = url.replace("add", "getLdapEmail/"); |
124 | 179 | $.ajax({ |
125 | 180 | url: emailUrl + $("#nom").val() |
... | ... | @@ -127,11 +182,13 @@ $(document).ready(function () { |
127 | 182 | $("#email").val(data) |
128 | 183 | }); |
129 | 184 | |
130 | - }); | |
131 | -}); | |
185 | + }); // ON "nom" field change | |
186 | + | |
187 | +*/ | |
188 | + | |
132 | 189 | |
133 | 190 | </script> |
134 | 191 | |
135 | 192 | <?php |
136 | -} | |
193 | +} // if ($LDAP_USED) | |
137 | 194 | ?> |
138 | 195 | \ No newline at end of file | ... | ... |