Redmine Ticket Preset

Autofill new ticket fields.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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" );
})();