text: ﻿//员工通讯录
  var game_gameTitleList = function () {
  	var tableId = "tableId";
  	var oTable = null;
  	
  	//初始化加载表格数据的表头定义
      var initTableHeaderInfo = function(){
          var aoColumns = [
  			{ "sTitle": "id", "sWidth" : "1%", "mData": "id"},
  			{ "sTitle": "游戏类型","sWidth" : "1%", "mData": "questiontype"},
  			{ "sTitle": "游戏题目", "sWidth" : "8%", "mData": "questiontitle"},
  			{ 
  				"sTitle": "题目选项",
  				"mDataProp" : "",
  				"sDefaultContent" : "",
              	"sWidth" : "5%",
  				"sVisible" : false,
  				"fnCreatedCell" : function(nTd,sData, oData, iRow, iCol) {
  						$(nTd).append(oData.option1 == null ? "" :oData.option1+"<br/>")
  						.append(oData.option2 == null ? "" :oData.option2+"<br/>")
  						.append(oData.option3 == null ? "" :oData.option3+"<br/>")
  						.append(oData.option4 == null ? "" :oData.option4+"<br/>")
  						.append(oData.option5 == null ? "" :oData.option5+"<br/>");
  						
  				}
  			},
  			{ "sTitle": "答案","sWidth" : "5%", "mData": "answer"},
  			{ 
  				"sTitle": "游戏名称",
  				"mDataProp" : "",
  				"sDefaultContent" : "",
              	"sWidth" : "3%",
  				"sVisible" : false,
  				"fnCreatedCell" : function(nTd,sData, oData, iRow, iCol) {
  						$(nTd).append("<label class='label label-primary'>"+oData.gamename+"</label>");
  				}
  			}
          ];
          //渲染特殊的列(操作列)
          var aoColumnDefs =[];
              aoColumns.push({
              	"sTitle": "操作",
              	"mDataProp" : "",
              	"sDefaultContent" : "",
              	"sWidth" : "5%",
              	"sVisible" : false, 
              	"fnCreatedCell": function(nTd,sData, oData, iRow, iCol){
              		if(App.checkUserOperRight("gameQuestionList", "editGameQuestion")){
              			$(nTd).append("<span style='margin: 0 5px 0 5px'><span class='btn btn-xs purple ajaxify'" +
              					" href='addGameQuestionView.html?id="+oData.id+"'><i class='fa fa-edit'></i> 编辑 </span>");
              		}
              		if(App.checkUserOperRight("gameQuestionList", "deleteGameQuestion")){
              			$(nTd).append("<span class='btn default btn-xs black' data-toggle='modal' " +
              					"href='#confirmWin' enable='ok' " + "id='"+ oData.id +"'>" +
                          "<i class='fa fa-trash-o'></i> 删除 </span>");
              		}
              		 
                  }
              });
  
          return {
              aoColumns : aoColumns,
              aoColumnDefs : aoColumnDefs
          };
      };
      
      
      //加载datatable表格数据
      var loadTableData = function(){
          var headerInfo = initTableHeaderInfo();
          oTable = $('#'+tableId).DataTable({
              "sAjaxSource": "queryGameQuestionData.html",
              "sAjaxDataProp": "queryResult",
              "bFilter" : true,
              "bInfo": true,
              "bJQueryUI": true,
              "bLengthChange": true,
              "bPaginate": true,
              "bProcessing": true,
              "bSort": false,
              "bSortClasses": true,
              "bStateSave": false,
              "bAutoWidth":true,
              "bSortCellsTop": true,
              "iTabIndex": 1,
              "sServerMethod": "POST",
              "bServerSide": true,
              "aoColumns": headerInfo.aoColumns,
              "aLengthMenu": [
                  [10, 20, 30, 40, -1],
                  [10, 20, 30, 40, 50]
              ],
              "iDisplayLength": 10,
              "oLanguage": {
              	"sProcessing" : "努力加载中...",
                  "sLengthMenu": "显示 _MENU_ 条记录",
                  "sInfoEmpty" : "搜索结果为0条记录",
                  "sInfoFiltered": "(从 _MAX_ 条记录中过滤出)",
                  "sZeroRecords" : "没有您要搜索的内容", 
                  "sSearch" : "搜索", 
                  "sInfo": "当前显示 _START_ 到 _END_ 总共 _TOTAL_ 条记录",
                  "oPaginate": {
                      "sFirst":"首页",
                      "sPrevious": "上一页",
                      "sNext": "下一页",
                      "sLast":"末页"
                  }
              }
          });
      };
      
      $('#btnSearch').click(function(){
      	oTable.fnDestroy();
      	game_gameQuestionList.loadTableData();
       });
      
      $('#btnReset').click(function(){
  		document.getElementById("mobilePhone").value="";	  	
      });
  
  
      var initToolBar = function(){
      	//触发相关赋值
          $("#confirmWin").on("show.bs.modal", function(e){
              var id = $(e.relatedTarget).attr("id");
              $("#id").val('').val(id);
          });
      	//删除事件
          $("#deleteBut").on("click", function(){
          	var param = {teplId : $("#id").val()};
              $.ajax({
                  type : "post",
                  dataType : "json",
                  url : "deleteGameQuestion.html",
                  data : param,
                  success : function(data) {
                      if(data.code==0){
                          oTable.fnReloadAjax();
                          bootbox.alert("删除成功");
                          $("#confirmWin").modal("hide");
                      }else{
                          bootbox.alert("删除失败");
                      }
                  }
              });
          });
      };
  
      return {
          init: function () {
              loadTableData();
              initToolBar();
          },
          loadTableData: loadTableData
      };
  }();
  
  