<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="edit.aspx.cs" Inherits="wjdhcms_SAAS.module.admin.edit" %>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>内容</title>
    <!-- start: CSS file-->
    <!-- Vendor CSS-->
    <link href="../static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="../static/vendor/skycons/css/skycons.css" rel="stylesheet" />
    <link href="../static/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
    <!-- Plugins CSS-->
    <link href="../static/plugins/bootkit/css/bootkit.css" rel="stylesheet" />
  

    <!-- Page CSS -->   
    <link href="../static/css/style.css" rel="stylesheet" />
    <link href="../static/css/add-ons.min.css" rel="stylesheet" />

    <!-- end: CSS file--> 
    <!-- Head Libs -->
    <script src="../static/plugins/modernizr/js/modernizr.js"></script>
    
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="../static/js/html5shiv.min.js"></script>
      <script src="../static/js/respond.min.js"></script>
    <![endif]-->
    




</head>

<body class="mainbody">
  <div class="container-fluid">
    <div class="row">
      <div class="col-lg-12">
        <div class="panel wizard-type1" id="wizard2">
          <form id="form" data-toggle="formcache">
                <div class="panel-heading bk-bg-primary">
                  <ul class="steps">
                      <li><a href="#tab11" data-toggle="tab"><span class="badge badge-info"><i class="fa fa-file-text"></i></span>系统基本信息</a></li>
                      <li><a href="#tab12" data-toggle="tab"><span class="badge badge-info"><i class="fa fa-sitemap"></i></span>权限设置</a></li>
                    </ul>
                    <div class="progress thin progress-striped active">
                      <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
                      </div>
                    </div>
                </div>
                <div class="panel-body">
                  <div>
                    <div class="tip">
                    </div>
                    <div class="tab-content">
                      <div class="tab-pane" id="tab11">
                          <div class="row">
                          <div class="col-sm-12">
                            <div class="form-horizontal">
                              <div class="form-group">
                                <label class="col-md-1 control-label" for="text-input">用户名</label>
                                <div class="col-md-3">
                                  <input type="text" id="username" name="username" class="form-control" value="">
                                </div>
                                <div class="col-md-2">
                                  <span class="help-block text-right"></span>
                                </div>
                              </div>
                              <div class="form-group">
                                <label class="col-md-1 control-label" for="text-input">密码</label>
                                <div class="col-md-3">
                                  <input type="text" id="password" name="password" class="form-control" value="">
                                </div>
                                <div class="col-md-2">
                                    <input type="hidden" id="hpassword" name="hpassword" class="form-control" value="">
                                  <span class="help-block text-right"></span>
                                </div>
                              </div>                              
                              <div class="form-group">
                                <label class="col-md-1 control-label" for="text-input">头像</label>
                                <div class="col-md-3 img-upload">
                                  <input type="text" id="img" name="img" class="form-control" value="">
                                  <div class="upload-box upload-img"></div>
                                </div>
                                <div class="col-md-2">
                                  <span class="help-block text-right"></span>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>

                      <div class="tab-pane" id="tab12">
                          <div class="row">
                            <div class="col-sm-12" id="jurisdiction">

                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="navbar-fixed-bottom" style="padding: 0 25px;">
                    <div class="actions">               
                      <input type="button" class="btn btn-info" id="submit" value="提交保存" />
                      <input type="button" class="btn btn-primary button-next" name="next" value="下一项" />
                    </div>
                    </div>
                  </div>
                </div>
                </form>
              </div>
      </div>
    </div>
  </div>

    <!-- start: JavaScript-->
    
    <!-- Vendor JS-->       
    <script src="../static/vendor/js/jquery-2.1.1.min.js"></script>
    <script src="../static/vendor/js/jquery-migrate-1.2.1.min.js"></script>
    <script src="../static/vendor/bootstrap/js/bootstrap.min.js"></script>
    
    <!-- Plugins JS-->
    <script src="../static/plugins/wizard/js/jquery.bootstrap.wizard.min.js"></script>
    <script src="../static/plugins/webuploader/webuploader.min.js"></script>
    <script src="../static/plugins/webuploader/imgupload.js"></script>
    <!-- Pages JS -->
    <script src="../static/js/pages/form-wizard.js"></script>
    <script src="../static/js/ajax.js"></script>
    <!-- end: JavaScript-->
   <script>

       $(function () {
           $(".upload-img").InitUploader({ filesize: "20480", sendurl: "../../api/upload_ajax.ashx", swf: "../static/plugins/webuploader/uploader.swf", filetypes: "gif,jpg,png" });
           if ($.getUrlParam('action') == 'edit') {
               get_json('../../api/admin.ashx?action=getedit&id=' + $.getUrlParam('id') + '', function (data) {
                   for (var attr in data.data) {
                       $('[name=' + attr + ']').val(data.data[attr]);
                   }
                   $('[name=hpassword]').val(data.data['password']);
                   $('[name=password]').val('');
                   var list = "";
                   for (var i = 0; i < data.data.authlist.length; i++) {
                       var list2 = "";
                       for (var k = 0; k < data.data.authlist[i].list.length; k++) {
                           list2 += ''
                           + '<ol class="dd-list">'
                               + '<li class="dd-item">'
                                   + '<div class="dd-handle">'
                                     + '<div class="checkbox-custom checkbox-inline">'
                                       + '<input type="checkbox" id="' + data.data.authlist[i].list[k].id + '" name="' + data.data.authlist[i].list[k].id + '" value="' + data.data.authlist[i].list[k].id + '"> '
                                       + '<label for="' + data.data.authlist[i].list[k].id + '">' + data.data.authlist[i].list[k].name + '</label>'
                                     + '</div>'
                                   + '</div>'
                               + '</li>'
                           + '</ol>'
                       };
                       list += ''
                         + '<div class="col-sm-4 col-md-2">'
                             + '<ol class="dd-list">'
                                 + '<li class="dd-item">'
                                     + '<div class="dd-handle">'
                                       + '<div class="checkbox-custom checkbox-inline">'
                                         + '<input type="checkbox" id="' + data.data.authlist[i].id + '" name="' + data.data.authlist[i].id + '" value="' + data.data.authlist[i].id + '"> '
                                         + '<label for="' + data.data.authlist[i].id + '">' + data.data.authlist[i].name + '</label>'
                                       + '</div>'
                                     + '</div>'
                                     + list2
                                 + '</li>'
                               + '</ol>'
                             + '</div>'
                   };
                   $('#jurisdiction').html(list);

                   var authArry = [];
                   authArry = data.data.auth.split(',')
                   for (var i = 0; i < authArry.length; i++) {
                       $('[name=' + authArry[i] + ']').attr('checked', true);
                   }
               })

           } else {
               get_json('../../api/admin.ashx?action=getadd', function (data) {
                   var list = "";
                   for (var i = 0; i < data.data.length; i++) {
                       var list2 = "";
                       for (var k = 0; k < data.data[i].list.length; k++) {
                           list2 += ''
                           + '<ol class="dd-list">'
                               + '<li class="dd-item">'
                                   + '<div class="dd-handle">'
                                     + '<div class="checkbox-custom checkbox-inline">'
                                       + '<input type="checkbox" id="' + data.data[i].list[k].id + '" name="' + data.data[i].list[k].id + '" value="' + data.data[i].list[k].id + '"> '
                                       + '<label for="' + data.data[i].list[k].id + '">' + data.data[i].list[k].name + '</label>'
                                     + '</div>'
                                   + '</div>'
                               + '</li>'
                           + '</ol>'
                       };
                       list += ''
                         + '<div class="col-sm-4 col-md-2">'
                             + '<ol class="dd-list">'
                                 + '<li class="dd-item">'
                                     + '<div class="dd-handle">'
                                       + '<div class="checkbox-custom checkbox-inline">'
                                         + '<input type="checkbox" id="' + data.data[i].id + '" name="' + data.data[i].id + '" value="' + data.data[i].id + '"> '
                                         + '<label for="' + data.data[i].id + '">' + data.data[i].name + '</label>'
                                       + '</div>'
                                     + '</div>'
                                     + list2
                                 + '</li>'
                               + '</ol>'
                             + '</div>'
                   };
                   $('#jurisdiction').html(list);
               })
           }

           $('#submit').on("click", function () {
               var that = $(this);
               var json = {}
               var username = $('#username').val();
               var password = $('#password').val();
               var hpassword = $('#hpassword').val();
               var img = $('#img').val();
               var selected = [];
               $('#tab12 input:checked').each(function (index, el) {
                   var val = $(this).val();
                   selected.push(val);
               });
               json.username = username;
               json.password = password;
                json.hpassword = hpassword;
               json.img = img;
               json.selected = selected;
               that.prop('disabled', true);
               var waiting = parent.layer.load(0, { shade: false });
               send_json("../../api/admin.ashx?action=" + $.getUrlParam('action') + "&id=" + $.getUrlParam('id'), json, function () {
                   window.location.href = document.referrer
               });
           });
           $('#jurisdiction').on('change', 'input[type="checkbox"]', function () {

               if ($(this).is(':checked')) {
                   $(this).parent().parent().parent().parent().parent().find('.dd-handle:eq(0) input[type="checkbox"]').attr('checked', true);
                   $(this).parent().parent().parent().find('input[type="checkbox"]').attr('checked', true);
               } else {
                   $(this).parent().parent().parent().find('input[type="checkbox"]').attr('checked', false);
               }
           })
       });
    </script>

</body>
</html>