<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="KeywordManagement.aspx.cs" Inherits="LYFZ.WeixinServers.WeiXinAPP.KeywordManagement" %>
<!--#include file="html/head.html" --> 
   <!--#include file="html/leftMenu.html" --> 
 <link rel="stylesheet" href="/WeiXinAPP/lib/font-awesome/css/font-awesome.css">
    
    <div class="content">
        
        
      <ul class="breadcrumb">
            <!--#include file="html/indexBread.html" --> 
            <li class="active">关键字管理</li>
        </ul>

        <div class="container-fluid">
            <div class="row-fluid">
<div  style="width:100%; min-height:700px;"> 
        
<div class="btn-toolbar">
    <!--   <button class="btn btn-primary"><i class="icon-plus"></i> New User</button>-->
    <div style="width:100%;height:24px;">
       <!-- <label style="width:50px;height:100%; padding-top:5px; float:left;">关键字</label>
        <div style="width:200px;height:100%; float:left; margin-right:5px;">
            <input id="Keyword" name="Keyword" type="text" class="span12" />
        </div>
        <button class="btn">查询</button>-->
        <button class="btn" onclick="showAddFunctionModule('add')">添加功能模块</button>
         <button class="btn" onclick="showAddKeyword('add')">添加关键字</button>
           <button class="btn" onclick="RefreshkeywordsCache()">刷新关键字缓存</button>

    </div>
    
  <div class="btn-group">
  </div>
</div>
<div class="well">
    <table class="table">
      <thead>
        <tr>
          <th  style="width:60px; ">#</th>
            <th  style="width:160px;">模块名称</th>
            <th  style="width:160px;">模块代码</th>
          <th>关键字集合</th>
            <th>创建时间</th>
            <th>启用状态</th>
          <th  style="width:62px;">操作</th>
        </tr>
      </thead>
      <tbody>
             <%=this.KeywordListHtmlTb.ToString() %>
      </tbody>
    </table>
</div>

<!--<div class="pagination">
    <ul>
        <li><a href="#">上一页</a></li>
        <li><a href="#">1</a></li>
        <li><a href="#">2</a></li>
        <li><a href="#">3</a></li>
        <li><a href="#">4</a></li>
        <li><a href="#">下一页</a></li>
    </ul>
</div>-->
</div>
<!--#include file="html/DeleteDialog.html" --> 
 <div class="modal hide fade" id="addKeyword" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myKeywordModalLabel">添加关键字</h3>
    </div>
    <div class="modal-body">
        <label>所属模块</label>
        <select name="Viewmodule" id="Viewmodule" class="input-xlarge">
          <%=SelectOptionList.ToString() %>
        </select>
         <label>关键字</label>
        <input  name="txtKeywordValue" id="txtKeywordValue"  type="text" value="" class="input-xlarge">
        <label>启用状态</label>
        <label class="remember-me"><input id="cbxEnabled" name="cbxEnabled"  runat="server" checked="checked"  type="checkbox" />启用</label>
        

    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
        <button class="btn btn-danger" onclick="AddKeyword()">确定</button>
    </div>
</div>

 <div class="modal small hide fade" id="addFunctionModule" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myFunctionModalLabel">添加功能模块</h3>
    </div>
    <div class="modal-body">
         <label>功能模块名称</label>
        <input  name="txtFunctionName" id="txtFunctionName"  type="text" value="" class="input-xlarge">
        <label>功能模块代码</label>
        <input  name="txtFunctionCode" id="txtFunctionCode"  type="text" value="" class="input-xlarge">
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
        <button class="btn btn-danger" onclick="addfunctionmodule()">确定</button>
    </div>
</div>


