Commit 0c8ac082 by Don Mitchell

Making acid and aside real js objects

and changing test code for aside to check type of block dom
parent f8faad69
...@@ -285,7 +285,7 @@ class AcidAside(XBlockAside, AcidSharedMixin): ...@@ -285,7 +285,7 @@ class AcidAside(XBlockAside, AcidSharedMixin):
frag.add_javascript(self.resource_string('static/js/acid.js')) frag.add_javascript(self.resource_string('static/js/acid.js'))
frag.add_css(self.resource_string("static/css/acid.css")) frag.add_css(self.resource_string("static/css/acid.css"))
frag.add_css_url('//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css') frag.add_css_url('//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css')
frag.initialize_js('AcidBlock') frag.initialize_js('AcidAsideBlock', {'test_aside': isinstance(block, AcidBlock)})
return frag return frag
......
...@@ -56,4 +56,5 @@ ...@@ -56,4 +56,5 @@
</tr> </tr>
% endfor % endfor
</table> </table>
<p>Sees Acid DOM: <span class="acid-dom"><i class="${unknown_class}"></i></span></p>
</div> </div>
/* Javascript for the Acid XBlock. */ /* Javascript for the Acid XBlock. */
function AcidBlock(runtime, element) { function AcidBlock(runtime, element) {
this.runtime = runtime;
this.element = element;
function acidData(key) { this.mark('success', '.js-init-run', $(element));
return $('.acid-block, .aside-block', element).data(key); this.resourceTests();
} this.scopeTests();
}
function mark(result, selector, subelem, msg) { AcidBlock.prototype = {
acid_update_status(selector, subelem, element, msg, acidData: function(key) {
acidData(result + '-class'), acidData('error-class')); return $('.acid-block, .aside-block', this.element).data(key);
} },
function resourceTests() { mark: function(result, selector, subelem, msg) {
$.get(acidData('local-resource-url')) acid_update_status(selector, subelem, this.element, msg,
this.acidData(result + '-class'), this.acidData('error-class'));
},
resourceTests: function() {
var that = this;
$.get(this.acidData('local-resource-url'))
.fail(function() { .fail(function() {
mark('failure', '.local-resource-test', element, 'Unable to load local resource'); that.mark('failure', '.local-resource-test', that.element, 'Unable to load local resource');
}) })
.done(function(data) { .done(function(data) {
if (data.test_data === 'success') { if (data.test_data === 'success') {
mark('success', '.local-resource-test'); that.mark('success', '.local-resource-test', $(that.element));
} else { } else {
mark('failure', '.local-resource-test', element, 'Data mismatch'); that.mark('failure', '.local-resource-test', that.element, 'Data mismatch');
} }
}); });
} },
function scopeTests() { scopeTests: function() {
$('.scope-storage-test', element).each(function() { var that = this;
$('.scope-storage-test', this.element).each(function() {
var $this = $(this); var $this = $(this);
$.ajaxq("acid-queue", { $.ajaxq("acid-queue", {
type: "POST", type: "POST",
data: {"VALUE": $this.data('value')}, data: {"VALUE": $this.data('value')},
url: $this.data('handler-url'), url: $this.data('handler-url'),
context: that,
success: function (ret) { success: function (ret) {
mark('success', '.server-storage-test-returned', $this); this.mark('success', '.server-storage-test-returned', $this);
if (ret.status === "ok") { if (ret.status === "ok") {
mark('success', '.server-storage-test-succeeded', $this); this.mark('success', '.server-storage-test-succeeded', $this);
$.ajaxq("acid-queue", { $.ajaxq("acid-queue", {
type: "POST", type: "POST",
data: {"VALUE": ret.value}, data: {"VALUE": ret.value},
url: runtime.handlerUrl(element, "check_storage", ret.suffix, ret.query), url: this.runtime.handlerUrl(this.element, "check_storage", ret.suffix, ret.query),
context: this,
success: function (ret) { success: function (ret) {
mark('success', '.client-storage-test-returned', $this); this.mark('success', '.client-storage-test-returned', $this);
if (ret.status === "ok") { if (ret.status === "ok") {
mark('success', '.client-storage-test-succeeded', $this); this.mark('success', '.client-storage-test-succeeded', $this);
} else { } else {
mark('failure', '.client-storage-test-succeeded', $this, ret.message); this.mark('failure', '.client-storage-test-succeeded', $this, ret.message);
} }
} }
}); });
} else { } else {
mark('failure', '.server-storage-test-succeeded', $this, ret.message); this.mark('failure', '.server-storage-test-succeeded', $this, ret.message);
} }
} }
}); });
}); });
} }
};
mark('success', '.js-init-run'); function AcidAsideBlock(runtime, element, block_element, init_args) {
AcidBlock.call(this, runtime, element);
resourceTests(); this.block_element = block_element;
scopeTests(); this.test_aside = init_args['test_aside']
this.runTests();
return {parentValue: acidData('parent-value')}; }
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));
}
}
} }
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