Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.80 KB | None | 0 0
  1. var app = angular.module('addApp', []);
  2.  
  3. app.controller('modifyCtrl', ['$scope', function($scope){
  4. $scope.tabelsData= [
  5. {'name':'rohit', 'dob':'15-august-1985', 'emailId':'rohit@rohit.com', 'phone':'9999999999', 'address':'Delhi Rohini', 'id':'0' },
  6. {'name':'aman', 'dob':'26-july-1975', 'emailId':'haryanat@hr.com', 'phone':'9874563210', 'address':'Haryana Sonepat', 'id':'1' },
  7. {'name':'devraj', 'dob':'27-march-1980', 'emailId':'punjab@punjab.com', 'phone':'7410258963', 'address':'Punjab AmritSar', 'id':'2' }
  8. ];
  9.  
  10.  
  11. $scope.modify = function(tableData){
  12.  
  13. $scope.modifyField = true;
  14. $scope.viewField = true;
  15. };
  16.  
  17.  
  18. $scope.update = function(tableData){
  19. $scope.modifyField = false;
  20. $scope.viewField = false;
  21. };
  22.  
  23. }]);
  24.  
  25. <div ng-app="addApp">
  26.  
  27. <div class="wraper" ng-controller="modifyCtrl">
  28.  
  29. <table>
  30. <thead>
  31. <tr>
  32. <th>Name:</th>
  33. <th>Date Of Birth</th>
  34. <th>Email Id</th>
  35. <th>Phone No.</th>
  36. <th>Address</th>
  37. <th>Action</th>
  38. </tr>
  39. </thead>
  40. <tbody>
  41. <tr ng-repeat="tableData in tabelsData"><form>
  42. <td>
  43. <div ng-hide="viewField">{{tableData.name | uppercase}}</div>
  44. <div ng-show="modifyField"><input type="text" ng-model="tableData.name" /></div>
  45. </td>
  46. <td>
  47. <div ng-hide="viewField">{{tableData.dob}}</div>
  48. <div ng-show="modifyField"><input type="text" ng-model="tableData.dob" /></div>
  49. </td>
  50. <td>
  51. <div ng-hide="viewField">{{tableData.emailId}}</div>
  52. <div ng-show="modifyField"><input type="text" ng-model="tableData.emailId" /></div>
  53. </td>
  54. <td>
  55. <div ng-hide="viewField">{{tableData.phone}}</div>
  56. <div ng-show="modifyField"><input type="text" ng-model="tableData.phone" /></div>
  57. </td>
  58. <td>
  59. <div ng-hide="viewField">{{tableData.address}}</div>
  60. <div ng-show="modifyField">
  61. <textarea ng-model="tableData.address"></textarea>
  62. </div>
  63. </td>
  64. <td>
  65. <button ng-hide="viewField" ng-click="modify(tableData)">Modify</button>
  66. <button ng-show="modifyField" ng-click="update(tableData)">Update</button>
  67. <button ng-hide="viewField">Add</button>
  68. <button ng-hide="viewField">Remove</button>
  69. </td></form>
  70. </tr>
  71. </tbody>
  72. </table>
  73.  
  74. </div>
  75.  
  76. </div>
  77.  
  78. $scope.editingData = {};
  79.  
  80. for (var i = 0, length = $scope.tabelsData.length; i < length; i++) {
  81. $scope.editingData[$scope.tabelsData[i].id] = false;
  82. }
  83.  
  84. $scope.modify = function(tableData){
  85. $scope.editingData[tableData.id] = true;
  86. };
  87.  
  88.  
  89. $scope.update = function(tableData){
  90. $scope.editingData[tableData.id] = false;
  91. };
  92.  
  93. <tbody>
  94. <tr ng-repeat="tableData in tabelsData">
  95. <td>
  96. <div ng-hide="editingData[tableData.id]">{{tableData.name | uppercase}}</div>
  97. <div ng-show="editingData[tableData.id]"><input type="text" ng-model="tableData.name" /></div>
  98. </td>
  99. <td>
  100. <div ng-hide="editingData[tableData.id]">{{tableData.dob}}</div>
  101. <div ng-show="editingData[tableData.id]"><input type="text" ng-model="tableData.dob" /></div>
  102. </td>
  103. <td>
  104. <div ng-hide="editingData[tableData.id]">{{tableData.emailId}}</div>
  105. <div ng-show="editingData[tableData.id]"><input type="text" ng-model="tableData.emailId" /></div>
  106. </td>
  107. <td>
  108. <div ng-hide="editingData[tableData.id]">{{tableData.phone}}</div>
  109. <div ng-show="editingData[tableData.id]"><input type="text" ng-model="tableData.phone" /></div>
  110. </td>
  111. <td>
  112. <div ng-hide="editingData[tableData.id]">{{tableData.address}}</div>
  113. <div ng-show="editingData[tableData.id]">
  114. <textarea ng-model="tableData.address"></textarea>
  115. </div>
  116. </td>
  117. <td>
  118. <button ng-hide="editingData[tableData.id]" ng-click="modify(tableData)">Modify</button>
  119. <button ng-show="editingData[tableData.id]" ng-click="update(tableData)">Update</button>
  120. <button ng-hide="viewField">Add</button>
  121. <button ng-hide="viewField">Remove</button>
  122. </td>
  123. </tr>
  124. </tbody>
  125.  
  126. fichier.html:
  127. <ng2-toasty [position]="'top-left'"></ng2-toasty>
  128. <label for="trainingInput" class="mr-2">{{ 'LABEL.FORMATION' | translate }} :</label>
  129. <table class="table table-hover table-striped table-sortable table-bordered">
  130. <thead>
  131. <tr>
  132. <th *ngFor="let column of columns" [class]="selectedClass(column.variable)" (click)="changeSorting(column.variable)" translate>
  133. {{column.display}}
  134. </th>
  135. </tr>
  136. </thead>
  137. <tbody>
  138. <tr *ngFor="let object of data | orderBy : convertSorting(); let rowIndex = index">
  139. <td *ngFor="let column of columns" class="{{column.variable}}-td">
  140. <div *ngIf="!toUpdates[object['id']]" >{{object[column.variable] | format: column.filter}}</div>
  141. <div *ngIf="toUpdates[object['id']]"><input type="text" [(ngModel)]="object[column.variable]" ></div>
  142. </td>
  143. <td class="text-center">
  144. <i *ngIf="!toUpdates[object['id']]" class="fa fa-pencil-square-o edit-formation" aria-hidden="true" (click) = "editFormation(object)"></i>
  145. <i *ngIf="toUpdates[object['id']]" class="fa fa-check-square-o save-edit-form" (click)="updateFormation(object)"></i>
  146. <i class="fa fa-times" aria-hidden="true" (click)="deleteFormation(object['id'])"></i>
  147. </td>
  148. </tr>
  149. <tr [hidden]="isDisabled()">
  150. <td><input type="text" class="form-control" placeholder="Année" #years></td>
  151. <td><input type="text" class="form-control" placeholder="Formation" #label></td>
  152. <td><input type="text" class="form-control" placeholder="Durée" #duration></td>
  153. <td class="text-center align-middle">
  154. <i class="fa fa-plus-circle fa-2x" (click)="addFormation(years.value, label.value, duration.value)"></i>
  155. </td>
  156. </tr>
  157. </tbody>
  158. </table>
  159.  
  160. fichier.ts:
  161. import {Component, Injector, Input, OnChanges, OnInit} from '@angular/core';
  162. import { Http, Headers, RequestOptions, URLSearchParams } from '@angular/http';
  163. import DynamicComponent from '../dynamic-component';
  164. import Formation from './formation';
  165. import {ToastyService, ToastyConfig, ToastOptions, ToastData} from 'ng2-toasty';
  166.  
  167.  
  168. @Component({
  169. moduleId: module.id,
  170. selector: 'formations-selector',
  171. templateUrl: './formations-template.html',
  172. styleUrls: ['./formations-template.css'],
  173. })
  174. export default class FormationsComponent{
  175.  
  176. candidate: any = null;
  177. listFormations: any = null;
  178. candidateDetails: any = null;
  179. columns: any[];
  180. sort: any;
  181. data: any[];
  182. toUpdates: {};
  183.  
  184. constructor(private injector: Injector, private http: Http,private toastyService: ToastyService, private toastyConfig: ToastyConfig) {
  185. this.candidateDetails = this.injector.get('candidateDetails');
  186. this.candidate = this.candidateDetails.candidate;
  187. this.listFormations = this.candidateDetails.listFormations;
  188. this.columns = this.listFormations.columns;
  189. this.sort = this.listFormations.sort;
  190. this.data = this.listFormations.data;
  191. this.toastyConfig.theme = 'material';
  192. this.toUpdates = {};
  193. }
  194.  
  195. ngAfterViewInit(){
  196. $(document).ready(function() {
  197. /*
  198. $('.edit-formation').click(function () {
  199. var dad = $(this).parent().parent();
  200. dad.find('td .duration-span').hide();
  201. dad.find('td.duration-td').append('<input type="text" class="form-control" placeholder="Durée" value="'+dad.find('td .duration-span').html()+'" id = "duration-update" #durationu>');
  202. dad.find('td .label-span').hide();
  203. dad.find('td.label-td').append('<input type="text" class="form-control" placeholder="Formation" id="label-update" value="'+dad.find('td .label-span').html()+'" #labelu>');
  204. dad.find('td .years-span').hide();
  205. dad.find('td.years-td').append('<input type="text" class="form-control" placeholder="Année" id="years-update" value="'+dad.find('td .years-span').html()+'" #yearsu>');
  206.  
  207. dad.find('td.years-td').append('<i class="fa fa-check-square-o save-edit-form hidden" (click)="updateFormation(1, years.value, label.value, durationu)"></i>');
  208.  
  209.  
  210. dad.find('td .edit-formation').addClass("hidden");
  211. dad.find('td .save-edit-form').removeClass("hidden");
  212.  
  213. });
  214. */
  215. /*
  216. $('.save-edit-form').click(function () {
  217. var dad = $(this).parent().parent();
  218. dad.find('td .save-edit-form').addClass("hidden");
  219. dad.find('td .edit-formation ').removeClass("hidden");
  220.  
  221. dad.find('td .duration-span').show();
  222. $('#duration-update').remove();
  223. dad.find('td .label-span').show();
  224. $('#label-update').remove();
  225. dad.find('td .years-span').show();
  226. $('#years-update').remove();
  227. });
  228. */
  229. });
  230. }
  231.  
  232.  
  233. //Action déclenché lors d'un changement de société du candidat : on met à jour la liste des métiers associés
  234. onChangeCompaniesInput(value) {
  235.  
  236. }
  237.  
  238. isDisabled(isDisabled) {
  239. //return (isDisabled || !this.candidateDetails.isUserAuthorized) ? true : false;
  240. }
  241.  
  242. selectedClass(columnName): string{
  243. return columnName == this.sort.column ? 'sort-' + this.sort.descending : '';
  244. }
  245.  
  246. changeSorting(columnName): void{
  247. var sort = this.sort;
  248. if (sort.column == columnName) {
  249. sort.descending = !sort.descending;
  250. } else {
  251. sort.column = columnName;
  252. sort.descending = false;
  253. }
  254. }
  255.  
  256. convertSorting(): string{
  257. return this.sort.descending ? '-' + this.sort.column : this.sort.column;
  258. }
  259.  
  260. onChangeMainFormaion(value): void{
  261. console.log(value);
  262. }
  263.  
  264. deleteFormation(idFormation): void{
  265. let headers = new Headers('Content-Type', 'application/json');
  266. let params: URLSearchParams = new URLSearchParams();
  267.  
  268. this.http.post('/api/formations/'+idFormation+'/deleteFormation', params).toPromise()
  269. .then(
  270. res =>
  271. {
  272. if(res.status == 200){
  273. this.toastyService.success({
  274. title: "Success",
  275. msg: "La formation a etait supprmié avec Succès",
  276. showClose: true,
  277. timeout: 5000,
  278. theme: 'default',
  279. });
  280. }else{
  281. this.toastyService.error({
  282. title: "Error",
  283. msg: "Une erreur est survenue, veuillez réessayer ultérieurement",
  284. showClose: true,
  285. timeout: 5000,
  286. theme: 'default',
  287. });
  288. }
  289. }
  290. ).catch(this.handleError);
  291. }
  292.  
  293. editFormation(tableData): void{
  294. this.toUpdates[tableData['id']]= true;
  295. }
  296.  
  297. updateFormation(tableData): void {
  298. this.toUpdates[tableData['id']]= false;
  299. console.log(tableData);
  300. }
  301.  
  302. addFormation(years: string, label: string, durration: string, main: boolean = false): void{
  303. let headers = new Headers('Content-Type', 'application/json');
  304. let params: URLSearchParams = new URLSearchParams();
  305. params.append('years', years);
  306. params.append('label', label);
  307. params.append('durration', durration);
  308. params.append('main', main);
  309.  
  310. //let formation = new Formation(years, label, durration, false);
  311. return this.http.post('/api/formations/'+this.candidate.id+'/addFormation', params).toPromise()
  312. .then(
  313. res =>
  314. {
  315. if(res.status == 200){
  316. this.toastyService.success({
  317. title: "Success",
  318. msg: "La formation a etait ajouter avec Succès",
  319. showClose: true,
  320. timeout: 5000,
  321. theme: 'default',
  322. });
  323. }else{
  324. this.toastyService.error({
  325. title: "Error",
  326. msg: "Une erreur est survenue, veuillez réessayer ultérieurement",
  327. showClose: true,
  328. timeout: 5000,
  329. theme: 'default',
  330. });
  331. }
  332. }
  333. ).catch(this.handleError);
  334. }
  335.  
  336. private handleError(error: any) {
  337. let errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : 'Server error';
  338. console.error(errMsg);
  339.  
  340. return Promise.reject(errMsg);
  341. }
  342.  
  343. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement