[TASK] Migrate LayoutModule/DragDrop.js to TypeScript
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / AjaxDataHandler.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13 define(["require","exports","./Enum/Severity","jquery","./Icons","./Modal","./Notification","./Viewport"],function(e,t,a,n,i,o,r,l){"use strict";var d,s;Object.defineProperty(t,"__esModule",{value:!0}),(s=d||(d={})).hide=".t3js-record-hide",s.delete=".t3js-record-delete",s.icon=".t3js-icon";var c=function(){function e(){var e=this;n(function(){e.initialize()})}return e.refreshPageTree=function(){l.NavigationContainer&&l.NavigationContainer.PageTree&&l.NavigationContainer.PageTree.refreshTree()},e.prototype.process=function(e){var t=this;return this._call(e).done(function(e){e.hasErrors&&t.handleErrors(e)})},e.prototype.initialize=function(){var e=this;n(document).on("click",d.hide,function(t){t.preventDefault();var a=n(t.currentTarget),i=a.find(d.icon),o=a.closest("tr[data-uid]"),r=a.data("params");e._showSpinnerIcon(i),e._call(r).done(function(t){t.hasErrors?e.handleErrors(t):e.toggleRow(o)})}),n(document).on("click",d.delete,function(t){t.preventDefault();var i=n(t.currentTarget);o.confirm(i.data("title"),i.data("message"),a.SeverityEnum.warning,[{text:i.data("button-close-text")||TYPO3.lang["button.cancel"]||"Cancel",active:!0,btnClass:"btn-default",name:"cancel"},{text:i.data("button-ok-text")||TYPO3.lang["button.delete"]||"Delete",btnClass:"btn-warning",name:"delete"}]).on("button.clicked",function(t){"cancel"===t.target.getAttribute("name")?o.dismiss():"delete"===t.target.getAttribute("name")&&(o.dismiss(),e.deleteRecord(i))})})},e.prototype.toggleRow=function(t){var a,o,r,l=t.find(d.hide),s=l.closest("table[data-table]").data("table"),c=l.data("params");"hidden"===l.data("state")?(o="visible",a=c.replace("=0","=1"),r="actions-edit-hide"):(o="hidden",a=c.replace("=1","=0"),r="actions-edit-unhide"),l.data("state",o).data("params",a),l.tooltip("hide").one("hidden.bs.tooltip",function(){var e=l.data("toggleTitle");l.data("toggleTitle",l.attr("data-original-title")).attr("data-original-title",e).tooltip("show")});var f=l.find(d.icon);i.getIcon(r,i.sizes.small).done(function(e){f.replaceWith(e)});var u=t.find(".col-icon "+d.icon);"hidden"===o?i.getIcon("miscellaneous-placeholder",i.sizes.small,"overlay-hidden").done(function(e){u.append(n(e).find(".icon-overlay"))}):u.find(".icon-overlay").remove(),t.fadeTo("fast",.4,function(){t.fadeTo("fast",1)}),"pages"===s&&e.refreshPageTree()},e.prototype.deleteRecord=function(t){var a=this,n=t.data("params"),o=t.find(d.icon);this._showSpinnerIcon(o),this._call(n).done(function(n){if(i.getIcon("actions-edit-delete",i.sizes.small).done(function(e){(o=t.find(d.icon)).replaceWith(e)}),n.hasErrors)a.handleErrors(n);else{var r=t.closest("table[data-table]"),l=t.closest(".panel"),s=l.find(".panel-heading"),c=r.data("table"),f=t.closest("tr[data-uid]"),u=f.data("uid"),p=r.find("[data-l10nparent="+u+"]").closest("tr[data-uid]");if((f=f.add(p)).fadeTo("slow",.4,function(){f.slideUp("slow",function(){f.remove(),0===r.find("tbody tr").length&&l.slideUp("slow")})}),"0"===t.data("l10parent")||""===t.data("l10parent")){var h=Number(s.find(".t3js-table-total-items").html());s.find(".t3js-table-total-items").text(h-1)}"pages"===c&&e.refreshPageTree()}})},e.prototype.handleErrors=function(e){n.each(e.messages,function(e,t){r.error(t.title,t.message)})},e.prototype._call=function(e){return n.getJSON(TYPO3.settings.ajaxUrls.record_process,e)},e.prototype._showSpinnerIcon=function(e){i.getIcon("spinner-circle-dark",i.sizes.small).done(function(t){e.replaceWith(t)})},e}();t.default=new c});