Redmine Ticket Preset

Autofill new ticket fields.

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 or Violentmonkey 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           Redmine Ticket Preset
// @description:en Autofill new ticket fields.
// @version        0.2
// @namespace      http://twitter.com/foldrr/
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
// @match          http://*/redmine/projects/*/issues/new
// @description Autofill new ticket fields.
// ==/UserScript==

(function(){
    var config = {
        'project1': {
            'private' : true,
            'tracker' : '開発',
            'assigned': 'Steve',
            'version' : 'v1.0.0',
        },
        'project2': {
            'private' : false,
            'tracker' : '開発',
            'assigned': 'Woz',
            'version' : 'v1.1.0',
        },
    };
    var project_name = (location.href.match(/projects\/([^\/]+)/) || [])[1];
    if(! project_name) return;
    if(! config[project_name]) return;
    
    var setCheck = function(id, key){
        var value = config[project_name][key];
        if(! value) return;
        
        $('input[id="' + id + '"]').prop('checked', !!value);
    };
    
    var setSelect = function(id, key){
        var text = config[project_name][key];
        if(! text) return;
        
        value = $('select[id="' + id + '"] option:contains("' + text + '")').val();
        $('select[id="' + id + '"]').val(value);
    };
    
    setCheck ("issue_is_private"      , "private" );
    setSelect("issue_tracker_id"      , "tracker" );
    setSelect("issue_assigned_to_id"  , "assigned");
    setSelect("issue_fixed_version_id", "version" );
})();