7a3d7dc296a1a9f8a7fe97688bcaa42b9506612b
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / PageActions.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/KeyTypes","jquery","./Storage/Persistent","./Wizard/NewContentElement"],function(t,e,n,i,a,o){"use strict";var s,c;return(c=s||(s={})).pageTitle=".t3js-title-inlineedit",c.hiddenElements=".t3js-hidden-record",c.newButton=".t3js-toggle-new-content-element-wizard",new(function(){function e(){var t=this;this.pageId=0,this.pageOverlayId=0,this.$pageTitle=null,this.$showHiddenElementsCheckbox=null,i(function(){t.initializeElements(),t.initializeEvents(),t.initializeNewContentElementWizard(),t.initializePageTitleRenaming()})}return e.prototype.setPageId=function(t){this.pageId=t},e.prototype.setLanguageOverlayId=function(t){this.pageOverlayId=t},e.prototype.initializePageTitleRenaming=function(){var t=this;if(i.isReady){if(!(this.pageId<=0)){var e=i('<a class="hidden" href="#" data-action="edit"><span class="t3-icon fa fa-pencil"></span></a>');e.on("click",function(e){e.preventDefault(),t.editPageTitle()}),this.$pageTitle.on("dblclick",function(){t.editPageTitle()}).on("mouseover",function(){e.removeClass("hidden")}).on("mouseout",function(){e.addClass("hidden")}).append(e)}}else i(function(){t.initializePageTitleRenaming()})},e.prototype.initializeElements=function(){this.$pageTitle=i(s.pageTitle+":first"),this.$showHiddenElementsCheckbox=i("#checkTt_content_showHidden")},e.prototype.initializeEvents=function(){this.$showHiddenElementsCheckbox.on("change",this.toggleContentElementVisibility)},e.prototype.toggleContentElementVisibility=function(t){var e=i(t.currentTarget),n=i(s.hiddenElements),o=i("<span />",{class:"checkbox-spinner fa fa-circle-o-notch fa-spin"});e.hide().after(o),e.prop("checked")?n.slideDown():n.slideUp(),a.set("moduleData.web_layout.tt_content_showHidden",e.prop("checked")?"1":"0").done(function(){o.remove(),e.show()})},e.prototype.editPageTitle=function(){var t=this,e=i('<form><div class="form-group"><div class="input-group input-group-lg"><input class="form-control"><span class="input-group-btn"><button class="btn btn-default" type="button" data-action="submit"><span class="t3-icon fa fa-floppy-o"></span></button> </span><span class="input-group-btn"><button class="btn btn-default" type="button" data-action="cancel"><span class="t3-icon fa fa-times"></span></button> </span></div></div></form>'),a=e.find("input");e.find("[data-action=cancel]").on("click",function(){e.replaceWith(t.$pageTitle),t.initializePageTitleRenaming()}),e.find("[data-action=submit]").on("click",function(){var n=i.trim(a.val());""!==n&&t.$pageTitle.text()!==n?t.saveChanges(a):e.find("[data-action=cancel]").trigger("click")}),a.parents("form").on("submit",function(t){return t.preventDefault(),!1});var o=this.$pageTitle;o.children().last().remove(),o.replaceWith(e),a.val(o.text()).focus(),a.on("keyup",function(t){switch(t.which){case n.KeyTypesEnum.ENTER:e.find('[data-action="submit"]').trigger("click");break;case n.KeyTypesEnum.ESCAPE:e.find('[data-action="cancel"]').trigger("click")}})},e.prototype.saveChanges=function(e){var n=this,i=e.parents("form");i.find("button").addClass("disabled"),e.attr("disabled","disabled");var a,o={};a=this.pageOverlayId>0?this.pageOverlayId:this.pageId,o.data={},o.data.pages={},o.data.pages[a]={title:e.val()},t(["TYPO3/CMS/Backend/AjaxDataHandler"],function(t){t.process(o).done(function(){i.find("[data-action=cancel]").trigger("click"),n.$pageTitle.text(e.val()),n.initializePageTitleRenaming(),top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree()}).fail(function(){i.find("[data-action=cancel]").trigger("click")})})},e.prototype.initializeNewContentElementWizard=function(){i(s.newButton).click(function(t){var e=i(t.currentTarget);o.wizard(e.data("url"),e.data("title"))})},e}())});