authData.vm 8.79 KB

#set($page_title="编辑")
#set($crumbs="首页:/home,编辑")

#set($url_save = "/dataAuth/save.do")
#set($url_data_auth = "/dataAuth/preSave.do")

<script type="text/javascript" src="/static/js/jquery.json.min.js"></script>
<script type="text/javascript" src="/static/js/modal.js"></script>

<div class="modal fade" id="progress_bar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">        
        <h4 class="modal-title" id="myModalLabel">操作进行中......</h4>
      </div>
      <div class="modal-body">
        <div class="progress">
          <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
            0%
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="page-content">
    <div class="page-header">
        <span class="pull-right">
            <a href="javascript:history.back()" class="btn btn-white btn-default">返回</a>
        </span>
        <h1>

            <small>
                <i class="icon-double-angle-right"></i>
            数据权限
            </small>
        </h1>
    </div>
    <!-- /.page-header -->

    <div>
    <ul class="nav nav-tabs">
        #foreach($item in $itemList)
##            <li role="presentation" class="active"><a href="#">$item.v</a></li>
            <li role="presentation" #if(${obj.type}==${item.type}) class="active" #end ><a href="${url_data_auth}?userId=${obj.userId}&type=${item.type}">$item.label</a></li>
        #end
##        <li role="presentation" class="active"><a href="#">城市</a></li>
##        <li role="presentation"><a href="#">Profile</a></li>
##        <li role="presentation"><a href="#">Messages</a></li>
    </ul>
    </div>

    <div class="row">
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->

            <form class="form-horizontal" role="form" method="post" action="$url_save">
                <input type="hidden" id="form-field-1" placeholder="" name="type" value="$obj.type">
                <input type="hidden" id="form-field-2" placeholder="用户ID" name="userId" value="$!{obj.userId}">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right"
                               for="form-field-3"> 数据权限ID: </label>
                        <div class="col-xs-12 col-sm-4">
                            <input type="checkbox" value="-1" name="dataId" id="selectAll" #if(${obj.dataId} == -1) checked #end>全部
##                            <input type="text" id="form-field-3"
##                                   placeholder="数据权限ID" name="dataId"
##                                   value="$!{obj.dataId}"
##                                   class="width-100">
                            <div id="cityBox" class="ztree" #if(${obj.dataId} == -1) style="display: none" #end></div>
                        </div>
                    </div>

                <div id="formHidden"></div>

                <div class="clearfix form-actions">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn btn-info" type="button" id="submitbtn">
                            <i class="icon-ok bigger-110"></i>
                            提交
                        </button>

                        &nbsp; &nbsp; &nbsp;
                        <a class="btn btn-info" href="javascript:history.back()">
                            <i class="icon-undo bigger-110"></i>
                            返回
                        </a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<link rel="stylesheet" href="/static/module/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="/static/module/ztree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="/static/module/ztree/js/jquery.ztree.excheck-3.5.js"></script>


<script type="text/javascript">
        $("#selectAll").click(function(){
            if($(this).is(":checked")){
                ##$("#cityBox").hide();
    			window.tree.checkAllNodes(true);
            }else{
                ##$("#cityBox").show();
    			window.tree.checkAllNodes(false);
            }
        });

        #macro(makeDataTree $tree)
            #foreach(${item} in ${tree})
                #if($velocityCount> 1),#end{
                    id:$!{item.id},
                    name: '$!{item.name}',
					parentId:'$!{item.parentId}'
                #if(${das.contains(${item.id})})
                        , checked: true
                #end
                #if(${item.children} && ${item.children.size()} > 0)					
    ##                        ,open:true
                            ,isParent: true
                            , children: [
                        #makeDataTree(${item.children})					
                ]
                #end
        }
            #end
        #end
    var znodes = [
        #makeDataTree(${authData})
    ];
    var setting = {
        check: {
            enable: true
        }
##        , async: {
##            enable: true
##            , autoParam: ["id=parent"]
##            , dataType: "json"
##            , url: "$!{webUtils.getLocalPath("/dataAuth/city.do")}"
##            , dataFilter: function (treeId, parentNode, resp) {
##                var citys = new Array();
##                for(var i in resp) {
##                    obj = resp[i];
##                    if(obj.level > 2) {
##                        continue;
##                    }
##                    city = {
##                        "name":obj.regionName
##                        ,"id":obj.regionId
##                    }
##                    if(obj.level < 2) {
##                        city["isParent"]=true;
##//                        city["nocheck"]=true;
##                    } else {
##//                        city["nocheck"]=false;
##                        city["isParent"]=false;
##                    }
##                    citys.push(city)
##                }
##                return citys;
##            }
##        }
    };

    $(function(){
        window.tree = $.fn.zTree.init($("#cityBox"), setting, znodes);
		window.tree.isCheckedAll=function(){
			var nodes= window.tree.transformToArray(window.tree.getNodes());
			var len=nodes.length;
			for(var i=0;i<len;i++){
				if(nodes[i].checked==false)
					return false;
			}
			return true;
		}
		window.tree.setting.callback.onCheck=function(evt,tid,tnode){
			if(tnode.checked==false)
				$('#selectAll').prop('checked',false);
		};
		#if($das.contains("-1"))
		window.tree.checkAllNodes(true);
		#end
        $("#submitbtn").click(function(){
			$('#selectAll').prop('checked',window.tree.isCheckedAll());
            var div = $("#formHidden");
            div.html("");
            var items = tree.getCheckedNodes();
			var arr=[];
			$(items).each(function(index,item){
				var obj={dataId:item.id,label:item.name,parentDataId:item.parentId==''?0:item.parentId};
				arr.push(obj);
			});
			var params={
				params: $.toJSON(arr),
				type: $('#form-field-1').val(),
				userId: $('#form-field-2').val()
			};
			var progressBar=$('#progress_bar .progress-bar');
			$('#progress_bar').on('hidden.bs.modal', function (e) {
				progressBar.attr('aria-valuenow', 0);
				progressBar.text('0%');
				progressBar.css('width', '0%');
            })
    		$('#progress_bar').modal({
        		backdrop:false,
        		keyboard:false
    		});
			progressBar.interval= window.setInterval(function(){
    			var tmp = progressBar.attr('aria-valuenow');
    			var progress=parseInt(tmp);
				var increase=progress + Math.round((Math.random() + 1) * 10);
				if(increase < 100){
					progressBar.attr('aria-valuenow', increase);
					progressBar.text(increase + '%');
					progressBar.css('width', increase + '%');
				}else{					
					window.clearInterval(progressBar.interval);
				}
			},1000);
			$.post('$url_save', params, function(data){
				if(data.success){
					window.clearInterval(progressBar.interval);
					window.bs.MessageBox.alert('提示','操作成功');
				}else{
					window.bs.MessageBox.alert('提示',data.message);
				}
				progressBar.attr('aria-valuenow', 100);
				progressBar.text('100%');
				progressBar.css('width', '100%');
				$('#progress_bar').modal('hide');
			}, 'json');
            ##for(var i in items) {
            ##    var item = items[i];
            ##    var hi = "<input type='hidden' name='dataIds' value='"+item.id+"'>"
            ##    div.append(hi);
            ##    var hilabel = "<input type='hidden' name='labels' value='"+item.name+"'>"
            ##    div.append(hilabel);
            ##}
        });
		$('#selectAll').prop('checked',window.tree.isCheckedAll());
		
    })

</script>