Skip to content

Commit

Permalink
Dev: Move CPDB JS into a namespace object
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 22, 2016
1 parent d3cdefb commit 62e5261
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 81 deletions.
Expand Up @@ -28,7 +28,7 @@
'htmlOptions' => array('class'=> 'table-responsive'),
'rowHtmlOptionsExpression' => '["data-attribute_id" => $data->attribute_id]',
'itemsCssClass' => 'table table-responsive table-striped',
'afterAjaxUpdate' => 'bindButtons',
'afterAjaxUpdate' => 'LS.CPDB.bindButtons',
'summaryText' => gT('Displaying {start}-{end} of {count} result(s).').' '. sprintf(gT('%s rows per page'),
CHtml::dropDownList(
'pageSizeAttributes',
Expand Down
Expand Up @@ -76,7 +76,7 @@
'filter'=>$model,
'htmlOptions' => array('class'=> 'table-responsive'),
'itemsCssClass' => 'table table-responsive table-striped',
'afterAjaxUpdate' => 'bindButtons',
'afterAjaxUpdate' => 'LS.CPDB.bindButtons',
'ajaxType' => 'POST',
'beforeAjaxUpdate' => 'insertSearchCondition',
'template' => "{items}\n<div id='tokenListPager'><div class=\"col-sm-4\" id=\"massive-action-container\">$massiveAction</div><div class=\"col-sm-4 pager-container \">{pager}</div><div class=\"col-sm-4 summary-container\">{summary}</div></div>",
Expand Down
20 changes: 20 additions & 0 deletions application/views/admin/participants/massive_actions/_selector.php
Expand Up @@ -40,6 +40,26 @@
'aCustomDatas' => array(
),
),

// Export
array(
'type' => 'action',
'action' => 'export',
'url' => App()->createUrl('/admin/participants/sa/export'),
'iconClasses' => 'icon-exportcsv text-success',
'text' => gT('Export'),
'grid-reload' => 'no',

'actionType' => 'window-location-href',
),
/*
// Share
array(
),
// Add to survey
array(
)
*/
)
));

Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/participants/sharePanel_view.php
Expand Up @@ -13,7 +13,7 @@
'columns' => $model->columns,
'filter'=>$model,
'ajaxType' => 'POST',
'afterAjaxUpdate' => 'bindButtons',
'afterAjaxUpdate' => 'LS.CPDB.bindButtons',
'summaryText' => gT('Displaying {start}-{end} of {count} result(s).').' '. sprintf(gT('%s rows per page'),
CHtml::dropDownList(
'pageSizeShareParticipantView',
Expand Down
168 changes: 90 additions & 78 deletions scripts/admin/participantpanel.js
@@ -1,5 +1,5 @@
//Namespacing all Methods of the participant panel in one JS-Prototype
var Bindings = function(){
LS.CPDB = (function() {
var

// Basic modal used by all submethods
Expand Down Expand Up @@ -68,8 +68,74 @@ var Bindings = function(){
});
},

/**
* Run when user clicks 'Export'
* Used for both all participants and checked participants
* @return
*/
onClickExport = function() {
var postdata = {
selectedParticipant: [],
YII_CSRF_TOKEN : LS.data.csrfToken
};
$('.selector_participantCheckbox:checked').each(function(i,item){
postdata.selectedParticipant.push($(item).val());
});

$.ajax({
url: exporttocsvcountall,
data: postdata,
method: 'POST',
success: function(data) {
count = data;
if(count == 0)
{
$('#exportcsvallnorow').modal('show');
$('#exportcsvallnorow').on('shown.bs.modal', function(e) {
var self = this;
$(this).find('.exportButton').remove();
});
}
else
{
$('#exportcsv').modal('show');
$('#exportcsv').on('shown.bs.modal', function(e) {
var self = this;
$(this).find('h4.modal-title').text(count);
$(this).find('.exportButton').on('click', function(){
var dldata = postdata;
dldata.attributes =$('#attributes').val().join('+');
console.log(dldata);
var dlForm = $("<form></form>")
.attr('action', exportToCSVURL)
.attr('method', "POST");
$.each(dldata, function(key,value){
$('<input />')
.attr('name', key)
.attr('value', value)
.appendTo(dlForm);
});
dlForm.submit();
$(self).modal("hide");
});
$('#attributes')
.multiselect({
includeSelectAllOption:true,
selectAllValue: '0',
selectAllText: sSelectAllText,
nonSelectedText: sNonSelectedText,
nSelectedText: sNSelectedText,
maxHeight: 140
});
});
/* $.download(exporttocsvall,'searchcondition=dummy',$('#exportcsvallprocessing').dialog("close"));*/
}
}
});
},

// Basic settings and bindings that should take place in all three views
basics = function(){
basics = function() {
// Code for AJAX download
jQuery.download = function(url, data, method){
//url and data options required
Expand All @@ -87,70 +153,8 @@ var Bindings = function(){
.appendTo('body').submit().remove();
};
};
/**
* @TODO rewrite export
*/
$('#export').click(function(){
var postdata = {
selectedParticipant: [],
YII_CSRF_TOKEN : LS.data.csrfToken
};
$('.selector_participantCheckbox:checked').each(function(i,item){
postdata.selectedParticipant.push($(item).val());
});

$.ajax({
url: exporttocsvcountall,
data: postdata,
method: 'POST',
success: function(data) {
count = data;
if(count == 0)
{
$('#exportcsvallnorow').modal('show');
$('#exportcsvallnorow').on('shown.bs.modal', function(e) {
var self = this;
$(this).find('.exportButton').remove();
});
}
else
{
$('#exportcsv').modal('show');
$('#exportcsv').on('shown.bs.modal', function(e) {
var self = this;
$(this).find('h4.modal-title').text(count);
$(this).find('.exportButton').on('click', function(){
var dldata = postdata;
dldata.attributes =$('#attributes').val().join('+');
console.log(dldata);
var dlForm = $("<form></form>")
.attr('action', exportToCSVURL)
.attr('method', "POST");
$.each(dldata, function(key,value){
$('<input />')
.attr('name', key)
.attr('value', value)
.appendTo(dlForm);
});
dlForm.submit();
$(self).modal("hide");
});
$('#attributes')
.multiselect({
includeSelectAllOption:true,
selectAllValue: '0',
selectAllText: sSelectAllText,
nonSelectedText: sNonSelectedText,
nSelectedText: sNSelectedText,
maxHeight: 140
});
});
/* $.download(exporttocsvall,'searchcondition=dummy',$('#exportcsvallprocessing').dialog("close"));*/
}
}
});
});
},

//JS-bindings especially for the participantPanel
participantPanel = function(){
$('#removeAllFilters').on('click', function(e){
Expand Down Expand Up @@ -314,22 +318,30 @@ var Bindings = function(){
$.fn.yiiGridView.update('share_central_participants',{ data:{ pageSizeShareParticipantView: $(this).val() }});
});
};

function bindButtons() {
basics();
participantPanel();
attributePanel();
sharePanel();

/**
* @TODO rewrite export
*/
$('#export').click(onClickExport);
};

return {
basics : basics,
participantPanel : participantPanel,
attributePanel : attributePanel,
sharePanel : sharePanel
basics: basics,
participantPanel: participantPanel,
attributePanel: attributePanel,
sharePanel: sharePanel,
onClickExport: onClickExport,
bindButtons: bindButtons
};

}
})();

var bind = new Bindings();
function bindButtons(){
bind.basics();
bind.participantPanel();
bind.attributePanel();
bind.sharePanel();
};
function rejectParticipantShareAjax(participant_id){
var runRejectParticipantShareAjax = function(){
$.ajax({
Expand Down Expand Up @@ -365,4 +377,4 @@ function insertSearchCondition(id,options){
return options;
}

$(document).ready(bindButtons);
$(document).ready(LS.CPDB.bindButtons);

0 comments on commit 62e5261

Please sign in to comment.