Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1. namespace YOUR_NAMESPACE.Common {
  2.  
  3. export class MySlilerRevealOptions {
  4. target: JQuery;
  5. initDialog: () => Serenity.EntityDialog<any, any>;
  6. onDataChangeCallback?: () => void;
  7. sliderWidth?: any;
  8. entityOrId: any;
  9. }
  10.  
  11. @Serenity.Decorators.registerClass()
  12. export class MySlilerReveal extends Serenity.TemplatedWidget<MySlilerRevealOptions> {
  13.  
  14. private slider: JQuery;
  15. private overlayDiv: JQuery = $(`<div class="custom-slide-reveal-overlay" style="position: fixed; top: 0px; left: 0px; height: 100%; width: 100%; background-color: rgba(0, 0, 0, 0.5); display: block !important;"></div>`);
  16. private dlg: Serenity.EntityDialog<any, any>;
  17.  
  18. constructor(container: JQuery, opt?: MySlilerRevealOptions) {
  19. super(container, opt);
  20.  
  21. let target = this.getTargetElement();
  22. target.addClass("slider-dialog-force-show-target");
  23.  
  24. if (!$(".s-DataGrid").hasClass("panel-hidden")) {
  25. $(".s-DataGrid").addClass("slider-dialog-force-show-target");
  26. }
  27.  
  28. this.dlg = this.options.initDialog();
  29.  
  30. container.appendTo(target);
  31.  
  32. if ($(".custom-slide-reveal-overlay").length > 0) {
  33. this.overlayDiv.css("opacity", 0.2);
  34. }
  35.  
  36. this.overlayDiv.insertBefore(this.element);
  37.  
  38. this.overlayDiv.click(e => {
  39. (this.slider as any).slideReveal('hide');
  40. });
  41.  
  42. let targetCurIndex = 0;
  43. try {
  44. targetCurIndex = Q.parseInteger(target.css("z-index"));
  45. } catch{ }
  46.  
  47. targetCurIndex = targetCurIndex.toString() == "NaN" ? 0 : targetCurIndex;
  48. targetCurIndex = targetCurIndex <= 0 ? 1101 : targetCurIndex;
  49.  
  50. this.overlayDiv.css("z-index", targetCurIndex);
  51. this.element.css("z-index", targetCurIndex);
  52.  
  53.  
  54. this.element.css("position", "relative");
  55.  
  56. this.dlg.element.addClass("flex-layout");
  57.  
  58. let nbrExistedSlider = $(".slider-container").length;
  59.  
  60. //let topHeight = $('header.main-header').height();
  61. this.slider = (this.byId("sliderContainer") as any).slideReveal({
  62. push: false,
  63. position: 'right',
  64. zIndex: 1100,
  65. overlay: false,
  66. autoEscape: true,
  67. //top: topHeight,
  68. width: Q.coalesce(this.options.sliderWidth, `calc(50% - ${nbrExistedSlider * 40}px`),
  69. trigger: this.byId("sliderCloseButton"),
  70. show: (slider, trigger) => {
  71.  
  72. },
  73. shown: (slider, trigger) => {
  74. $(slider).css("right", "-10px");
  75. },
  76. hide: (slider, trigger) => {
  77.  
  78. },
  79. hidden: (slider, trigger) => {
  80. this.byId("sliderContainer").remove();
  81.  
  82. let target = this.getTargetElement();
  83. $(".slider-dialog-force-show-target").removeClass("hidden").removeClass("panel-hidden");
  84.  
  85. target.removeClass("slider-dialog-force-show-target");
  86.  
  87. try {
  88. this.overlayDiv.remove();
  89. } catch {
  90.  
  91. }
  92.  
  93. try {
  94. //this.dlg.dialogClose();
  95. //Serenity.TemplatedDialog.closePanel(this.dlg.element);
  96. } catch {
  97.  
  98. }
  99. }
  100. });
  101.  
  102. this.dlg.element.bind('panelclose', () => {
  103. (this.slider as any).slideReveal('hide');
  104. });
  105.  
  106. this.dlg.element.on("ondatachange", (x, data) => {
  107. this.options.onDataChangeCallback && this.options.onDataChangeCallback();
  108. });
  109. }
  110.  
  111. private getTargetElement(): JQuery {
  112. if (this.options.target.hasClass("s-Panel")) {
  113. return this.options.target;
  114. }
  115.  
  116. if (this.options.target.hasClass("ui-dialog-content")) {
  117. return this.options.target.parent();
  118. }
  119.  
  120. if (this.options.target.hasClass("s-DataGrid")) {
  121. return this.options.target;
  122. }
  123.  
  124. return this.options.target;
  125. }
  126.  
  127. public handleEditItem() {
  128. if (typeof this.options.entityOrId == "string") {
  129. this.loadByIdAndOpenSlider(this.options.entityOrId);
  130. Q.Router.dialog(this.element, this.dlg.element, () => 'edit/' + this.options.entityOrId.toString());
  131. }
  132. else {
  133. Q.Router.dialog(this.element, this.dlg.element, () => "new");
  134. this.loadNewAndOpenSlider();
  135. }
  136. }
  137.  
  138. public loadByIdAndOpenSlider(id: any) {
  139.  
  140. this.dlg.loadById(id,
  141. response => window.setTimeout(() => {
  142.  
  143. this.dlg.dialogOpen(true);
  144. this.slider.parent().removeClass("hidden").removeClass("panel-hidden");
  145. this.dlg.element.find(".panel-titlebar").remove();
  146.  
  147. this.dlg.element.appendTo(this.byId("panelContainer"));
  148.  
  149. }, 0),
  150. () => {
  151. try {
  152. (this.slider as any).slideReveal('close');
  153. } catch{
  154.  
  155. }
  156.  
  157. if (!this.element.is(':visible')) {
  158. this.element.remove();
  159. }
  160. });
  161.  
  162. this.injectDialogIntoPanel(id);
  163. }
  164.  
  165. public loadNewAndOpenSlider() {
  166.  
  167. this.dlg.loadNewAndOpenDialog(true);
  168. this.slider.parent().removeClass("hidden").removeClass("panel-hidden");
  169. this.dlg.element.find(".panel-titlebar").remove();
  170. this.dlg.element.find(".apply-changes-button").hide();
  171.  
  172. this.dlg.element.appendTo(this.byId("panelContainer"));
  173.  
  174. this.injectDialogIntoPanel();
  175. }
  176.  
  177. private injectDialogIntoPanel(id?: any) {
  178. var nbrRetry = 0;
  179.  
  180. var self = this;
  181. (function appendDialogIntoPanel() {
  182. setTimeout(function () {
  183. nbrRetry++;
  184.  
  185. if (nbrRetry >= 100) {
  186. return;
  187. }
  188.  
  189. if (self.slider.find(".s-TemplatedDialog").length === 1) {
  190. (self.slider as any).slideReveal('toggle');
  191. }
  192. else {
  193. appendDialogIntoPanel();
  194. }
  195.  
  196. }, 100);
  197. })();
  198.  
  199. }
  200.  
  201. getTemplate() {
  202. return `<div id="~_sliderContainer" class="slider-container" style="background-color:#fff; position:relative; border-left: solid 1px #c9c9c9">
  203. <div id="~_sliderCloseButton" style="width:25px; height: 25px; position: absolute; top: 10px; right: 13px;color: red; cursor: pointer">
  204. <i class="fa fa-lg fa-times" aria-hidden="true"></i>
  205. </div>
  206. <div id="~_panelContainer">
  207.  
  208. </div>
  209. </div>`;
  210. }
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement