JAVASCRIPT   20
slides
Guest on 18th September 2023 07:56:27 AM


  1. (function(d, a) {
  2.     a.SlidesPageController = can.Control.extend({}, {
  3.         sliderId: null,
  4.         table: null,
  5.         updating: !1,
  6.         init: function(e, c) {
  7.             this._super(e, c);
  8.             this.sliderId = a.Vars.page.slider_id;
  9.             this.table = this.element.find("table");
  10.             this.setSlidesSortable()
  11.         },
  12.         disableActions: function() {
  13.             this.table.sortable("disable");
  14.             this.element.find(".mpsl_delete_slide, .mpsl_duplicate_slide, #create_slide").attr("disabled", "disabled")
  15.         },
  16.         enableActions: function() {
  17.             this.table.sortable("enable");
  18.             this.element.find(".mpsl_delete_slide, .mpsl_duplicate_slide, #create_slide").removeAttr("disabled")
  19.         },
  20.         setSlidesSortable: function() {
  21.             var a = this;
  22.             this.table.sortable({
  23.                 items: "tbody>tr",
  24.                 axis: "y",
  25.                 containment: "parent",
  26.                 cursor: "move",
  27.                 handle: ".mpsl-slide-sort-handle",
  28.                 tolerance: "pointer",
  29.                 helper: "clone",
  30.                 start: function(c, b) {
  31.                     a.updating = !1;
  32.                     a.disableActions()
  33.                 },
  34.                 stop: function(c, b) {
  35.                     a.updating || a.enableActions()
  36.                 },
  37.                 update: function(c, b) {
  38.                     a.updating = !0;
  39.                     a.updateSlidesOrder();
  40.                     a.enableActions()
  41.                 }
  42.             })
  43.         },
  44.         updateSlidesOrder: function() {
  45.             var e = this,
  46.                 c = this.table.find("tbody>tr"),
  47.                 b = {};
  48.             d.each(c, function(a, c) {
  49.                 b[a] = d(c).attr("data-id")
  50.             });
  51.             d.ajax({
  52.                 type: "POST",
  53.                 url: a.Vars.ajax_url,
  54.                 data: {
  55.                     action: "mpsl_update_slides_order",
  56.                     nonce: a.Vars.nonces.update_slides_order,
  57.                     order: b
  58.                 },
  59.                 success: function(b) {
  60.                     a.Functions.showMessage(a.Vars.lang.slides_sorted, a.Functions.MSG_SUCCESS_TYPE)
  61.                 },
  62.                 error: function(b) {
  63.                     b = d.parseJSON(b.responseText);
  64.                     b.debug ? console.log(b.message) : a.Functions.showMessage(b.message, a.Functions.MSG_ERROR_TYPE);
  65.                     e.enableActions()
  66.                 },
  67.                 dataType: "JSON"
  68.             })
  69.         },
  70.         "#create_slide click": function(e) {
  71.             var c = this;
  72.             this.disableActions();
  73.             d.ajax({
  74.                 type: "POST",
  75.                 url: a.Vars.ajax_url,
  76.                 data: {
  77.                     action: "mpsl_create_slide",
  78.                     nonce: a.Vars.nonces.create_slide,
  79.                     slider_id: this.sliderId
  80.                 },
  81.                 success: function(b) {
  82.                     b.hasOwnProperty("result") ? (a.Functions.showMessage(a.Vars.lang.slide_created, a.Functions.MSG_SUCCESS_TYPE), window.location.href = a.Vars.menu_url + "&view=slide&id=" + b.id) : (a.Functions.showMessage(a.Vars.lang.slider_created_error, a.Functions.MSG_ERROR_TYPE), c.enableActions())
  83.                 },
  84.                 error: function(b) {
  85.                     b = d.parseJSON(b.responseText);
  86.                     b.debug ? console.log(b.message) : a.Functions.showMessage(b.message, a.Functions.MSG_ERROR_TYPE);
  87.                     c.enableActions()
  88.                 },
  89.                 dataType: "JSON"
  90.             })
  91.         },
  92.         ".mpsl_delete_slide click": function(e) {
  93.             var c = this;
  94.             this.disableActions();
  95.             var b = e.attr("data-id");
  96.             d.ajax({
  97.                 type: "POST",
  98.                 url: a.Vars.ajax_url,
  99.                 data: {
  100.                     action: "mpsl_delete_slide",
  101.                     nonce: a.Vars.nonces.delete_slide,
  102.                     id: b
  103.                 },
  104.                 success: function(c) {
  105.                     a.Functions.showMessage(a.Vars.lang.slide_deleted.replace("%d", b), a.Functions.MSG_SUCCESS_TYPE);
  106.                     window.location.reload(!0)
  107.                 },
  108.                 error: function(b) {
  109.                     b = d.parseJSON(b.responseText);
  110.                     b.debug ? console.log(b.message) : a.Functions.showMessage(b.message, a.Functions.MSG_ERROR_TYPE);
  111.                     c.enableActions()
  112.                 },
  113.                 dataType: "JSON"
  114.             })
  115.         },
  116.         ".mpsl_duplicate_slide click": function(e) {
  117.             var c = this;
  118.             c.disableActions();
  119.             e = e.attr("data-id");
  120.             d.ajax({
  121.                 type: "POST",
  122.                 url: a.Vars.ajax_url,
  123.                 data: {
  124.                     action: "mpsl_duplicate_slide",
  125.                     nonce: a.Vars.nonces.duplicate_slide,
  126.                     id: e
  127.                 },
  128.                 success: function(b) {
  129.                     b.hasOwnProperty("result") && (a.Functions.showMessage(a.Vars.lang.slide_duplicated, a.Functions.MSG_SUCCESS_TYPE), window.location.reload(!0));
  130.                     c.enableActions()
  131.                 },
  132.                 error: function(b) {
  133.                     b = d.parseJSON(b.responseText);
  134.                     b.debug ? console.log(b.message) :
  135.                         a.Functions.showMessage(b.message, a.Functions.MSG_ERROR_TYPE);
  136.                     c.enableActions()
  137.                 },
  138.                 dataType: "JSON"
  139.             })
  140.         }
  141.     })
  142. })(jQuery, MPSL);
  143. jQuery(function(d) {
  144.     new MPSL.SlidesPageController(".mpsl-wrapper")
  145. });

Raw Paste

Login or Register to edit or fork this paste. It's free.