מדיה ויקי:Gadget-TemplateParamWizard.js: הבדלים בין גרסאות בדף
סימון שגיאות פרמטריות |
מ 148 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-TemplateParamWizard.js יובאו |
||
| (18 גרסאות ביניים של 3 משתמשים אינן מוצגות) | |||
| שורה 82: | שורה 82: | ||
var tp = templateParams[name] = | var tp = templateParams[name] = | ||
templateParams[name] || | templateParams[name] || | ||
~allAliases.indexOf(name) && { options: {isAlias: 1} } || | ~allAliases.indexOf(name) && { param:{}, options: {isAlias: 1} } || | ||
{options: {notInParamPage: 1}}; | {param: {}, options: { notInParamPage: 1}}; | ||
addParam(name); | addParam(name); | ||
$.extend( tp.options, { defval: val } ); | $.extend( tp.options, { defval: val } ); | ||
| שורה 100: | שורה 100: | ||
while (m = paramExtractor.exec(data)) { | while (m = paramExtractor.exec(data)) { | ||
var paramName = $.trim(m[1]); | var paramName = $.trim(m[1]); | ||
templateParams[paramName] = {desc: '', options: {multiline: 5}, label: paramName}; | templateParams[paramName] = { desc: '', options: {multiline: 5}, label: paramName, param:{} }; | ||
addParam(paramName); | addParam(paramName); | ||
} | } | ||
| שורה 109: | שורה 109: | ||
paramOrder = data.paramOrder; | paramOrder = data.paramOrder; | ||
function optionsOfParam(param) { | |||
var options = {}; | |||
if (param.required) options.required = true; | |||
if (param.suggestedvalues && param.suggestedvalues.length) options.choices = param.suggestedvalues.join(','); | |||
return options; | |||
} | |||
function onemore(name) { | function onemore(name) { | ||
var param = params[name]; | var param = params[name]; | ||
if (param.deprecated) | |||
return; // ignore deprecated parameters - pretend they are not in TD. | |||
templateParams[name] = { | templateParams[name] = { | ||
desc: param.description || '', | desc: param.description || '', | ||
options: | options: optionsOfParam(param), | ||
label: param.label || name, | label: param.label || name, | ||
param: param | param: param | ||
| שורה 223: | שורה 231: | ||
paramValueDelim = $('#' + oneLineTemplate).prop('checked') ? '=' : ' = ', | paramValueDelim = $('#' + oneLineTemplate).prop('checked') ? '=' : ' = ', | ||
createEmpties = $('#createEmpties').prop('checked'), | createEmpties = $('#createEmpties').prop('checked'), | ||
mustNumberNameless = dialogFields | mustNumberNameless, | ||
. | valuedOrdered; | ||
for (var i = dialogFields.length - 1; i >= 0; i--) { | |||
var field = dialogFields[i], | |||
val = $.trim(field[1].val()); | |||
if (isNaN(field[0])) continue; // look only at order-based fields | |||
mustNumberNameless |= | |||
/=/.test(val) // order-based value containing "=" | |||
|| valuedOrdered && !val; // empty ordered w lower index than a non-empty one. | |||
if (val) valuedOrdered = true; | |||
} | |||
for (var i in dialogFields) { | for (var i in dialogFields) { | ||
var | var | ||
| שורה 346: | שורה 365: | ||
case 'pve-incompatible': return 'שדה זה מצפה לערך מספרי'; | case 'pve-incompatible': return 'שדה זה מצפה לערך מספרי'; | ||
case 'pve-no-such-name': return 'שדה זה לא קיים בתבנית'; | case 'pve-no-such-name': return 'שדה זה לא קיים בתבנית'; | ||
case 'explain-pve': return 'שדות עם שגיאה מסומנים ברקע ורוד'; | |||
case 'pve-approve-close': return 'יש בתבנית שגיאות. אנא אשרו יציאה מהאשף'; | case 'pve-approve-close': return 'יש בתבנית שגיאות. אנא אשרו יציאה מהאשף'; | ||
} | } | ||
| שורה 378: | שורה 398: | ||
} | } | ||
break; | break; | ||
case 'ru': | |||
switch (key) { | |||
case 'explain': return 'поля с красной рамкой обязательны, остальные - по желанию'; | |||
case 'wizard dialog title': return 'Настройте параметры для шаблона: ' + template; | |||
case 'ok': return 'OK'; | |||
case 'cancel': return 'Отмена'; | |||
case 'params subpage': return 'Параметры'; | |||
case 'preview': return 'Просмотр'; | |||
case 'options select': return 'Выбрать:'; | |||
case 'multiline': return 'Многострочный вид'; | |||
case 'close': return 'Закрыть'; | |||
case 'required': return 'Необходимое'; | |||
case 'depends': return 'Зависит от'; | |||
case 'defval': return 'По умолчанию'; | |||
case 'choices': return 'Выбор'; | |||
case 'date': return 'Дата'; | |||
case 'extended': return 'Расширенный'; | |||
case 'button hint': return 'Мастер параметров шаблона'; | |||
case 'able templates category name': throw('Необходимо определить название категории для шаблонов с поддержкой мастера'); | |||
case 'template selector title': return 'Пожалуйста, введите имя шаблона'; | |||
case 'notInParamPage': return 'поле "' + param + '" не отображается в списке параметров шаблона'; | |||
case 'editParamPage': return 'Править страницу параметров'; | |||
case 'unknown error': return 'Произошла ошибка: \n' + param; | |||
case 'please select template': return 'Пожалуйста, введите имя шаблона'; | |||
case 'oneliner': return 'Однострочный вид'; | |||
case 'dateFormat': return 'ММ дд, гг'; | |||
case 'extended labels': return 'Показать все параметры'; | |||
} | |||
default: | default: | ||
switch (key) { | switch (key) { | ||
| שורה 409: | שורה 457: | ||
case 'pve-incompatible': return 'expaects numteric value'; | case 'pve-incompatible': return 'expaects numteric value'; | ||
case 'pve-no-such-name': return 'undercgonzed parameter'; | case 'pve-no-such-name': return 'undercgonzed parameter'; | ||
case 'explain-pve': return 'fields with errors are marked with pink background'; | |||
case 'pve-approve-close': return 'Template contains errors. Please confim exit'; | case 'pve-approve-close': return 'Template contains errors. Please confim exit'; | ||
} | } | ||
| שורה 418: | שורה 467: | ||
var explanation; | var explanation; | ||
if (rawTemplate) return 'לתבנית "' + template + '" אין דף פרמטרים, ולכן לשדות אין תיאור.'; | if (rawTemplate) return 'לתבנית "' + template + '" אין דף פרמטרים, ולכן לשדות אין תיאור.'; | ||
if (anyRequiredParam()) return ' | if (anyRequiredParam()) return 'שדות חובה מסומנים במסגרת אדומה'; | ||
return ''; | return ''; | ||
} | } | ||
| שורה 430: | שורה 479: | ||
} | } | ||
function templatePage() {return mw.config.get('wgFormattedNamespaces')[10] + ':' + | function templatePage() { | ||
var t = $.trim(template) | |||
return t.match(':') ? t : mw.config.get('wgFormattedNamespaces')[10] + ':' + t; | |||
} | |||
function updateRawPreview(){ | function updateRawPreview(){ | ||
| שורה 462: | שורה 514: | ||
return false; | return false; | ||
} | } | ||
if (param.options.notInParamPage) return markError('pve-no-such-name'); | var hasVal = !! input.val(); | ||
if (param.param.required && ! | if (param.options.notInParamPage && hasVal) return markError('pve-no-such-name'); | ||
if (param.param.deprecated && | if (param.param.required && ! hasVal) return markError('pve-required-empty'); | ||
if (param.param.type === 'number' && isNaN( Number( input.val() ) ) ) return markError('pve-incompatible'); | if (param.param.deprecated && hasVal) return markError('pve-deprecated'); | ||
if (param.param.type === 'number' && isNaN( Number( input.val().replace(/,/g, '') ) ) ) return markError('pve-incompatible'); | |||
return true; | |||
} | } | ||
| שורה 479: | שורה 533: | ||
aOK = validateField(param, input) && aOK; | aOK = validateField(param, input) && aOK; | ||
} | } | ||
$('#tpw-explain').html(i18n(aOK ? 'explain' : 'explain-pve') ); | |||
return aOK; | return aOK; | ||
} | } | ||
| שורה 491: | שורה 548: | ||
var choices = options.choices.split(/\s*,\s*/); | var choices = options.choices.split(/\s*,\s*/); | ||
if (choices.length > 1) { | if (choices.length > 1) { | ||
f = $('<select>').append($('<option>', {text: i18n('options select'), value: ''})); | f = $('<select>').append($('<option>', {text: i18n('options select'), value: '' })); | ||
for (var i in choices) | for (var i in choices) { | ||
var choice = choices[i].trim(); // first and last may carry spaces | |||
var option = $('<option>', {text: choice, value: choice}); | |||
f.append(option); | |||
} | |||
} | } | ||
else { | else { | ||
checkbox = true; | checkbox = true; | ||
f = $('<input>', {type: 'checkbox', value: choices[0], text: choices[0]}) | var choice = choices[0].trim(); | ||
f = $('<input>', {type: 'checkbox', value: choices[0], text: choices[0].trim()}) | |||
.css({float: rtl ? 'right' : 'left'}); | .css({float: rtl ? 'right' : 'left'}); | ||
f.prop('checked', options.defval && options.defval == choices[0]); | f.prop('checked', options.defval && options.defval.trim() == choices[0]); | ||
} | } | ||
} | } | ||
| שורה 518: | שורה 579: | ||
.on('paste cut drop input change', updateRawPreview); | .on('paste cut drop input change', updateRawPreview); | ||
if (options.defval) | if (options.defval && ! checkbox) | ||
f.val(options.defval); | f.val(options.defval.trim()); | ||
if (options.required) | if (options.required) | ||
f.addClass(' | f.addClass('tpw-required'); | ||
if (options.date) | if (options.date) | ||
| שורה 549: | שורה 610: | ||
function tipsyContent() { | function tipsyContent() { | ||
var | var | ||
paramName = $(this). | paramName = $(this).data('paramname'), | ||
def = templateParams[paramName], | def = templateParams[paramName], | ||
desc = def && def.desc || ''; | desc = def && def.desc || ''; | ||
| שורה 587: | שורה 648: | ||
$('<td>', {width: 120}) | $('<td>', {width: 120}) | ||
.css({fontWeight: 'bold', color: nameColor}) | .css({fontWeight: 'bold', color: nameColor}) | ||
.data({ paramname: paramName }) | |||
.text(templateParams[paramName].label || paramName) | .text(templateParams[paramName].label || paramName) | ||
.tipsy({html: true, trigger: 'manual', title: tipsyContent}) | .tipsy({html: true, trigger: 'manual', title: tipsyContent}) | ||
| שורה 622: | שורה 684: | ||
function buildDialog(data) { | function buildDialog(data) { | ||
var title = $('<span>').html(i18n('wizard dialog title', template)); | |||
$('.tpw_disposable').remove(); | $('.tpw_disposable').remove(); | ||
if (rawTemplate) | if (rawTemplate) | ||
buildParamsRaw(data); | buildParamsRaw(data); | ||
else if (tdTemplate) | else if (tdTemplate) { | ||
buildParamsTd(data); | buildParamsTd(data); | ||
if (data.description) title.find('a').attr({ title: data.description }); | |||
} | |||
paramsFromSelection(); | paramsFromSelection(); | ||
| שורה 632: | שורה 698: | ||
var dialog = $('<div>', {'class': 'tpw_disposable'}) | var dialog = $('<div>', {'class': 'tpw_disposable'}) | ||
.dialog({height: 'auto', | .dialog({height: 'auto', | ||
title: | title: title.html(), | ||
width: 'auto', | width: 'auto', | ||
overflow: 'auto', | overflow: 'auto', | ||
| שורה 639: | שורה 705: | ||
}) | }) | ||
.append($('<div>', {id: 'tpw_globalExplanation'}).html(globalExplanation)) | .append($('<div>', {id: 'tpw_globalExplanation'}).html(globalExplanation)) | ||
.append($('<p>').html(i18n('explain'))) | .append($('<p>', { id: 'tpw-explain' } ).html(i18n('explain')) ) | ||
.append(anyExtended ? createExtendedCheckBox() : '') | .append(anyExtended ? createExtendedCheckBox() : '') | ||
.append(table) | .append(table) | ||
| שורה 654: | שורה 720: | ||
) | ) | ||
) | ) | ||
.append($('<pre>', {id: 'tpw_preview'}) | .append($('<pre>', {id: 'tpw_preview'}).addClass('tpw-wikicode-preview')); | ||
while (paramsOrder.length) | while (paramsOrder.length) | ||
addRow(paramsOrder.shift(), table); | addRow(paramsOrder.shift(), table); | ||
| שורה 661: | שורה 727: | ||
var buttons = {}; // we need to do it this way, because with literal object, the keys must be literal. | var buttons = {}; // we need to do it this way, because with literal object, the keys must be literal. | ||
buttons[i18n('ok')] = function() { | buttons[i18n('ok')] = function() { | ||
if (! validate() && ! | if (! validate() && ! confirm(i18n('pve-approve-close' ) ) ) return; | ||
injectResults(); | injectResults(); | ||
dialog.dialog('close'); | dialog.dialog('close'); | ||
| שורה 823: | שורה 889: | ||
tools: { | tools: { | ||
'templateParamsWizard': { | 'templateParamsWizard': { | ||
label: | label: i18n('button hint'), | ||
type: 'button', | type: 'button', | ||
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/7/7e/Template_alt_full_black_22.svg/22px-Template_alt_full_black_22.svg.png', | icon: '//upload.wikimedia.org/wikipedia/commons/thumb/7/7e/Template_alt_full_black_22.svg/22px-Template_alt_full_black_22.svg.png', | ||