Commit af10b0e7 authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

delete a form

parent 02ed6162
......@@ -10,18 +10,17 @@ class DeleteAction extends CAction
//check form et session exist
if($form = PHDB::findOne( Form::COLLECTION , array("_id"=>new MongoId(($id)))) )
{
// if( $form["creator"] == Yii::app()->session["userId"] ||
// Authorisation::isElementAdmin($id, Form::ANSWER_COLLECTION, Yii::app()->session["userId"], false)) {
// if( Authorisation::isElementAdmin($id, Form::ANSWER_COLLECTION, Yii::app()->session["userId"], false)) {
// if(isset($form["ids"])){
// $formId = implode("|", $form["ids"]);
// PHDB::remove( Form::ANSWER_COLLECTION, ["formId" => $formId]);
// }
// PHDB::remove( Form::COLLECTION, ["_id" => new MongoId($id)] );
// echo Rest::json(['result' => true ]);
if(isset($form["ids"])){
$formId = implode("|", $form["ids"]);
PHDB::remove( Form::ANSWER_COLLECTION, ["formId" => $formId]);
}
PHDB::remove( Form::COLLECTION, ["_id" => new MongoId($id)] );
echo Rest::json(['result' => true ]);
// } else
// $ctrl->render("co2.views.default.unTpl",array("msg"=>Yii::t("project", "Unauthorized Access."),"icon"=>"fa-lock"));
// echo Rest::json(['result' => false, "msg"=>Yii::t("project", "Unauthorized Access."),"icon"=>"fa-lock"]);
} else
echo Rest::json(['result' => false, "msg"=>"Formulaire introuvable","icon"=>"fa-search"]);
}
......
......@@ -60,8 +60,7 @@ jQuery(document).ready(function() {
});
$('.deleteFormBtn').off().click( function(){
formId = $(this).data("id");
collection = "forms";
tplCtx.id = $(this).data("id");
bootbox.dialog({
title: "Confirmez la suppression",
message: "<span class='text-red bold'><i class='fa fa-warning'></i> Cette action sera irréversible</span>",
......@@ -70,9 +69,12 @@ jQuery(document).ready(function() {
label: "Ok",
className: "btn btn-primary pull-left",
callback: function() {
getAjax("",baseUrl+"/survey/form/delete/id/"+id,function(){
toastr.success("Le form été supprimée avec succès");
$("#formline"+id).remove();
getAjax("",baseUrl+"/survey/form/delete/id/"+tplCtx.id,function(res){
if(res.result)
toastr.success("Le form été supprimée avec succès");
else
toastr.error(res.msg);
urlCtrl.loadByHash(location.hash);
},"html");
}
},
......
Supports Markdown
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