Complex editing in front-end Web pages

Source: Internet
Author: User

Complex editing in front-end Web pages

Source

/************************************************** global variable **************************************************///var all_service = null;varall_modules=NULL;varSelected_id= ";/************************************************** Auxiliary Method **************************************************/functionshow_error (Request, Textstatus, Errorthrown) {$ ("#list_div"). HTML ("<div style= ' text-align:center;width:100%; float:left;color:red; ' > No data obtained, please <a href= ' javascript:location.reload (); ' > Refresh </a></div> "+" <div class= ' error_div ' style= ' Display:none; ' > Server request error: status = ' + Textstatus + ' \ n message = "+ Errorthrown +" <br/> "+ Request.responsetext +" </div> ");}functionInit_parent_select (parentid,id) {$ ("#ParentModule"). empty (); $("#ParentModule"). Append ("<option value=" > (top module) </option> ");  for(vari=0;i<all_modules.length;i++)    {        if(All_modules[i]. parentmodule== " )        {            if(ID) {if(all_modules[i].id!=ID) {$ ("#ParentModule"). Append ("<option value=" + all_modules[i]. Id + "' >" + all_modules[i]. ModuleName + "</option>"); }            }            Else            {                $("#ParentModule"). Append ("<option value=" + all_modules[i]. Id + "' >" + all_modules[i]. ModuleName + "</option>"); }        }    }    if(ParentID) {$ ("#ParentModule"). Val (ParentID); }}functionClear_form () {$ ("#ModuleName"). Val (""); $("#ModulePackage"). Val (""); $("#service_sel"). empty (); $("#ParentModule"). Val (');} functionInit_form (model) {if(model) {$ ("#ModuleName"). val (model.        ModuleName); $("#ModulePackage"). val (model.        Modulepackage); Init_parent_select (model.        Parentmodule,model.id); $("#service_sel"). empty (); //$ ("#service_sel_all"). empty ();Ajax_post ("/module/getservice/"        , "JSON", {Id:model. Id},function(Result) {//log (result);            varrevices = eval (' (' + result + ') '); //var revices = result;            //result = Result.parsejson ();            //log (revices);            //log (revices.length)             for(vari = 0; i < revices.length; i++) {                varService =Revices[i]; //log (service);$ ("#service_sel"). Append ("<option value=" + service. Id + "' >" + service. ServiceName + "V" +service. Serviceversion+ "-" + service. ServiceDescription + "</option>"); }            $("#load_service_msg_span"). HTML (""); }, Show_error,"#load_service_msg_span"        ); }    Else{clear_form (); }}/************************************************** module Operation **************************************************/functionAdd_module () {if(!ValidateData ()) {        return; }    varParentID = $ (' #ParentModule '). Val (); varModuleName = $ (' #ModuleName '). Val (); varModulepackage = $ (' #ModulePackage '). Val (); varids = []; $("#service_sel option"). each (function(i, E) {Ids.push ($ (e). Val ());    }); Ajax_post ("/module/add/"        ,"Text", {modulename:modulename, modulepackage:modulepackage, Service_sel:ids.join (","), Parentmodule:parentid},function(Result) {alert ("Add Success"); selected_id=result;        Loadtree (); }, Show_error);}functionSave_module () {if(!selected_id) {Alert ("Please select module"); return; }    if(!ValidateData ()) {        return; }    varParentID = $ (' #ParentModule '). Val (); varID =selected_id; varModuleName = $ (' #ModuleName '). Val (); varModulepackage = $ (' #ModulePackage '). Val (); varids = []; $("#service_sel option"). each (function(i,e) {Ids.push ($ (e). Val ());    }); Ajax_post ("/module/save/"        ,"JSON", {id:id, modulename:modulename, Modulepackage:modulepackage, Service_sel:ids.join (","), Parentmodule:parentid},function(Result) {alert ("Saved successfully");        Loadtree (); }, Show_error);}functionDel_module () {if(!selected_id) {Alert ("Please select module"); return; }    if(!confirm ("Are you sure you want to delete it?"))) {        return false; } ajax_post ("/module/del/"        ,"JSON", {id:selected_id},function(Result) {loadtree ();            Clear_form (); selected_id=NULL; }, Show_error);}functionValidateData () {varresult =true; varmsg = "; if($.trim ($ ("#ModuleName"). val ()) = = ") {msg+ = "Module name cannot be empty \ n"; Result=false; }    if($.trim ($ ("#ModulePackage"). val ()) = = ") {msg+ = "Package name cannot be empty \ n"; Result=false; }    if(!result)    {alert (msg); }    returnresult;}varsetting ={view: {dblclickexpand:false, ShowLine:true, Selectedmulti:false}, Data: {simpledata: {enable:true//,}}, callback: {Onclick:onclick}};functionOnClick (event, Treeid, TreeNode, Clickflag) { for(vari=0;i<all_modules.length;i++)    {        varModel =All_modules[i]; if(model. id==treenode.id) {init_form (model); selected_id=treenode.id; return; }} selected_id= ' ';}functionLoadtree (afterget) {ajax_post ("/module/getallmodule/"        , "JSON"        , {}        , function(Result) {$ ("#load_module_msg_span"). HTML (""); All_modules=result;  for(vari = 0; i < all_modules.length; i++) {All_modules[i].open=true; }            varZtree = $.fn.ztree.init ($ ("#ztree_ul"), setting, result); if(selected_id! = ") {                varnode = Ztree.getnodesbyparam ("id", selected_id); if(node) {node.checked=true; $ (node). Trigger ("Click"); }                Else{clear_form (); }            }            if(afterget) {afterget (); }}, Show_error,"#load_module_msg_span"    );} $ (document). Ready (function () {    /** * * load all modules into a tree and load to all top-level modules * * * **/Loadtree (function() {init_parent_select ();} );functionShowadddialog () {varSelected = []; $("#service_sel option"). each (function(i, E) {Selected.push ($ (e). Val ());    }); varAdd_service_dialog =$.dialog ({title:"Add Service", Width:' 700px ', Height:' 450px ', padding:5,        //content: ' url:/service/dialogservicelist/?selected= ' + selected.join (', '),Content: ' url:/service/dialogservicelist/',        //data:{selected:selected.join (', ')},Init:function () {             This. Content. SetSelected (Selected.join (', '))); }, Okval:Determine, OK:function () {            varresult = This. Content.            Getselectedservices (); varTemplate = $ ("#service_template"). html ();  for(vari = 0; i < result.length; i++) {                //log (service);                varService =Result[i]; $("#service_sel"). Append ("<option value=" + service. Id + "' >" + service. ServiceName + "V" + service. Serviceversion + "-" + service. ServiceDescription + "</option>"); }}, Cancelval:Close, Cancel:true /*true is equivalent to function () {}*/    });}functionDelservice () {varSelected = $ (' #service_sel option:selected '); $ (selected). Remove ();

Complex editing within a front-end Web 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.