123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- /**
- * 执行语句管理定义引用的js
- */
- var grid_selector = "#grid-table";
- var pager_selector = "#grid-pager";
- jQuery(function($) {
- //初始化日期控件
- initDateTime();
- // 初始化Grid
- initGrid();
- // 初始化下拉列表
- initDdl();
- });
- /**
- * 初始化Grid
- */
- function initGrid() {
- //resize to fit page size
- $(window).on('resize.jqGrid', function() {
- $(grid_selector).jqGrid('setGridWidth', $(".page-content").width()-1);
- });
- //resize on sidebar collapse/expand
- var parent_column = $(grid_selector).closest('[class*="col-"]');
- $(document).on(
- 'settings.ace.jqGrid',
- function(ev, event_name, collapsed) {
- if (event_name === 'sidebar_collapsed'
- || event_name === 'main_container_fixed') {
- //setTimeout is for webkit only to give time for DOM changes and then redraw!!!
- setTimeout(function() {
- $(grid_selector).jqGrid('setGridWidth',
- parent_column.width());
- }, 0);
- }
- });
- // 数据表格初始化
- jQuery(grid_selector).jqGrid({
- url : basePath + '/tasksql/initTaskSql',
- mtype : "POST", //提交方式
- datatype : "json",
- autowidth: false,
- height :"auto",
- shrinkToFit: true,
- sortname : "", //默认的排序列
- sortorder : "", //默认的排序列
- colNames : [ '','id','所在任务', '源连接地址','目标连接地址','查询语句','目标表','同步模式'],
- colModel : [ {
- name:'Edit',
- index:'Edit',
- width:30,
- sortable : false,
- fixed : true
- },{
- name : 'id',
- index : 'id',
- key : true,
- hidden:true,
- editable : false,
- sortable : false
- },{
- name : 'taskCode',
- index : 'taskCode',
- editable : false,
- sortable : true
- },{
- name : 'srcConn',
- index : 'srcConn',
- editable : false,
- sortable : true
- },{
- name : 'targetConn',
- index : 'targetConn',
- editable : false,
- sortable : true
- }, {
- name : 'querySql',
- index : 'querySql',
- editable : false,
- sortable : true
- }, {
- name : 'targetTable',
- index : 'targetTable',
- editable : false,
- sortable : true
- }, {
- name : 'mode',
- index : 'mode',
- editable : false,
- sortable : true
- ,formatter:function(cellvalue, options, rowObject){
- if(cellvalue == 1){
- return '逐条';
- } else if(cellvalue == 2){
- return '全表';
- } else{
- return "";
- }
- }
- } ],
- rowNum : _rowNum, //每页显示记录数
- rowList : _rowList, //用于改变显示行数的下拉列表框的元素数组。
- pager : pager_selector, //定义翻页用的导航栏
- page : 1, //设置初始的页码,初始为1
- pagerpos : 'right', //指定分页栏的位置
- altRows : true, //设置为交替行表格,默认为false
- multiselect : true, //可以多选
- multiboxonly : true, //只有选择checkbox才会起作用
- loadComplete : function() {
- var table = this;
- setTimeout(function() {
- updatePagerIcons(table);
- enableTooltips(table);
- }, 0);
- },
- prmNames : {
- oper : "oper",
- page : "page",
- rows : "rows",
- sort : "sidx",
- order : "sord"
- },
- postData :{
- wldwCode : function(){ return ""; },//问题内容
- wldwName : function(){ return ""; }//服务类型
- },
- jsonReader : {
- root : "list", // json中代表实际模型数据的入口
- page : "page", // json中代表当前页码的数据
- total : "pages", // json中代表页码总数的数据
- records : "total", // json中代表数据行总数的数据
- repeatitems : false// 如果设为false,则jqGrid在解析json时,会根据name来搜索对应的数据元素
- },
- gridComplete: function () {
- comGridComplete("grid-table", "editRecord");
- },
- onPaging: function(){
- comGridPage("grid-table");
- }
- });
- $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size
- // 隐藏水平垂直滚动条
- jQuery(grid_selector).closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'hidden' ,'overflow-y':'hidden'});
- //navButtons
- jQuery(grid_selector).jqGrid(
- 'navGrid',
- pager_selector,
- { //navbar options
- edit : false,
- editicon : 'ace-icon fa fa-pencil blue',
- add : false,
- addicon : 'ace-icon fa fa-plus-circle purple',
- del : false,
- delicon : 'ace-icon fa fa-trash-o red',
- search : false,
- searchicon : 'ace-icon fa fa-search orange',
- refresh : false,
- refreshicon : 'ace-icon fa fa-refresh green',
- view : false,
- viewicon : 'ace-icon fa fa-search-plus grey',
- });
- //初始化操作按钮
- intOperButton();
- $(document).one('ajaxloadstart.page', function(e) {
- $(grid_selector).jqGrid('GridUnload');
- $('.ui-jqdialog').remove();
- });
-
- setMulti();
- };
- /**
- * 初始化下拉列表
- */
- function initDdl() {
- // 初始化所在工作
- $.ajax({
- type : "POST",
- url : basePath + '/task/getTaskForDdl',//请求的路径
- dataType : "json",
- success : function(data) {
- var option1="<option selected value=''>----请选择----</option>";
- $("#taskCode").append(option1);
- if(data) {
- var length=data.length;
- if(length > 0) {
- for(var i=0;i<length;i++){
- $("<option/>").html(data[i].name).val(data[i].code).appendTo("#taskCode");
- }
- }
- }
- }
- });
- // 初始化源和目标下拉
- $.ajax({
- type : "POST",
- url : basePath + '/datasource/getconnForDdl',//请求的路径
- dataType : "json",
- success : function(data) {
- var option1="<option selected value=''>----请选择----</option>";
- $("#srcConn").append(option1);
- $("#targetConn").append(option1);
- if(data) {
- var length=data.length;
- if(length > 0) {
- for(var i=0;i<length;i++){
- $("<option/>").html(data[i].id).val(data[i].id).appendTo("#srcConn");
- $("<option/>").html(data[i].id).val(data[i].id).appendTo("#targetConn");
- }
- }
- }
- }
- });
- }
- /**
- * 初始化操作按钮
- */
- function intOperButton() {
- jQuery(grid_selector).navButtonAdd(pager_selector, {
- caption : "新增",
- buttonicon : "ui-icon ui-icon btn-minier ace-icon fa fa-plus-circle",
- onClickButton : function() {
- comClearFormData("form");
- // 隐藏校验图标
- hideValidateTip();
- $("#id").val("");
- $("#btnSave").show();
- // 启用元素
- comEnableElements("modal-table");
- $("#modal-table #myModalLabel").text("新增执行语句");
- $('#modal-table').modal('show');
- },
- position : "last"
- });
- jQuery(grid_selector).navButtonAdd(pager_selector, {
- caption : "删除",
- buttonicon : "ui-icon ui-icon ace-icon fa fa-trash-o red",
- onClickButton : function() {
- var idsStr = getMultiData();
- if(idsStr.length >=1 ){
- showMsgConfimDialog("确定删除吗?",function(){
- $.ajax({
- async : false,
- type : 'POST',
- dataType : "json",
- data : {"ids":idsStr, opt:'QY'},
- url : basePath + '/tasksql/delTaskSql',//请求的路径
- success : function(data) {
- // 成功后刷新页面
- if (data == "SUCCESS") {
- showMsgDialog("数据已删除!");
- }
- jQuery(grid_selector).trigger("reloadGrid");
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- showMsgDialog("error:" + errorThrown);
- }
- });
- });
- } else {
- showMsgDialog("请至少选择一条记录");
- }
- },
- position : "last"
- });
- }
- /**
- * 初始化日期控件
- */
- function initDateTime() {
- $('#startTime').datetimepicker({
- format : 'yyyy-mm-dd hh:ii:ss',
- minView: 1
- }).next().on(ace.click_event, function(){
- $(this).prev().focus();
- });
-
- $('#endTime').datetimepicker({
- format : 'yyyy-mm-dd hh:ii:ss',
- minView: 1
- }).next().on(ace.click_event, function(){
- $(this).prev().focus();
- });
- };
- /**
- * 编辑
- * @param rid
- */
- function editRecord(rid) {
- var data = jQuery("#grid-table").jqGrid('getRowData', rid);
- $("#btnSave").show();
- // 隐藏校验图标
- hideValidateTip();
- // 启用元素
- comEnableElements("modal-table");
- $("#modal-table #myModalLabel").text("编辑执行语句");
- initBaseInfo(rid);
- }
- /**
- * 获取多行选中的id
- */
- function getMultiData(opt){
- var ids = "";
- //获取选择行的id
- var row = jQuery(grid_selector).jqGrid('getGridParam','selarrrow');
- if (row.length >= 1) {
- for (var i = 0; i < row.length; i++) {
- //获取选择的行的数据,只要传入rowId即可
- var data = jQuery(grid_selector).jqGrid('getRowData', row[i]);
- ids += data.id +",";
- }
- ids = ids.substr(0, ids.length - 1);
- }
- return ids;
- }
- /**
- * 查询事件
- */
- function searchRecord() {
-
- //$.extend(jQuery(grid_selector)[0].p.postData);
- jQuery("#grid-table").trigger("reloadGrid", [{ page: 1 }]);
- };
- /**
- * form提交事件
- */
- function submitForm() {
- $.ajax({
- async:false,
- type : "post",
- url : basePath + '/tasksql/save',
- dataType:'json',
- data : $('#form').serialize()
- , //表单序列化,获取数据
- success : function(data) {
- // 成功删除后刷新页面
- if (data) {
- showMsgDialog("数据已成功保存!");
- closeWin();
- searchRecord();
- } else {
- showMsgDialog("数据保存失败!");
- }
- }, //操作成功后的操作!data是后台传过来的值
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- showMsgDialog("error:" + errorThrown);
- }
- });
- };
- // 关闭弹出窗口,刷新列表
- function closeWin(){
- $('.layui-layer').hide();
- $('#modal-table').modal('hide');
- }
- /**
- * 根据id查询所有信息并赋值
- */
- function initBaseInfo(rowid, flg){
- // 后台获取
- $.ajax({
- async : true,
- type : 'POST',
- dataType : "json",
- data : {id:rowid},
- url : basePath + '/tasksql/initEditTaskSql', //请求的路径
- success : function(data) {
- // 填充信息
- $('#id').val(data.id);
- $('#taskCode').val(data.taskCode);
- $('#srcConn').val(data.srcConn);
- $('#targetConn').val(data.targetConn);
- $('#targetTable').val(data.targetTable);
- $('#querySql').val(data.querySql);
- $('#updateSql').val(data.updateSql);
- $('#insertSql').val(data.insertSql);
- $('#refreshSql').val(data.refreshSql);
- $('#mode').val(data.mode);
- if(flg && flg=="VIEW") {
- comDisableElements("modal-table");
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- showMsgDialog("error:" + errorThrown);
- }
- });
- $('#modal-table').modal('show');
- };
- /**
- * 隐藏校验图标
- */
- function hideValidateTip() {
- }
|