Added delete save function in JavaScript page!

Source: Internet
Author: User

$doc. On (' click ', '. Btn-funnel-new,.edit_funnel,.charts_add,.postcharts,.charts_remove,.del_funnel ', function (e) {

E.stoppropagation ();

E.preventdefault ();

var _this = $ (this);

var Odialog = $ (' #chartsModal ');

Switch (TRUE) {

Case _this.is ('. Btn-funnel-new ')://add

Odialog.modal (' show ');

$ (' #hid_name '). Val (' 1 ');

Break

Case _this.is ('. Edit_funnel ')://edit

Odialog.modal (' show ');

$ (' #hid_name '). Val (' 2 ');

var oTr = _this.parents (' tr ');

var idx = otr.attr (' id ');

$ (' #hid_bj '). Val (idx);

var Tmpl = $ ('. Charts-tem. Charts_templ ');

var request={

Eid_idx:idx,

}

var ajax = $.ajax ({

Type: ' POST ',

Url:getroleuserurls (' Get '),

Data:request,

Success:function (response) {

if (typeof response = = = ' String ') response = $.parsejson (response);

if (response.success = = 1) {

Odialog.find ('. Textname '). Val (Response.data.tempname);

Odialog.find ('. Charts_templ '). Remove ();

Createresponse (response.data.points);

Console.log (response.data.points);

}

}

});

function Createresponse (data) {

if (!data) return;

var tmpls = [];

$.each (Data,function () {

var _tmpl = Tmpl.clone ();

$ ('. Modal-title '). Text (' edit ');

_tmpl.find (' input[name=t] '). Val (THIS.T);

_tmpl.find (' input[name=tmpl_name] '). Val (This.point_name);

_tmpl.find (' Input[name=sell] '). Val (this.name);

_tmpl.find (' Input[name=shun] '). Val (This.display_index);

Tmpls.push (_tmpl);

});

if (!! Tmpls.length) {

var oform = Odialog.find ('. Form-horizontal ');

var dom = Oform.children (). Last ();

(!! dom.length)? Dom.after (TMPLS): Oform.append (TMPLS);

}

}

Break

Case _this.is ('. Charts_add ')://sub_add

var Otmpl = $ ($ ('. Charts-tem '). html ());

var ogroup = _this.parents ('. Charts_templ ');

if (ogroup.length) {

Ogroup.index () = = Ogroup.parent (). Children (). Length-1? Ogroup.after (Otmpl.clone ()): Ogroup.after (Otmpl.clone ());

}

$ ('. Charts_remove ') [0].style.display = ' inline-block ';

Break

Case _this.is ('. Postcharts ')://add

var odialog = _this.parents (' #chartsModal ');

var tname = Odialog.find (' input[name=textname] '). Val ();

/ * var _t = $ ('. T '), Val ();

var _tmpl_name = $ ('. Tmpl_name '). Val ();

var _sell = $ ('. Sell '). Val ();

var _shun = $ ('. Shun '). Val ();

if (_t.length = ' && _tmpl_name.length = ' && _sell.length = ' && _shun.length = ') {

Alert ("Please complete the contents!") ");

return false;

}  */

var idx = $ (' #hid_bj '). Val ();

var rule = {};

$ ('. Charts_templ ', Odialog). Each (function (i,v) {

var ary = {};

var _me = $ (this);

$.each (_me.find (' input '), function () {

Ary[this.name] = This.value;

});

Rule[i] = ary;

})

var h_input = $ (' #hid_name '). Val ();

if (h_input = = 1) {

var request = {

Textname:tname,

Rule:rule

};

var ajax = $.ajax ({

Type: ' POST ',

Url:getroleuserurls (' Add '),

Data:request

});

}else if (h_input = = 2) {

var request = {

Textname:tname,

Rule:rule,

Eid_idx:idx

}

var ajax = $.ajax ({

Type: ' POST ',

Url:getroleuserurls (' edit '),

Data:request

});

}

Ajax.done (function (ret) {

if (typeof ret = = = ' String ') ret = $.parsejson (ret);

if (ret.success = = 1) {

$ (' #chartsModal '). Modal (' hide ');

Window.location.reload ();

}else{

Alert (' ERROR: ' +ret.info);

}

});

Break

Case _this.is (". Charts_remove"):

$ (this). Parent (). Parent (). remove ();

var oGroup1 = $ ('. Charts_templ ');

if (ogroup1.length = = 2) {

Console.log ($ ('. Charts_remove '));

$ ('. Charts_remove ') [0].style.display = ' none ';

}

Break

Case _this.is ('. Del_funnel '):

var idx = $ (this). Parent (). Parent (). index ();

var noticeidx = $ ('. Custom-table '). Find (' tr '). EQ (idx). attr (' id ');

var request = {

Ids:noticeidx

};

var ajax = $.ajax ({

Type: ' POST ',

Url:getroleuserurls (' del '),

Data:request

});

Ajax.done (function (ret) {

if (typeof ret = = = ' String ') ret = $.parsejson (ret);

if (ret.success = = 1) {

$ (' #chartsModal '). Modal (' hide ');

Window.location.reload ();

}else{

Alert (' ERROR: ' +ret.info);

}

});

}

});


Added delete save function in JavaScript page!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.