Zentao Utils

7/27/2021, 4:53:18 PM

Ekde 2021/07/29. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Zentao Utils
// @namespace   Violentmonkey Scripts
// @match       http://zentao.inovance.com/pro/*
// @grant       all
// @version     1.2
// @author      sbw <[email protected]>
// @description 7/27/2021, 4:53:18 PM
// ==/UserScript==


(function() {
  
  // 显示 alert 对话框
  function show_alert(message)
  {
    bootAlert(message);
  }
  
  // 显示对话框
  function update_dialog(title, content)
  {
    $('#dialog .modal-title').html(title);
    $('#dialog .modal-body').html(content);
  }
  
  // 获取当前项目中的模块分类
  function update_module_on_dialog()
  {
    var url = "/tree-ajaxGetOptionMenu-149-bug-0-0-html--true.html";
    $.get(url, function(data, status){
      update_dialog('更新模块', data);
      
      // 清除事件
      $('.form-control').off('change');
      $('.form-control').removeAttr('onchange');
    });
  }
  
  // 更新任务所属模块
  function update_jobs_module(e)
  {
    // 禁止默认的响应
    e.preventDefault();
    
    update_module_on_dialog();
    
    // 绑定对话框确定按钮的事件
    $('#dialog .btn-primary').off('click');
    $('#dialog .btn-primary').click(submit_jobs_module);
  }
  
  function submit_jobs_module()
  {
    // 获取选择的数据
    var choose = $('#module').find(":selected").val();
    
    // 隐藏对话框
    $('#dialog').modal('hide');
    
    // 获取选中的任务列表
    $('#bugList tr').filter('.checked').each(function () {
      var id = $(this).find('.c-id input').val();
      var title = $(this).find('.text-left').attr('title');
      if (typeof(title) === "undefined") {
        title = $(this).find('.text-left > a').attr('title');
      }
      
      // 修改任务的地址
      var url = '/pro/bug-edit-' + id + '.html';
      $.get(url, function(data, status) {
        // 从任务修改界面获取初始数据集
        var resData = $.parseHTML(data, true);
        var formData = new FormData($(resData).find('form')[0]);
        // 修改所属模块
        formData.set('module', choose);
        
        // 发送数据
        $.ajax({
          type: 'post',
          url: url, 
          data: formData, 
          contentType: false,
          processData: false,
          success: function(data, status) { 
            /*$('html').html(data);*/
            new $.zui.Messager('任务 ' + id + ' 更新完成', { icon: 'bell' }).show();
          }
        });
      });
    });
  }
  
  // 添加对话框
  $("body").append("<div class='modal fade' id='dialog'><div class='modal-dialog modal-sm'><div class='modal-content'><div class='modal-header'><h4 class='modal-title'></h4></div><div class='modal-body'></div><div class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button><button type='button' class='btn btn-primary'>保存</button></div></div></div></div>");

  // 添加模块修改按钮
  $('.table-actions').append('<button class="btn" id="update-module" data-toggle="modal" data-target="#dialog">所属模块</button>');
  // 更新模块点击的事件
  $('#update-module').click(update_jobs_module);

  // 如果在 bug view 界面,增加快速修改按钮
  var basicInfoPanel = $('#legendBasicInfo');
  if (basicInfoPanel.length > 0)
  {
    var btn = '<button class="btn" id="update-module-x" data-toggle="modal" data-target="#dialog">更新模块</button>';
    $('#legendBasicInfo tr:nth-child(2) td:first').append(btn);
    $('#update-module-x').click(update_jobs_module);
  }
})();