<!--#include file="html/footer.html" --> 
                    
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var addFunctionModule = "addFunctionModule";
        var addKeyword = "addKeyword";
        var myFunctionModalLabel="myFunctionModalLabel";
        var myKeywordModalLabel = "myKeywordModalLabel";
     $(document).ready(function () {
         var Keyword = GetQueryString("Keyword");
         $(".tr_FunctionList").find("td:lt(6)").click(function () {
             var mytag = $(this).parent("tr").attr("mytag");
             var trClass = "."+mytag;
             if ($(trClass).is(':hidden')) {
                 $(trClass).show();
             } else {
                 $(trClass).hide();
             }
             //alert(mytag);
         });
       
         $('#' + addFunctionModule).on('hidden.bs.modal', function () {
             $('#' + addFunctionModule).find("input").val("");
             $('#' + addFunctionModule).attr("rel","");
         })
         $('#' + addKeyword).on('hidden.bs.modal', function () {
             $('#' + addKeyword).find("input").val("");
             $('#' + addKeyword).attr("rel", "");
         })
     });
     function RefreshkeywordsCache()
     {
         document.location = "KeywordManagement.aspx?type=refresh";
     }
     function showAddKeyword(modatype)
         {
         $("#" + myKeywordModalLabel).attr("modatype", modatype);
         if (modatype == "edit") {
             $("#" + myKeywordModalLabel).text("编缉关键字");
         } else {
             $("#" + myKeywordModalLabel).text("添加关键字");
         }
         $('#'+addKeyword).modal({
             backdrop: "static"
         }, 'show');
     }
     function showAddFunctionModule(modatype) {
         $("#" + myFunctionModalLabel).attr("modatype", modatype);
         if (modatype == "edit") {
             $("#" + myFunctionModalLabel).text("编缉功能模块");
             $("#txtFunctionCode").attr("readonly", true);
         } else {
             $("#" + myFunctionModalLabel).text("添加功能模块");
             $("#txtFunctionCode").attr("readonly", false);
         }
         $('#'+addFunctionModule).modal({
             backdrop: "static"
         }, 'show');
     }
     function AddKeyword() {
         var modatype = $("#" + myKeywordModalLabel).attr("modatype");
         var Viewmodule = $.trim($("#Viewmodule").val());
         var txtKeywordValue = $.trim($("#txtKeywordValue").val());
         var kid = $('#' + addKeyword).attr("rel");
         if (!kid) {
             kid = 0;
         }
         var cbxEnabled = $("#cbxEnabled").attr("checked");
         if (cbxEnabled) {
             cbxEnabled = 1;
         } else {
             cbxEnabled = 0;
         }
         if (!Viewmodule) {
             alert("请选择模块"); return;
         }
         if (!txtFunctionCode) {
             alert("请输入关键字"); return;
         }
         var parameter = "id=" + kid + "&modatype=" + modatype + "&viewmodule=" + Viewmodule + "&keyword=" + txtKeywordValue + "&checked=" + cbxEnabled;
         AjaxGetRequest("addkeyword", parameter, function (data) {

             if (data.indexOf("Request success") != -1) {
                 $('#' + addFunctionModule).modal('hide');
                 location.reload();//刷新当前页面.
             } else {
                 alert(data);
             }

         });
     }

     function addfunctionmodule() {
         var modatype = $("#" + myFunctionModalLabel).attr("modatype");
         var txtFunctionName = $.trim($("#txtFunctionName").val());
         var txtFunctionCode = $.trim($("#txtFunctionCode").val());
         var fid = $('#' + addFunctionModule).attr("rel");
         if (!fid) {
             fid = 0;
         }
         if (!txtFunctionName) {
             alert("请输入模块名称"); return;
         }
         if (!txtFunctionCode) {
             alert("请输入模块代码"); return;
         }
         var parameter = "id=" + fid + "&modatype=" + modatype + "&fname=" + escape(txtFunctionName) + "&fcode=" + txtFunctionCode;
         AjaxGetRequest("addfunctionmodule", parameter, function (data) {

             if (data.indexOf("Request success") != -1) {
                 $('#' + addFunctionModule).modal('hide');
                 location.reload();//刷新当前页面.
             } else {
                 alert(data);
             }

         });
     }

     function updateFunctionmodule(id, fname, fcode) {
         showAddFunctionModule("edit");
         $('#' + addFunctionModule).attr("rel", id);
         $("#txtFunctionName").val(fname);
         $("#txtFunctionCode").val(fcode);
     }
     function updateKeyword(id,vmodule,keyword,isEnabled) {
         showAddKeyword("edit");
         $('#' + addKeyword).attr("rel", id);
         $("#Viewmodule").val(vmodule);
         $("#txtKeywordValue").val(keyword);
         if (isEnabled == 1) {
             $("#cbxEnabled").attr("checked", "checked");
         } else {
             $("#cbxEnabled").removeAttr("checked");
         }  
     }
        //删除
     function myModalDefine(objModal)
     {
         var relValue = objModal.attr("rel");
         var relvalues = relValue.split('@');
         var parameter = "id=" + relvalues[0] + "&delvalue=" + relvalues[1] + "&deltype=" + relvalues[2];
         AjaxGetRequest("delkeyword", parameter, function (data) {
             if (data.indexOf("Request success") != -1) {

                 location.reload();//刷新当前页面.
             } else {
                 alert(data); 
             }

         });

     }

     function setEnabled(value) {
         var relvalues = value.split('@');
         var parameter = "enabled=" + relvalues[0] + "&setvalue=" + relvalues[1] + "&enabledtype=" + relvalues[2];
         AjaxGetRequest("setenabled", parameter, function (data) {
             if (data.indexOf("Request success") != -1) {
                 location.reload();//刷新当前页面.
             } else {
                 alert(data);
             }

         });
     }

     var ajaxUrl = "/WeiXinAPP/WXServiceHandler.aspx";
     function AjaxGetRequest(type,parameter, callback)
     {
         $("#loading").fadeIn();
         $.ajax({
             type: "get",
             url: ajaxUrl + "?type=" + type + "&" + parameter, async: true, success: function (retdata) {
                 $("#loading").fadeOut();
                 callback(retdata);
         }});
     }


   </script>
<!--#include file="html/bottom.html" -->