Commit 5bbb4a22 by Don Mitchell

Make acid_parent use js subclassing

and get it to work.
parent 2921b892
/* Javascript for the Acid XBlock. */
function AcidBlock(runtime, element) {
function AcidBlock(runtime, element, fields) {
this.runtime = runtime;
this.element = element;
if (fields && fields.acid_data_ele) {
this.acid_data_ele = fields.acid_data_ele;
} else {
this.acid_data_ele = $(this.element).children('div[data-error-class]')[0];
}
this.type = $(element).data('block-type')
this.mark('success', '.js-init-run', $(element));
this.resourceTests();
......@@ -10,7 +17,7 @@ function AcidBlock(runtime, element) {
AcidBlock.prototype = {
acidData: function(key) {
return $('.acid-block, .aside-block', this.element).data(key);
return $(this.acid_data_ele).data(key);
},
mark: function(result, selector, subelem, msg) {
......@@ -35,7 +42,7 @@ AcidBlock.prototype = {
scopeTests: function() {
var that = this;
$('.scope-storage-test', this.element).each(function() {
$('.scope-storage-test', this.acid_data_ele).each(function() {
var $this = $(this);
$.ajaxq("acid-queue", {
type: "POST",
......@@ -71,6 +78,7 @@ AcidBlock.prototype = {
}
};
function AcidAsideBlock(runtime, element, block_element, init_args) {
AcidBlock.call(this, runtime, element);
this.block_element = block_element;
......@@ -81,14 +89,13 @@ function AcidAsideBlock(runtime, element, block_element, init_args) {
)
this.runTests();
}
AcidAsideBlock.prototype = Object.create(AcidBlock.prototype)
AcidAsideBlock.prototype = Object.create(AcidBlock.prototype);
AcidAsideBlock.prototype.runTests = function() {
if (this.test_aside) {
if (this.block_element.data('block-type') === 'acid') {
this.mark('success', '.acid-dom', $(this.element));
// AcidBlock.prototype.mark.call(this, 'success', '.acid-dom', $(element));
} else {
AcidBlock.prototype.mark.call(this, 'failure', '.acid-dom', $(this.element));
this.mark('failure', '.acid-dom', $(this.element));
}
}
}
/* Javascript for the Acid XBlock. */
function AcidParentBlock(runtime, element) {
// this looks like but isn't really a subclass of AcidBlock
this.runtime = runtime;
this.element = element;
this.type = $(element).data('block-type');
function acidData(key) {
return $('.acid-parent-block', element).data(key);
}
var acid_frag_dom = $("> div > .acid-block", element);
this.acid_frag = new AcidBlock(runtime, element, {acid_data_ele: acid_frag_dom});
this.childTests();
}
function mark(result, selector, subelem, msg) {
acid_update_status(selector, subelem, element, msg,
acidData(result + '-class'), acidData('error-class'));
}
AcidParentBlock.prototype = {
acidData: function(key) {
return $(this.element).children('div[data-' + key + ']').data(key);
},
function childTests() {
var acidChildCount = runtime.children(element).filter(function(child) {
return child.type == "acid";
mark: function(result, selector, subelem, msg) {
acid_update_status(selector, subelem, this.element, msg,
this.acidData(result + '-class'), this.acidData('error-class'));
},
childTests: function(){
var acidChildCount = this.runtime.children(this.element).filter(function(child) {
return child.type === "acid";
}).length;
if (acidData('acid-child-count') == acidChildCount) {
mark('success', '.child-counts-match');
}
var childValues = JSON.parse($('.acid-child-values', element).html());
this.mark((this.acidData('acid-child-count') == acidChildCount) ? 'success' : 'failure', '.child-counts-match');
var childValues = JSON.parse($('.acid-child-values', this.element).html());
var that = this;
$.each(childValues, function(name, value) {
var child_value = runtime.childMap(element, name).parentValue;
var child_value = that.runtime.childMap(that.element, name).parentValue;
if (child_value !== value) {
mark(
'failure', '.child-values-match', element,
that.mark(
'failure', '.child-values-match', that.element,
'Child ' + name + ' had value ' + child_value + ' but expected ' + value
);
return;
}
});
mark('success', '.child-values-match');
this.mark('success', '.child-values-match');
}
AcidBlock(runtime, element);
childTests();
return {parentValue: acidData('parent-value')};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment