Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
pollen8 committed Apr 23, 2013
2 parents 6a78cad + bcff072 commit b9ba6b9
Show file tree
Hide file tree
Showing 51 changed files with 391 additions and 868 deletions.
Expand Up @@ -58,7 +58,6 @@ COM_FABRIK_BEGINNING="Beginning"
COM_FABRIK_BOTH="Both"
COM_FABRIK_BUTTONS="Buttons"
COM_FABRIK_BUTTON_TEXT="Button text"
COM_FABRIK_CHECKBOX="Checkbox"
COM_FABRIK_CODE="Code"
COM_FABRIK_COLUMNS_DESC="The number of columns you want to display your elements within"
COM_FABRIK_COLUMNS_LABEL="Columns"
Expand Down Expand Up @@ -831,7 +830,6 @@ COM_FABRIK_MEDIA_BOX_LABEL="Use mediabox instead of slimbox"
COM_FABRIK_MERGE_ROWS="Merge rows"
COM_FABRIK_MOBILE_LAYOUT="Mobile layout"
COM_FABRIK_MSG_BATCH_DONE="Batch process complete"
COM_FABRIK_MULTISELECT="Multi-select list"
COM_FABRIK_NAME="Name"
COM_FABRIK_NAVIGATION="Navigation"
COM_FABRIK_NEW="New"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

