diff --git a/common/modules/comment/Controller.php b/common/modules/comment/Controller.php index 5e65752..1d7e87b 100644 --- a/common/modules/comment/Controller.php +++ b/common/modules/comment/Controller.php @@ -205,5 +205,33 @@ return [ 'error' => 'Missing comment_id' ]; } } + + public function actionDeleteAnswer() + { + \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $post = \Yii::$app->request->post('CommentProjectAnswer'); + $get = \Yii::$app->request->get(); + if(empty( $post[ 'comment_id' ] ) && !empty( $get[ 'comment_id' ] )) { + $post[ 'comment_id' ] = $get[ 'comment_id' ]; + } + if(!empty( $post[ 'comment_id' ] )) { + if($model = \common\modules\comment\models\CommentProjectAnswer::findOne($post[ 'comment_id' ])) { + /** + * @var \common\modules\comment\models\Comment $model + */ + $model->scenario = is_int(\Yii::$app->user->getId()) ? \common\modules\comment\models\CommentProjectAnswer::SCENARIO_USER : \common\modules\comment\models\CommentProjectAnswer::SCENARIO_GUEST; + if($model->deleteComment()) { + \Yii::$app->response->data = [ 'text' => 'Comment marked as deleted and will be check by administrators' ]; + } else { + \Yii::$app->response->data = [ 'error' => $model->hasErrors('comment_id') ? $model->getFirstError('comment_id') : 'Cannot delete message' ]; + } + } else { + \Yii::$app->response->data = [ 'error' => 'Comment not found' ]; + }; + } else { + \Yii::$app->response->data = [ 'error' => 'Missing comment_id' ]; + } + \Yii::$app->response->send(); + } } \ No newline at end of file diff --git a/common/modules/comment/models/CommentProjectAnswer.php b/common/modules/comment/models/CommentProjectAnswer.php index b66d963..2b4c5c5 100644 --- a/common/modules/comment/models/CommentProjectAnswer.php +++ b/common/modules/comment/models/CommentProjectAnswer.php @@ -108,12 +108,10 @@ public function beforeDelete() { - if(parent::beforeDelete()) { - - return false; - } else { - return false; + if(!empty($this->child)) { + $this->child->delete(); } + return parent::beforeDelete(); // TODO: Change the autogenerated stub } public function checkCreate() diff --git a/common/modules/comment/resources/comment.js b/common/modules/comment/resources/comment.js index b0f3954..b689e2f 100644 --- a/common/modules/comment/resources/comment.js +++ b/common/modules/comment/resources/comment.js @@ -2,8 +2,9 @@ $(function() { $(document).on('click', '.artbox_comment_container .removeable', function(e) { e.preventDefault(); - var container = $(this).parents('.artbox_comment_container'); - $(container).remove(); + $(this).remove(); +// var container = $(this).parents('.artbox_comment_container'); +// $(container).remove(); }); $(document).on( @@ -152,4 +153,46 @@ $(function() { ) } ); + + $(document).on( + 'click', '.artbox_comment_delete_answer', function(e) + { + e.preventDefault(); + var container = $(this).parents('.artbox_comment_container'); + var comment_id = $(container).data('key'); + var form_name = $(container).data('form'); + if(confirm("Уверены, что хотите удалить вопрос?")) + { + $.post( + '/artbox-comment/delete-answer', { + CommentProjectAnswer : { + comment_id : comment_id + } + }, function(data, textStatus, jqXHR) + { + if(!data.error) + { + $(container).empty(); + $(container).append('
' + data.text + '
'); + } else + { + $(container).prepend('' + data.error + '
') + } + } + ); + } + } + ); + + $(document).on('click', '.artbox_comment_reply_answer', function(e) { + e.preventDefault(); + var widget = $(this).parents('.artbox_comment_widget'); + $(widget).find('.artbox_comment_answer_label').text('Ответ'); + }); + + $(document).on('click', '.artbox_comment_reply_answer_block', function(e) { + var form = $(this).parents('.artbox_comment_form'); + $(form).find('.artbox_comment_answer_label').text('Вопрос'); + }); + }); diff --git a/common/modules/comment/widgets/views/_question_comment_view.php b/common/modules/comment/widgets/views/_question_comment_view.php index 4d5a1c0..eb4859b 100644 --- a/common/modules/comment/widgets/views/_question_comment_view.php +++ b/common/modules/comment/widgets/views/_question_comment_view.php @@ -14,8 +14,11 @@ * @var User $user */ $user = $model->user; - if(empty($model->comment_pid)) { - $model->buildButtons([ 'reply', 'delete' ]); + if(empty( $model->comment_pid )) { + $model->buildButtons([ + 'reply', + 'delete', + ]); } ?>