Skip to content
Snippets Groups Projects
Commit 9786fe2c authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #15356 wrap url into methods

parent a7d0eac0
Branches
Tags
2 merge requests!321Dev#12992 custom fields,!313Dev#12992 custom fields
......@@ -50,7 +50,7 @@ class Admin_CustomFieldsReportController extends ZendAfi_Controller_Action {
Class_ScriptLoader::getInstance()
->addAdminScript('/custom-fields/custom_fields')
->addAdminScript('custom-fields/custom_fields')
->addJQueryReady($report->getScript());
$this->_forward('index');
......
......@@ -9,7 +9,7 @@ echo $this->renderForm($this->form, [
]);
Class_ScriptLoader::getInstance()
->addAdminScript('/custom-fields/custom_fields')
->addAdminScript('custom-fields/custom_fields')
->loadCodeMirror()
->addJQueryReady("
var cm;
......
......@@ -19,24 +19,46 @@
*/
(function ( $ ) {
$.fn.report_helper = function() {
var base_url = window.location.hostname;
var current = this;
return {
'current': current,
downloadReport: function(datas) {
var a = $('<a target="_blank" download="report.csv" href="data:attachment/csv,' + encodeURIComponent(datas) + '"></a>');
a.appendTo(this.current);
a.click();
a.appendTo($('body'));
this.download(a);
},
download: function(anchor) {
anchor[0].click();
},
jsonContent: function() {
jsonContent: function(url) {
var ajax= $.ajax({
url: url,
dataType: 'json',
async: false
});
return $.parseJSON(ajax.responseText);
},
datasFields: function(model) {
return this.jsonContent(base_url+'/opac/datas/fields/model/'+model);
},
fieldValues: function(model) {
return this.jsonContent(base_url+'/opac/datas/values/field/'+model);
},
numberOf: function(model, id, child_name) {
return this.jsonContent(base_url+'/opac/datas/numberof/model/'+model+'/id/'+id+'/children/'+child_name);
}
};
};
} (jQuery));
......@@ -18,22 +18,55 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
var fixture;
var fixture = '';
var helper = null;
var options = null;
QUnit.module('custom_fields', {
setup: function() {
fixture = $('<div></div>');
jQuery.ajax = function (param) {
options = param;
var responseText = function() {
return false;
};
return this;
};
jQuery.parseJSON = function(response) {
return response;
}
helper = $.fn.report_helper();
helper.download = function() {};
}
});
test('plugin is defined', function() {
ok($.fn.report_helper);
});
test('link to download csv should be present', function() {
var helper = fixture.report_helper();
helper.downloadReport('info');
equal(fixture.find('a[href*="data:attachment/csv,info"]').length, 1, fixture.html());
equal($('body').find('a[href*="data:attachment/csv,info"]').length, 1, $('body').html());
});
test('url for data model should be as expected' ,function() {
var fields = helper.datasFields('Article');
equal(options.url.length, window.location.hostname+'/opac/datas/fields/model/Artcile'.length);
});
test('url for field values should be as expected' ,function() {
var values = helper.fieldValues(456);
equal(options.url.length, window.location.hostname+'/opac/datas/values/field/456'.length);
});
test('url for number of children by model and id should be as expected' ,function() {
var values = helper.numberOf('Formation',98,'Session');
equal(options.url.length, window.location.hostname+'/opac/datas/numberof/model/Formation/id/98/children/Session'.length, options.url);
});
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