191 changes: 71 additions & 120 deletions administrator/components/com_fabrik/models/fields/fabrikmodalrepeat.js
Expand Up @@ -6,9 +6,6 @@ var FabrikModalRepeat = new Class({
this.content = false;
this.setup = false;
this.elid = el;
this.win = {};
this.el = {};
this.field = {};

// If the parent field is inserted via js then we delay the loading untill the html is present
if (!this.ready()) {
Expand All @@ -35,137 +32,91 @@ var FabrikModalRepeat = new Class({

setUp: function () {
this.button = document.id(this.elid + '_button');
if (this.mask) {
this.mask.destroy();
}
this.mask = new Mask(document.body, {style: {'background-color': '#000', 'opacity': 0.4, 'z-index': 9998}});
document.addEvent('click:relay(*[data-modal=' + this.elid + '])', function (e, target) {
var tbl;
// Correct when in repeating group
var id = target.getNext('input').id;
this.field[id] = target.getNext('input');
var c = target.getParent('li');
this.origContainer = c;
tbl = c.getElement('table');
if (typeOf(tbl) !== 'null') {
this.el[id] = tbl;
this.el = document.id(this.elid).getElement('table');
this.el.id = this.elid + '-table';
this.field = document.id(this.field);
this.button.addEvent('click', function (e) {
if (!this.win) {
this.win = new Element('div', {'styles': {'padding': '5px', 'background-color': '#fff', 'display': 'none', 'z-index': 9999}}).inject(document.body);
this.win.adopt(this.el);
var close = new Element('button.btn.button').set('text', 'close');
close.addEvent('click', function (e) {
e.stop();
this.store();
this.close();
}.bind(this));
var controls = new Element('div.controls', {'styles': {'text-align': 'right'}}).adopt(close);
this.win.adopt(controls);
this.win.position();
this.mask = new Mask(document.body, {style: {'background-color': '#000', 'opacity': 0.4, 'z-index': 9998}});
this.content = this.el;
this.build();
this.watchButtons();
}
this.openWindow(id);
}.bind(this));
},

openWindow: function (target) {

var makeWin = false;
if (!this.win[target]) {
makeWin = true;
this.makeTarget(target);
}
this.el[target].inject(this.win[target], 'top');
this.el[target].show();

if (!this.win[target] || makeWin) {
this.makeWin(target);
}
// Testing moviing out of makeWin


//this.build(target);

this.win[target].show();
this.win[target].position();
this.resizeWin(true, target);
this.win[target].position();
this.mask.show();
},

makeTarget: function (target) {
this.win[target] = new Element('div', {'data-modal-content': target, 'styles': {'padding': '5px', 'background-color': '#fff', 'display': 'none', 'z-index': 9999}}).inject(document.body);
},

makeWin: function (target) {

// Testing adopting in.out on show/hide
//this.win[target].adopt(this.el[target]);
var close = new Element('button.btn.button').set('text', 'close');
close.addEvent('click', function (e) {
e.stop();
this.store(target);
this.el[target].hide();
this.el[target].inject(this.origContainer);
this.close();
this.win.show();
this.win.position();
this.resizeWin(true);
this.win.position();
this.mask.show();
}.bind(this));
var controls = new Element('div.controls', {'styles': {'text-align': 'right'}}).adopt(close);
this.win[target].adopt(controls);
this.win[target].position();
this.content = this.el[target];
this.build(target);
this.watchButtons(this.win[target], target);
},

resizeWin: function (setup, target) {
console.log(target);

Object.each(this.win, function (win, key) {
var size = this.el[key].getDimensions(true);
var wsize = win.getDimensions(true);
var y = setup ? wsize.y : size.y + 30;
win.setStyles({'width': size.x + 'px', 'height': (y) + 'px'});
}.bind(this));

resizeWin: function (setup) {
var size = this.el.getDimensions(true);
var wsize = this.win.getDimensions(true);
var y = setup ? wsize.y : size.y + 30;
this.win.setStyles({'width': size.x + 'px', 'height': (y) + 'px'});
},

close: function () {
Object.each(this.win, function (win, key) {
win.hide();
});
this.win.hide();
this.mask.hide();
},

_getRadioValues: function (target) {
_getRadioValues: function () {
var radiovals = [];
this.getTrs(target).each(function (tr) {
this.getTrs().each(function (tr) {
var v = (sel = tr.getElement('input[type=radio]:checked')) ? sel.get('value') : v = '';
radiovals.push(v);
});
return radiovals;
},

_setRadioValues: function (radiovals, target) {
_setRadioValues: function (radiovals) {
// Reapply radio button selections
this.getTrs(target).each(function (tr, i) {
this.getTrs().each(function (tr, i) {
if (r = tr.getElement('input[type=radio][value=' + radiovals[i] + ']')) {
r.checked = 'checked';
}
});
},

watchButtons: function (win, target) {
win.addEvent('click:relay(a.add)', function (e) {
watchButtons: function () {
if (this.buttonsWatched) {
return;
}
this.buttonsWatched = true;
this.content.addEvent('click:relay(a.add)', function (e) {
if (tr = this.findTr(e)) {

// Store radio button selections
var radiovals = this._getRadioValues(target);
var radiovals = this._getRadioValues();

var body = tr.getParent('table').getElement('tbody');
this.tmpl.clone(true, true).inject(body);

/*if (tr.getChildren('th').length !== 0) {
var body = tr.getParent('table').getElement('tbody');
this.tmpl.clone(true, true).inject(body);
if (tr.getChildren('th').length !== 0) {
this.tmpl.clone().inject(tr, 'after');
} else {
tr.clone(true, true).inject(tr, 'after');
}*/
this.stripe(target);
tr.clone().inject(tr, 'after');
}
this.stripe();

// Reapply values as renaming radio buttons
this._setRadioValues(radiovals, target);
this.resizeWin(false, target);
this._setRadioValues(radiovals);
this.resizeWin();
}
win.position();
this.win.position();
e.stop();
}.bind(this));
win.addEvent('click:relay(a.remove)', function (e) {
this.content.addEvent('click:relay(a.remove)', function (e) {

// If only one row -don't remove
var rows = this.content.getElements('tbody tr');
Expand All @@ -176,18 +127,18 @@ var FabrikModalRepeat = new Class({
if (tr = this.findTr(e)) {
tr.dispose();
}
this.resizeWin(false, target);
win.position();
this.resizeWin();
this.win.position();
e.stop();
}.bind(this));
},

getTrs: function (target) {
return this.win[target].getElement('tbody').getElements('tr');
getTrs: function () {
return this.content.getElement('tbody').getElements('tr');
},

stripe: function (target) {
trs = this.getTrs(target);
stripe: function () {
trs = this.getTrs();
for (var i = 0; i < trs.length; i ++) {
trs[i].removeClass('row1').removeClass('row0');
trs[i].addClass('row' + i % 2);
Expand All @@ -199,26 +150,26 @@ var FabrikModalRepeat = new Class({
}
},

build: function (target) {
if (!this.win[target]) {
this.makeWin(target);
build: function () {
if (this.setup) {
return;
}

var a = JSON.decode(this.field[target].get('value'));
var a = JSON.decode(this.field.get('value'));
if (typeOf(a) === 'null') {
a = {};
}
var tr = this.win[target].getElement('tbody').getElement('tr');
var tr = this.content.getElement('tbody').getElement('tr');
var keys = Object.keys(a);
var newrow = keys.length === 0 || a[keys[0]].length === 0 ? true : false;
//var rowcount = keys.length === 0 ? 1 : a[keys[0]].length;
var rowcount = newrow ? 1 : a[keys[0]].length;

// Build the rows from the json object
for (var i = 1; i < rowcount; i ++) {
tr.clone().inject(tr, 'after');
}
this.stripe(target);
var trs = this.getTrs(target);
this.stripe();
var trs = this.getTrs();

// Populate the cloned fields with the json values
for (i = 0; i < rowcount; i++) {
Expand All @@ -235,7 +186,9 @@ var FabrikModalRepeat = new Class({
});
});
}
this.tmpl = tr;
if (newrow || typeOf(this.tmpl) === 'null') {
this.tmpl = tr;
}
if (newrow) {
tr.dispose();
}
Expand All @@ -248,15 +201,13 @@ var FabrikModalRepeat = new Class({
return (tr.length === 0) ? false : tr[0];
},

store: function (target) {
var c = this.content;
c = this.el[target];
store: function () {

// Get the current values
var json = {};
for (var i = 0; i < this.names.length; i++) {
var n = this.names[i];
var fields = c.getElements('*[name*=' + n + ']');
var fields = this.content.getElements('*[name*=' + n + ']');
json[n] = [];
fields.each(function (field) {
if (field.get('type') === 'radio') {
Expand All @@ -269,7 +220,7 @@ var FabrikModalRepeat = new Class({
}.bind(this));
}
// Store them in the parent field.
this.field[target].value = JSON.encode(json);
this.field.value = JSON.encode(json);
return true;
}

Expand Down

0 comments on commit b9ba6b9

Please sign in to comment.