Commit dce623fc authored by Tibor Katelbach's avatar Tibor Katelbach

adding Delete

parent 37c91bcc
......@@ -9,9 +9,10 @@
public function actions()
{
return array(
'create' => 'survey.controllers.openForm.CreateAction',
'edit'=> 'survey.controllers.openForm.EditAction',
'get' => 'survey.controllers.openForm.GetAction',
'create' => 'survey.controllers.form.CreateAction',
'edit' => 'survey.controllers.form.EditAction',
'get' => 'survey.controllers.form.GetAction',
'delete' => 'survey.controllers.form.DeleteAction',
);
}
}
......@@ -31,9 +31,9 @@ class IndexAction extends CAction
//Rest::json($params); exit;
$params["answer"] = $answer;
// TODO améliorer getdataForAnser pour soit viré la création de lanswers soit charger la bonne answer
//Rest::json($params); exit;
$form = PHDB::findOne( Form::COLLECTION , array("id"=>$_GET["form"]));
$form = PHDB::findOne( Form::COLLECTION , array("id"=>$answer["formId"]));
$parentForm = Slug::getElementBySlug($form["id"]);
$canEditForm = false;
$canEditAnswer = false;
......@@ -66,7 +66,7 @@ class IndexAction extends CAction
$params["canSee"] = $canSeeAnswer;
$params["mode"] = (!empty($mode) ? $mode : "r");
//$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.forms.formWizard";
$tpl=(!empty($form["tpl"])) ? $form["tpl"] : "survey.views.tpls.forms.formWizard";
$tpl=(!empty($this->getController()->costum["form"]["tpl"])) ? $this->getController()->costum["form"]["tpl"] : "survey.views.tpls.forms.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
} else {
if(Yii::app()->request->isAjaxRequest)
......
<?php
class DeleteAction extends CAction
{
public function run($id) {
$ctrl=$this->getController();
if ( ! Person::logguedAndValid() )
echo Rest::json(['result' => false, "msg"=>Yii::t("common","Please Login First"),"icon"=>"fa-sign-in"]);
//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(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"));
} else
echo Rest::json(['result' => false, "msg"=>"Formulaire introuvable","icon"=>"fa-search"]);
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
class GetAction extends CTKAction
{
//if $slug : getd all the forms for an element.slug
//http://127.0.0.1/survey/form/get/slug/dealAH
//if $id : opens the forms
public function run($slug = null,$form=null)
{
......
......@@ -10,7 +10,7 @@ class Answer{
}
public static function generateAnswer($formId){
public static function generateAnswer(){
$costum = CacheHelper::getCostum();
//Rest::json($costum); exit;
$ans = [
......@@ -46,24 +46,5 @@ class Answer{
}
public static function csv($elements, $idElt, $valElt, $forms ){
$elements[$idElt]["id"] = $idElt;
$elements[$idElt]["user"] = $valElt["user"];
$elements[$idElt]["created"] = $valElt["created"];
if(!empty($valElt["answers"])){
foreach ($forms as $keyF => $valF) {
if(!empty($valF["id"]) && !empty($valElt["answers"][$valF["id"]])){
foreach ($valElt["answers"][$valF["id"]] as $keyAns => $valAns) {
if(!empty($valF["inputs"]) && !empty($valF["inputs"][$keyAns]) && !empty($valF["inputs"][$keyAns]["label"])){
$elements[$idElt][$valF["inputs"][$keyAns]["label"]] = $valAns;
}
}
}
}
}
return $elements;
}
}
?>
\ No newline at end of file
......@@ -708,8 +708,11 @@ class Form {
$params["el"]["id"] = $costum["contextId"];
}
//if(isset($_GET["form"]))
$form = PHDB::findOne( Form::COLLECTION, [ "_id" => new MongoId($_GET["form"]) ] );
if(isset($_GET["form"]))
$form = PHDB::findOne( Form::COLLECTION, [ "_id" => new MongoId($_GET["form"]) ] );
if(!isset($form["ids"])){
return $params;
}
$params["parentForm"] = $form;
if(isset($costum["hasOpenForm"]))
......
......@@ -10,9 +10,13 @@ foreach ($forms as $fix => $f) {
if($ct == 0)
echo '<div class="row ">';
?>
<div class="liForm col-md-4 col-sm-3 col-xs-12 " style="padding:5px;">
<div id="formline<?php echo $fix ?>" class="liForm col-md-4 col-sm-3 col-xs-12 " style="padding:5px;">
<div class="col-xs-12 " style="padding:10px;border:1px solid grey">
<h4 class="letter-turq"><?php echo (isset($f['name'])) ? $f['name'] : "Formulaire ".$el["slug"] ?></h4>
<h4 class="letter-turq ">
<span class="col-xs-10"><?php echo (isset($f['name'])) ? $f['name'] : "Formulaire ".$el["slug"] ?></span>
<span class="col-xs-2">
<a href="javascript:;" class="editFormBtn" data-id="<?php echo $fix ?>"><i class="fa fa-pencil text-dark"></i></a>
<a href="javascript:;" class="deleteFormBtn" data-id="<?php echo $fix ?>"><i class="fa fa-trash text-red"></i></a> </span></h4>
steps : <br/>
<?php
if(isset($f['ids'])){
......@@ -54,6 +58,32 @@ jQuery(document).ready(function() {
tplCtx.id = $(this).data("id");
dyFObj.openForm(oformParams)
});
$('.deleteFormBtn').off().click( function(){
formId = $(this).data("id");
collection = "forms";
bootbox.dialog({
title: "Confirmez la suppression",
message: "<span class='text-red bold'><i class='fa fa-warning'></i> Cette action sera irréversible</span>",
buttons: [
{
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();
},"html");
}
},
{
label: "Annuler",
className: "btn btn-default pull-left",
callback: function() {}
}
]
});
});
});
var oform = {
......
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