Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. namespace myProject.Default {
  2.  
  3. @Serenity.Decorators.registerClass()
  4. @Serenity.Decorators.panel()
  5. export class MatrixEditDialog extends Serenity.EntityDialog<MatrixRow, any> {
  6. protected getFormKey() { return MatrixForm.formKey; }
  7. protected getIdProperty() { return MatrixRow.idProperty; }
  8. protected getLocalTextPrefix() { return MatrixRow.localTextPrefix; }
  9. protected getNameProperty() { return MatrixRow.nameProperty; }
  10. protected getService() { return MatrixService.baseUrl; }
  11.  
  12. protected form = new MatrixForm(this.idPrefix);
  13.  
  14. constructor() {
  15. super();
  16. this.element.addClass('flex-layout');
  17. this.toggleRun();
  18. }
  19.  
  20.  
  21. static initializePage() {
  22.  
  23. $(function () {
  24. new Default.MatrixEditDialog().element.appendTo($('#DialogDiv'));
  25.  
  26. });
  27. };
  28.  
  29.  
  30. protected onSaveSuccess(response: Serenity.SaveResponse): void {
  31. super.onSaveSuccess(response);
  32. var cID = this.getSaveEntity().CustomerId;
  33. var aID = this.getSaveEntity().AddressId;
  34.  
  35. Q.confirm(
  36. "Add another item to the same room?",
  37. () => {
  38. Q.notifySuccess("You clicked YES.");
  39. newDialogwithVals(cID, aID);
  40. },
  41. {
  42. onNo: () => {
  43. Q.notifyInfo("You clicked NO.");
  44. $('#DialogDiv').empty();
  45. new Default.MatrixEditDialog().element.appendTo($('#DialogDiv'));
  46. },
  47. onCancel: () => {
  48. Q.notifyError("You clicked X. Operation is cancelled.");
  49. $('#DialogDiv').empty();
  50. new Default.MatrixEditDialog().element.appendTo($('#DialogDiv'));
  51. }
  52. });
  53. }
  54.  
  55. protected toggleRun() {
  56.  
  57. this.categoryToggler(this.form.CustomerId, 'Address');
  58. this.categoryToggler(this.form.AddressId, 'Accounting');
  59. this.categoryToggler(this.form.AddressId, 'Revision');
  60. this.categoryToggler(this.form.AddressId, 'General');
  61. this.categoryToggler(this.form.AddressId, 'Equipment Info');
  62. this.categoryToggler(this.form.AddressId, 'Plumbing');
  63. this.categoryToggler(this.form.AddressId, 'Mechanical');
  64. this.categoryToggler(this.form.AddressId, 'Electrical');
  65. this.categoryToggler(this.form.AddressId, 'Dimensions');
  66. this.categoryToggler(this.form.AddressId, 'Other');
  67.  
  68. }
  69.  
  70. protected categoryToggler(triggerField: Serenity.LookupEditor, categoryTitle: string) {
  71. var myTag = categoryTitle;
  72. var ele = this.element.find(".category-title:contains('" + myTag + "')").parent();
  73. var checkTrigger = triggerField.value;
  74.  
  75. if (Q.isEmptyOrNull(checkTrigger)) {
  76. ele.toggle(false);
  77.  
  78. triggerField.changeSelect2(e => {
  79. var myTrigger = triggerField.value;
  80.  
  81. if (Q.isEmptyOrNull(myTrigger) === true) {
  82. ele.toggle(false);
  83. }
  84.  
  85. else {
  86. ele.toggle(true);
  87. }
  88. });
  89. }
  90.  
  91. else {
  92. triggerField.changeSelect2(e => {
  93. var myTrigger = triggerField.value;
  94.  
  95. if (Q.isEmptyOrNull(myTrigger) === true) {
  96. ele.toggle(false);
  97. }
  98.  
  99. else {
  100. ele.toggle(true);
  101. }
  102. });
  103. }
  104. };
  105. }
  106.  
  107. function newDialogwithVals(customerID: number, addressID: number)
  108. {
  109. $('#DialogDiv').empty();
  110. var dlg = new MatrixEditDialog();
  111.  
  112. dlg.loadEntityAndOpenDialog(<MatrixRow>{
  113. CustomerId: customerID,
  114. AddressId: addressID,
  115. Status: 1,
  116. ProvidedBy: 1,
  117. InstalledBy: 1
  118. });
  119. dlg.element.appendTo($('#DialogDiv'));
  120. };
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement