Skip to content

Commit

Permalink
Dev Implemented JS function to remove the surrounding DIV of CSRF pro…
Browse files Browse the repository at this point in the history
…tection token if needed
  • Loading branch information
c-schmitz committed Dec 4, 2012
1 parent 578449a commit 70a793f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
15 changes: 15 additions & 0 deletions scripts/admin/admin_core.js
Expand Up @@ -648,4 +648,19 @@ if ('ab'.substr(-1) != 'b') {
return substr.call(this, start, length);
}
}(String.prototype.substr);
}

/**
* Yii CSRF protection divs breaks this script so this function moves the
* hidden CSRF field out of the div and remove it if needed
*
*/
function removeCSRFDivs()
{
$('input[name=YII_CSRF_TOKEN]').each(function(){
parent = $(this).parent();
grandfather = $(parent).parent();
grandfather.append(this);
parent.remove();
});
}
1 change: 1 addition & 0 deletions scripts/admin/answers.js
@@ -1,5 +1,6 @@
var labelcache=[];
$(document).ready(function(){
removeCSRFDivs();
$('.tab-page:first .answertable tbody').sortable({ containment:'parent',
update:aftermove,
distance:3});
Expand Down
20 changes: 15 additions & 5 deletions scripts/admin/labels.js
@@ -1,5 +1,14 @@
// $Id: labels.js 8649 2010-04-28 21:38:53Z c_schmitz $

/*
* LimeSurvey
* Copyright (C) 2007-2012 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
$(document).ready(function(){
$('#btnDumpLabelSets').click(function(){
if ($('#labelsets > option:selected').size()==0)
Expand All @@ -13,6 +22,8 @@ $(document).ready(function(){
}
});

removeCSRFDivs();

if ($(".answertable tbody").children().length == 0)
add_label(undefined);

Expand Down Expand Up @@ -62,8 +73,7 @@ $(document).ready(function(){
$("tbody>tr",$("#tabs>form>div:first")).each(function(trindex,trelement){

var tr_code = $(trelement).attr('id');
tr_code=tr_code.split('_');// first is row, second langage and last the rox
tr_code=tr_code[2];
tr_code=tr_code.substr(3);
dataToSend['codelist'].push(tr_code);
dataToSend[tr_code] = {
code: $("#code_"+tr_code).val(),
Expand Down Expand Up @@ -260,7 +270,7 @@ function createNewLabelTR(alternate,first){
x = "<tr ";
if (alternate)
x = x + "class= 'highlight' ";
x = x + "style = 'white-space: nowrap;' id='row_###lang###_###next###'>";
x = x + "style = 'white-space: nowrap;' id='row###next###'>";

if (!first)
x = x + "<td>###codeval###</td><td>###assessmentval###</td>";
Expand Down
1 change: 1 addition & 0 deletions scripts/admin/subquestions.js
@@ -1,6 +1,7 @@
// $Id: subquestions.js 9692 2011-01-15 21:31:10Z c_schmitz $
var labelcache=[];
$(document).ready(function(){
removeCSRFDivs();
$("body").delegate(".code", "keypress", function(e) {
key=e.which;
if ( key==null || key==0 || key==8 || key==9 || key==27 )
Expand Down

0 comments on commit 70a793f

Please sign in to comment.