1
0
Fork 0
forked from 0x2620/oxjs

updating form elements

This commit is contained in:
rolux 2011-12-30 15:03:01 +05:30
commit 73f1105692
13 changed files with 305 additions and 140 deletions

View file

@ -14,33 +14,46 @@ Ox.Spreadsheet = function(options, self) {
rowTitleType: 'str',
rowTitleWidth: 128,
title: '',
value: []
value: {}
})
.options(options || {})
.addClass('OxSpreadsheet');
self.values = [];
self.options.rows.forEach(function(row, r) {
self.values.push([]);
self.options.columns.forEach(function(column, c) {
self.values[r].push(0);
if (Ox.isEmpty(self.options.value)) {
self.options.value = {
columns: [],
rows: [],
values: []
}
Ox.loop(4, function(i) {
self.options.value.columns.push('');
self.options.value.rows.push('');
self.options.value.values.push([0, 0, 0, 0]);
});
});
self.sums = getSums();
} else if (Ox.isEmpty(self.options.value.values)) {
self.options.value.rows.forEach(function(row, r) {
self.options.value.values.push([]);
self.options.value.columns.forEach(function(column, c) {
self.options.value.values[r].push(0);
});
});
}
Ox.print('Ss ----', self.options)
renderSpreadsheet();
function addColumn(index) {
self.options.columns.splice(index, 0, '');
self.values.forEach(function(columns) {
self.options.value.columns.splice(index, 0, '');
self.options.value.values.forEach(function(columns) {
columns.splice(index, 0, 0);
});
renderSpreadsheet();
}
function addRow(index) {
self.options.rows.splice(index, 0, '');
self.values.splice(index, 0, Ox.repeat([0], self.columns));
self.options.value.rows.splice(index, 0, '');
self.options.value.values.splice(index, 0, Ox.repeat([0], self.columns));
renderSpreadsheet();
}
@ -50,7 +63,7 @@ Ox.Spreadsheet = function(options, self) {
row: Ox.repeat([0], self.rows),
sheet: 0
};
self.values.forEach(function(columns, r) {
self.options.value.values.forEach(function(columns, r) {
columns.forEach(function(value, c) {
sums.column[c] += value;
sums.row[r] += value;
@ -61,23 +74,23 @@ Ox.Spreadsheet = function(options, self) {
}
function removeColumn(index) {
self.options.columns.splice(index, 1);
self.values.forEach(function(columns) {
self.options.value.columns.splice(index, 1);
self.options.value.values.forEach(function(columns) {
columns.splice(index, 1);
});
renderSpreadsheet();
}
function removeRow(index) {
self.options.rows.splice(index, 1);
self.values.splice(index, 1);
self.options.value.rows.splice(index, 1);
self.options.value.values.splice(index, 1);
renderSpreadsheet();
}
function renderSpreadsheet() {
self.columns = self.options.columns.length;
self.rows = self.options.rows.length;
self.columns = self.options.value.columns.length;
self.rows = self.options.value.rows.length;
self.sums = getSums();
self.$input = {};
@ -88,9 +101,9 @@ Ox.Spreadsheet = function(options, self) {
height: 16 * (self.rows + 2) + 'px'
});
Ox.merge([self.options.title], Ox.clone(self.options.rows), ['Total']).forEach(function(row, r) {
Ox.merge([self.options.title], Ox.clone(self.options.value.rows), ['Total']).forEach(function(row, r) {
r--;
Ox.merge([''], Ox.clone(self.options.columns), ['Total']).forEach(function(column, c) {
Ox.merge([''], Ox.clone(self.options.value.columns), ['Total']).forEach(function(column, c) {
c--;
if (r == -1) {
if (c == -1 || c == self.columns) {
@ -131,7 +144,7 @@ Ox.Spreadsheet = function(options, self) {
})
.bindEvent({
change: function(data) {
self.options.columns[c] = data.value;
self.options.value.columns[c] = data.value;
triggerChangeEvent();
}
})
@ -169,7 +182,7 @@ Ox.Spreadsheet = function(options, self) {
})
.bindEvent({
change: function(data) {
self.options.rows[r] = data.value;
self.options.value.rows[r] = data.value;
triggerChangeEvent();
}
})
@ -197,13 +210,13 @@ Ox.Spreadsheet = function(options, self) {
value: isSheetSum ? self.sums.sheet
: isColumnSum ? self.sums.column[c]
: isRowSum ? self.sums.row[r]
: self.values[r][c],
: self.options.value.values[r][c],
width: self.options.columnWidth
})
.appendTo(that);
!isSum && self.$input[id].bindEvent({
change: function(data) {
self.values[r][c] = parseInt(data.value);
self.options.value.values[r][c] = parseInt(data.value);
self.sums = getSums();
self.$input[c + ',' + self.rows].value(self.sums.column[c]);
self.$input[self.columns + ',' + r].value(self.sums.row[r]);
@ -220,18 +233,10 @@ Ox.Spreadsheet = function(options, self) {
function triggerChangeEvent() {
that.triggerEvent('change', {
value: that.value()
value: self.options.value
});
}
that.value = function() {
return {
columns: self.options.columns,
rows: self.options.rows,
values: self.values
};
};
return that;
};