github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/public/widgets.js (about) 1 "use strict"; 2 $(document).ready(() => { 3 let clickHandle = function(ev){ 4 log("in clickHandle") 5 ev.preventDefault(); 6 let ep = $(this).closest(".editable_parent"); 7 ep.find(".hide_on_block_edit").addClass("edit_opened"); 8 ep.find(".show_on_block_edit").addClass("edit_opened"); 9 ep.addClass("in_edit"); 10 11 ep.find(".widget_save").click(() => { 12 ep.find(".hide_on_block_edit").removeClass("edit_opened"); 13 ep.find(".show_on_block_edit").removeClass("edit_opened"); 14 ep.removeClass("in_edit"); 15 }); 16 17 ep.find(".widget_delete").click(function(ev) { 18 ev.preventDefault(); 19 ep.remove(); 20 let formData = new URLSearchParams(); 21 formData.append("s",me.User.S); 22 let req = new XMLHttpRequest(); 23 let target = this.closest("a").getAttribute("href"); 24 req.open("POST",target,true); 25 req.send(formData); 26 }); 27 }; 28 29 $(".widget_item a").click(clickHandle); 30 31 let changeHandle = function(ev){ 32 let wtype = this.options[this.selectedIndex].value; 33 let typeBlock = this.closest(".widget_edit").querySelector(".wtypes"); 34 typeBlock.className = "wtypes wtype_"+wtype; 35 }; 36 $(".wtype_sel").change(changeHandle); 37 38 $(".widget_new a").click(function(ev){ 39 log("clicked widget_new a") 40 let widgetList = this.closest(".panel_widgets"); 41 let widgetNew = this.closest(".widget_new"); 42 let widgetTmpl = document.getElementById("widgetTmpl").querySelector(".widget_item"); 43 let n = widgetTmpl.cloneNode(true); 44 n.querySelector(".wside").value = this.getAttribute("data-dock"); 45 widgetList.insertBefore(n,widgetNew); 46 $(".widget_item a").unbind("click"); 47 $(".widget_item a").click(clickHandle); 48 $(".wtype_sel").unbind("change"); 49 $(".wtype_sel").change(changeHandle); 50 }); 51 52 $(".widget_save").click(function(ev){ 53 log("in .widget_save") 54 ev.preventDefault(); 55 ev.stopPropagation(); 56 let pform = this.closest("form"); 57 let dat = new URLSearchParams(); 58 for (const pair of new FormData(pform)) dat.append(pair[0], pair[1]); 59 dat.append("s",me.User.S); 60 var req = new XMLHttpRequest(); 61 req.open("POST",pform.getAttribute("action")); 62 req.send(dat); 63 }); 64 });