Skip to content

Commit

Permalink
Item12952: first run after checking code
Browse files Browse the repository at this point in the history
... with jslint
  • Loading branch information
MichaelDaum committed Sep 1, 2014
1 parent dd928ea commit b499993
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 73 deletions.
7 changes: 7 additions & 0 deletions pub/System/ConfigurePlugin/Makefile
@@ -0,0 +1,7 @@
FOSWIKI_ROOT?=~/foswiki/core
TARGET= configure.js resig.js types.js

-include $(FOSWIKI_ROOT)/pub/System/JQueryPlugin/Makefile.include

clean:
rm $(TARGET) *.gz
167 changes: 94 additions & 73 deletions pub/System/ConfigurePlugin/types.uncompressed.js
@@ -1,8 +1,11 @@
/*global Class _id_ify */
// Handling for data value types in configure

var Types = {};

(function($) {
"use strict";

Types.BaseType = Class.extend({
// Set to a function that returns true if the current value
// is to be null
Expand All @@ -13,37 +16,39 @@ var Types = {};
},

createUI: function(change_handler) {
var val = this.spec.current_value;
if (val == undefined)
val = '';//eval(this.spec.default);
var val = this.spec.current_value, m, cols, rows, value, size;

if (typeof(val) === "undefined") {
val = '';//eval(this.spec['default']);
}

var m;
// columns x rows
if (this.spec.SIZE
&& (m = this.spec.SIZE.match(/^\s*(\d+)x(\d+)(\s|$)/))) {
var cols = m[1];
var rows = m[2];
var value = val == undefined ? '' : val;
this.$ui = $('<textarea id="' + _id_ify(this.spec.keys)
+ '" rows="' + rows
+ '" cols="' + cols
+ '" class="foswikiTextArea">' + value + '</textarea>');
if (this.spec.SIZE &&
(m = this.spec.SIZE.match(/^\s*(\d+)x(\d+)(\s|$)/))) {
cols = m[1];
rows = m[2];
value = typeof(val) === "undefined" ? '' : val;
this.$ui = $('<textarea id="' + _id_ify(this.spec.keys) +
'" rows="' + rows +
'" cols="' + cols +
'" class="foswikiTextArea">' + value + '</textarea>');
} else {
// simple size
var size = 80;
if (this.spec.SIZE
&& (m = this.spec.SIZE.match(/^\s*(\d+)(\s|$)/))) {
size = 80;
if (this.spec.SIZE &&
(m = this.spec.SIZE.match(/^\s*(\d+)(\s|$)/))) {
size = m[1];
}
this.$ui = $('<input id="' + _id_ify(this.spec.keys)
+ '" size="' + size + '"/>');
this.$ui = $('<input id="' + _id_ify(this.spec.keys) +
'" size="' + size + '"/>');
this.$ui.val(val);
}
if (this.spec.SPELLCHECK) {
this.$ui.attr('spellcheck', 'true');
}
if (change_handler != undefined)
if (typeof(change_handler) !== "undefined") {
this.$ui.change(change_handler);
}
return this.$ui;
},

Expand All @@ -52,8 +57,9 @@ var Types = {};
},

currentValue: function() {
if (this.null_if != null && this.null_if())
if (this.null_if !== null && this.null_if()) {
return null;
}
return this.$ui.val();
},

Expand All @@ -66,34 +72,36 @@ var Types = {};
},

restoreDefaultValue: function() {
this.useVal(this.spec.default);
this.useVal(this.spec['default']);
},

isModified: function() {
var cv = this.spec.current_value;
if (typeof(cv) == 'undefined')
if (typeof(cv) === 'undefined') {
cv = null;
}
return this.currentValue() != cv;
},

isDefault: function() {
// Implementation appropriate for number and string types
// which can be compared as their base type in JS. More
// complex types may need conversion to string first.
return this.currentValue() == this.spec.default;
return this.currentValue() == this.spec['default'];
}

});

Types.BOOLEAN = Types.BaseType.extend({
createUI: function(change_handler) {
this.$ui = $('<input type="checkbox" id="' + _id_ify(this.spec.keys)
+ '" />');
if (change_handler != undefined)
this.$ui = $('<input type="checkbox" id="' + _id_ify(this.spec.keys) + '" />');
if (typeof(change_handler) !== "undefined") {
this.$ui.change(change_handler);
if (typeof(this.spec.current_value) == 'undefined')
}
if (typeof(this.spec.current_value) === 'undefined') {
this.spec.current_value = 0;
if (this.spec.current_value != 0) {
}
if (this.spec.current_value !== 0) {
this.$ui.attr('checked', 'checked');
}
if (this.spec.extraClass) {
Expand All @@ -107,14 +115,14 @@ var Types = {};
},

isModified: function() {
var a = this.currentValue();
var b = this.spec.current_value;
var a = this.currentValue(),
b = this.spec.current_value;
return a != b;
},

isDefault: function() {
var a = this.currentValue();
var b = eval(this.spec.default);
var a = this.currentValue(),
b = eval(this.spec['default']);
return a == b;
},

Expand All @@ -125,18 +133,21 @@ var Types = {};

Types.BOOLGROUP = Types.BaseType.extend({
createUI: function(change_handler) {
var options = this.spec.select_from;
var sets = [];
var values = this.spec.current_value.split(/,\s*/);
for (var i = 0; i < values.length; i++) {
var options = this.spec.select_from,
sets = [],
values = this.spec.current_value.split(/,\s*/),
i, cb;

for (i = 0; i < values.length; i++) {
sets[values[i]] = true;
}
this.$ui = $('<div class="checkbox_group"></div>');
for (var i = 0; i < options.length; i++) {
var cb = $('<input type="checkbox" name="' + options[i]
+ ' id="' + _id_ify(this.spec.keys) + '"/>');
if (sets[options[i]])
for (i = 0; i < options.length; i++) {
cb = $('<input type="checkbox" name="' + options[i] +
' id="' + _id_ify(this.spec.keys) + '"/>');
if (sets[options[i]]) {
cb.attr('checked', 'checked');
}
cb.change(change_handler);
this.$ui.append(cb);
}
Expand All @@ -146,22 +157,26 @@ var Types = {};
currentValue: function() {
var newval = [];
$('#' + _id_ify(this.spec.keys)).each(function() {
if (this.attr('checked'))
if (this.attr('checked')) {
newval.push(this.attr('name'));
}
});
return newval.join(',');
},

useVal: function(val) {
var sets = [];
var values = split(/,\s*/, val);
for (var i = 0; i < values.length; i++) {
var sets = [],
values = val.split(/,\s*/),
i;

for (i = 0; i < values.length; i++) {
sets[values[i]] = true;
}
var i = 0;
i = 0;
this.$ui.find('input[type="checkbox"]').each(function() {
if (sets[options[i++]])
if (sets[options[i++]]) {
cb.attr('checked', 'checked');
}
});
}
});
Expand All @@ -178,7 +193,7 @@ var Types = {};
Types.REGEX = Types.BaseType.extend({
isDefault: function() {
// String comparison, no eval
return this.currentValue() == this.spec.default;
return this.currentValue() == this.spec['default'];
}
});

Expand All @@ -192,13 +207,13 @@ var Types = {};

isDefault: function() {
// String comparison, no eval
return this.currentValue() == this.spec.default;
return this.currentValue() == this.spec['default'];
}
});

Types.OCTAL = Types.BaseType.extend({
createUI: function(change_handler) {
if (this.spec.current_value != undefined && typeof this.spec.current_value != 'string') {
if (typeof(this.spec.current_value) !== "undefined" && typeof this.spec.current_value != 'string') {
this.spec.current_value = "" + this.spec.current_value.toString(8);
}
return this._super(change_handler);
Expand Down Expand Up @@ -233,8 +248,7 @@ var Types = {};

Types.BUTTON = Types.BaseType.extend({
createUI: function() {
this.$ui = $('<a href="' + this.spec.uri + '">'
+ this.spec.title + '</a>');
this.$ui = $('<a href="' + this.spec.uri + '">' + this.spec.title + '</a>');
this.$ui.button();
return this.$ui;
},
Expand All @@ -248,11 +262,12 @@ var Types = {};
// Get an array of items that need to be selected given the value
// 'val'
_getSel: function(val, mult) {
var sel = {};
if (val != undefined) {
var sel = {}, a, i;

if (typeof(val) !== "undefined") {
if (mult) {
var a = val.split(',');
for (var i = 0; i < a.length; i++) {
a = val.split(',');
for (i = 0; i < a.length; i++) {
sel[a[i]] = true;
}
} else {
Expand All @@ -263,24 +278,27 @@ var Types = {};
},

createUI: function(change_handler) {
var size = 1;
var m;
if (this.spec.SIZE && (m = this.spec.SIZE.match(/\b(\d+)\b/)))
var size = 1, m, sel, i, opt, options;

if (this.spec.SIZE && (m = this.spec.SIZE.match(/\b(\d+)\b/))) {
size = m[0];
}

this.$ui = $('<select id="' + _id_ify(this.spec.keys) + '" size="' + size
+ '" class="foswikiSelect" />');
if (change_handler != undefined)
this.$ui = $('<select id="' + _id_ify(this.spec.keys) + '" size="' + size +
'" class="foswikiSelect" />');

if (typeof(change_handler) !== "undefined") {
this.$ui.change(change_handler);
}
if (this.spec.MULTIPLE) {
this.$ui.attr('multiple', 'multiple');
}

if (this.spec.select_from != undefined) {
var sel = this._getSel(this.spec.current_value, this.spec.MULTIPLE);
for (var i = 0; i < this.spec.select_from.length; i++) {
var opt = this.spec.select_from[i];
var option = $('<option>' + opt + '</option>');
if (typeof(this.spec.select_from) !== "undefined") {
sel = this._getSel(this.spec.current_value, this.spec.MULTIPLE);
for (i = 0; i < this.spec.select_from.length; i++) {
opt = this.spec.select_from[i];
option = $('<option>' + opt + '</option>');
if (sel[opt]) {
option.attr('selected', 'selected');
}
Expand All @@ -291,16 +309,19 @@ var Types = {};
},

useVal: function(val) {
var sel = this._getSel(val);
var sf = this.spec.select_from;
if (sf != undefined) {
var i = 0;
var sel = this._getSel(val),
sf = this.spec.select_from,
i, opt;

if (typeof(sf) !== "undefined") {
i = 0;
this.$ui.find('option').each(function() {
var opt = sf[i++];
if (sel[opt])
opt = sf[i++];
if (sel[opt]) {
$(this).attr('selected', 'selected');
else
} else {
$(this).removeAttr('selected');
}
});
}
}
Expand Down

0 comments on commit b499993

Please sign in to comment.