var sUtil = null; $(function(){ sUtil = new SearchUtil(); }); $(function(){ init(); }); function init(){ $(".upload_btn").on("click",function(){ var mt = $(".select_item").attr("modulescode"); window.parent.window.openUploadLegend(mt); }); $(".save_btn").on("click",function(){ var i = 0; var params = {}; $(".lengen_item").each(function(index){ params[$(this).data("data").FD_OBJECTID] = index+10; i++; }); if(i > 0){ var sortParams = JSON.stringify(params); $.post('/nwyj/ws/icingZmap/IcingZmapService/updateLengenSort',{sort:sortParams},function(data){ if(data.state=="success") top.Dialog.alert("保存成功!"); },'json'); }else if(i==0){ top.Dialog.alert("没有要保存的图例,请上传!"); }; }); $(".sbject_item").on("click",function(){ $(".select_item").removeClass("select_item"); $(this).addClass("select_item"); var url = '/nwyj/ws/icingZmap/IcingZmapService/getLengend' ; var legenddata = sUtil.getJsonData(url, {map_type:$(this).attr("modulescode")}); if(legenddata.rows.length > 0){ createLegendItem(legenddata.rows); }else{ var $none_leg_div = document.createElement("div"); $($none_leg_div).addClass("none_leg").html("该专题没有图例,请点击右下角“上传图例”上传。"); $(".lengend_img_box").empty().append($none_leg_div); }; }); $(".sbject_item[modulescode='"+sUtil.resolveUrl().mt_id+"']").eq(0).click(); }; function refreshLegend(){ $(".sbject_item[modulescode='"+sUtil.resolveUrl().mt_id+"']").eq(0).click(); }; function createLegendItem(params){ var leg = '/nwyj/upload/icinglegend/'; var $portfolio_ul = document.createElement("ul"); $($portfolio_ul).addClass("portfolio-items"); var resSort = params.sort(function(a,b){ return a.LENGEND_SORT - b.LENGEND_SORT; }); for(var i = 0; i < params.length; i++){ var $lengen_li = document.createElement("li"); var $legend_img = document.createElement("img"); $($legend_img).attr("src",leg+params[i]["LENGEND_NAME"]+"."+params[i]["LENGEND_TYPE"]).addClass("lengen_img"); var $legend_des_input = document.createElement("input"); $($legend_des_input).addClass("lengen_desc none_border").attr("title",params[i]["LENGEND_DESC"]).val(params[i]["LENGEND_DESC"]).attr("readonly","readonly"); var $leg_edit_box_div = document.createElement("div"); $($leg_edit_box_div).addClass("lengen_edit_btn_box").append(createEidtBtn()).append(createDelBtn()).append(createSortBtn()); $($lengen_li).addClass("lengen_item").append($legend_img).append($legend_des_input).append($leg_edit_box_div).data("data",params[i]); $($portfolio_ul).append($lengen_li); }; $(".lengend_img_box").empty().append($portfolio_ul); }; function createEidtBtn(){ var $edit_btn_div = document.createElement("div"); $($edit_btn_div).addClass("lengen_btn edit_btn").attr("title","编辑").on("click",function(){ $(this).parent().prev().removeAttr("readonly").removeClass("none_border"); $(this).parent().empty().append(createSaveBtn()).append(createCelBtn()); }); return $edit_btn_div; }; function createDelBtn(){ var $edit_btn_div = document.createElement("div"); $($edit_btn_div).addClass("lengen_btn del_btn").attr("title","删除").on("click",function(){ var $item = $(this).parent().parent(); top.Dialog.confirm("确定要删除吗?",function(){ var param = $($item).data("data"); var url = '/nwyj/ws/icingZmap/IcingZmapService/delLengend' ; var legenddata = sUtil.getJsonData(url, {fd_id:param.FD_OBJECTID}); if(legenddata.state=="success"){ $($item).remove(); }else{ top.Dialog.alert("删除失败"); }; },function(){ return false; }); }); return $edit_btn_div; }; function createSaveBtn(){ var $save_btn_div = document.createElement("div"); $($save_btn_div).addClass("lengen_btn save_btn").attr("title","保存").on("click",function(){ var param = $(this).parent().parent().data("data"); var str = $.trim($(this).parent().prev().val()); if(str==""){ top.Dialog.alert("描述不能为空"); return ; }else if(str.length>50){ top.Dialog.alert("只能输入50个字"); return ; }; var url = '/nwyj/ws/icingZmap/IcingZmapService/updateLengend' ; var fp = $.param({fd_id:param.FD_OBJECTID, val:str}); var legenddata = sUtil.getJsonData(url, fp); if(legenddata.state=="success"){ top.Dialog.alert("保存成功!"); $(this).parent().prev().attr("title",str).attr("readonly","readonly").addClass("none_border"); }else{ top.Dialog.alert("编辑失败!"); var tit = $(this).parent().prev().attr("title"); $(this).parent().prev().val(tit).attr("readonly","readonly").addClass("none_border"); } $(this).parent().empty().append(createEidtBtn()).append(createDelBtn()); }); return $save_btn_div; }; function createCelBtn(){ var $cel_btn_div = document.createElement("div"); $($cel_btn_div).addClass("lengen_btn del_btn").attr("title","取消").on("click",function(){ var str = $(this).parent().prev().attr("title"); $(this).parent().prev().val(str).attr("readonly","readonly").addClass("none_border"); $(this).parent().empty().append(createEidtBtn()).append(createDelBtn()); }); return $cel_btn_div; }; function createSortBtn(){ var $sort_btn_div = document.createElement("div"); $($sort_btn_div).addClass("lengen_btn sort_btn").attr("title","上移").on("click",function(){ var $item = $(this).parent().parent(); var $afterItem = $(this).parent().parent().prev(); var afterItemPos = $($afterItem).height(); $($item).addClass("lengen_item_move"); $($item).stop(true).animate({top:0-(afterItemPos)},200); setTimeout(function(){ $($item).removeClass("lengen_item_move").removeAttr("style"); $($afterItem).before($item); },210); }); return $sort_btn_div; }