Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
guga-grigolia committed Jan 17, 2017
2 parents a4c2489 + 47e53bd commit 2200eb0
Show file tree
Hide file tree
Showing 23 changed files with 465 additions and 37 deletions.
7 changes: 6 additions & 1 deletion AssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ class AssetBundle extends \yii\web\AssetBundle
'css/main.css'
];

public $js = [
'js/i18nContent.js'
];

public $depends = [
'yii\bootstrap\BootstrapAsset'
'yii\bootstrap\BootstrapAsset',
'yii\bootstrap\BootstrapPluginAsset'
];

public function init()
Expand Down
84 changes: 84 additions & 0 deletions actions/ToggleStatusAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/**
* Created by PhpStorm.
* User: koco
* Date: 1/16/2017
* Time: 1:30 PM
*/

namespace centigen\i18ncontent\actions;

use Yii;
use yii\base\Action;
use yii\base\InvalidConfigException;
use yii\web\NotFoundHttpException;
use yii\web\Response;


/**
* Class ToggleStatusAction
*
* @author Giorgi Keshikashvili
* @package centigen\i18ncontent\actions
*/
class ToggleStatusAction extends Action
{
/**
* model class name with namespace
*
* @var null
*/
public $model = null;

/**
* status field name
*
* @var string
*/
public $statusField = 'status';


public function init()
{
if($this->model === null){
throw new InvalidConfigException('In class centigen\i18ncontent\actions\ToggleStatusAction model param must be passed!');
}
parent::init();
}

public function run()
{
$request = Yii::$app->request;
$model = $this->findModel($request->post('id'));
$model->{$this->statusField} = (int)!$model->{$this->statusField};

if($model->save()){
$res = [
'success' => true,
'msg' => '',
'errors' => '',
];
}else{
$res = [
'success' => false,
'msg' => Yii::t('i18ncontent', 'Status change error!'),
'errors' => $model->errors,
];
}
Yii::$app->response->format = Response::FORMAT_JSON;

return $res;
}


protected function findModel($id)
{
$model = $this->model;
if (($model = $model::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
69 changes: 69 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,75 @@
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
margin-bottom: 30px;
}
.togglebutton {
vertical-align: middle;
}
.togglebutton,
.togglebutton label,
.togglebutton input,
.togglebutton .toggle {
user-select: none;
}
.togglebutton label {
cursor: pointer;
color: rgba(0, 0, 0, 0.26);
}
.togglebutton label:focus {
outline: 0;
}
.togglebutton label input[type=checkbox] {
opacity: 0;
width: 0;
height: 0;
}
.togglebutton label .toggle {
text-align: left;
}
.togglebutton label .toggle,
.togglebutton label input[type=checkbox][disabled] + .toggle {
content: "";
display: inline-block;
width: 30px;
height: 15px;
background-color: rgba(80, 80, 80, 0.7);
border-radius: 15px;
margin-right: 15px;
transition: background 0.3s ease;
vertical-align: middle;
}
.togglebutton label .toggle:after {
content: "";
display: inline-block;
width: 20px;
height: 20px;
background-color: #F1F1F1;
border-radius: 20px;
position: relative;
box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4);
left: -5px;
top: -2px;
transition: left 0.3s ease, background 0.3s ease, box-shadow 0.1s ease;
}
.togglebutton label input[type=checkbox][disabled] + .toggle:after,
.togglebutton label input[type=checkbox][disabled]:checked + .toggle:after {
background-color: #BDBDBD;
}
.togglebutton label input[type=checkbox] + .toggle:active:after,
.togglebutton label input[type=checkbox][disabled] + .toggle:active:after {
box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px rgba(0, 0, 0, 0.1);
}
.togglebutton label input[type=checkbox]:checked + .toggle:after {
left: 15px;
}
.togglebutton label input[type=checkbox]:checked + .toggle {
background-color: rgba(60, 141, 188, 0.5);
}
.togglebutton label input[type=checkbox]:checked + .toggle:after {
background-color: #3c8dbc;
}
.togglebutton label input[type=checkbox]:checked + .toggle:active:after {
box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px rgba(60, 141, 188, 0.1);
}
.table-wrapper table > thead > tr > th {
white-space: nowrap;
}
Expand Down
59 changes: 59 additions & 0 deletions assets/js/i18nContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Created by koco on 1/16/2017.
*/
(function ($) {
var I18nContent = function () {
this.$toggleBtn = $('.togglebutton > label > input');

this.init();
};

I18nContent.prototype = {
constructor: I18nContent,

init: function () {
this.toggleStatus();
},


toggleStatus: function () {
var me = this;
this.$toggleBtn.change(function() {
var $row = $(this).closest('tr');
var action = $row.data('toggle-action') || 'toggle-status';
me._post(action, {id: $row.data('key')}).done(function (res) {
if(res.success) {

}else{
alert(res.msg);
}
});

});
},


_get: function (url, data) {
return $.ajax({
url: url,
type: 'GET',
data: data,
dataType: 'json'
});
},

_post: function (url, data) {
return $.ajax({
url: url,
type: 'POST',
data: data,
dataType: 'json'
});
}


};


window.i18ncontent = new I18nContent();
})($);
85 changes: 85 additions & 0 deletions assets/less/_togglebutton.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.togglebutton {
vertical-align: middle;
&, label, input, .toggle {
user-select: none;
}
label {
cursor: pointer;
color: rgba(0,0,0, 0.26);
&:focus{
outline: 0;
}

// Hide original checkbox
input[type=checkbox] {
opacity: 0;
width: 0;
height: 0;
}

.toggle {
text-align: left; // Issue #737 horizontal form
}
// Switch bg off and disabled
.toggle,
input[type=checkbox][disabled] + .toggle {
content: "";
display: inline-block;
width: 30px;
height: 15px;
background-color: rgba(80, 80, 80, 0.7);
border-radius: 15px;
margin-right: 15px;
transition: background 0.3s ease;
vertical-align: middle;
}
// Handle off
.toggle:after {
content: "";
display: inline-block;
width: 20px;
height: 20px;
background-color: #F1F1F1;
border-radius: 20px;
position: relative;
box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4);
left: -5px;
top: -2px;
transition: left 0.3s ease, background 0.3s ease, box-shadow 0.1s ease;
}
input[type=checkbox] {
// Handle disabled
&[disabled] {
& + .toggle:after,
&:checked + .toggle:after {
background-color: #BDBDBD;
}
}

& + .toggle:active:after,
&[disabled] + .toggle:active:after {
box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px rgba(0, 0, 0, 0.1);
}

// Ripple off and disabled
&:checked + .toggle:after {
left: 15px;
}
}

// set bg when checked
input[type=checkbox]:checked {
+ .toggle {
background-color: fade(#3c8dbc, 50%); // Switch bg on
}

+ .toggle:after {
background-color: #3c8dbc; // Handle on
}

+ .toggle:active:after {
box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.4), 0 0 0 15px fade(#3c8dbc, 10%); // Ripple on
}
}
}
}
1 change: 1 addition & 0 deletions assets/less/main.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "mixins";
@import "helpers";
@import "tabs";
@import "_togglebutton";

.table-wrapper {
table > thead > tr > th {
Expand Down
10 changes: 10 additions & 0 deletions controllers/ArticleCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public function behaviors()
];
}

public function actions()
{
return [
'toggle-status' => [
'class' => 'centigen\i18ncontent\actions\ToggleStatusAction',
'model' => 'centigen\i18ncontent\models\ArticleCategory',
]
];
}

/**
* Lists all ArticleCategory models.
* @return mixed
Expand Down
8 changes: 7 additions & 1 deletion controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function behaviors()
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post']
'delete' => ['post'],
'ToggleStatus' => ['post']
]
],
\centigen\base\behaviors\LayoutBehavior::className()
Expand All @@ -45,6 +46,10 @@ public function actions()
'responseUrlParam'=> 'filelink',
'multiple' => false,
'disableCsrf' => true
],
'toggle-status' => [
'class' => 'centigen\i18ncontent\actions\ToggleStatusAction',
'model' => 'centigen\i18ncontent\models\Article',
]
];
}
Expand Down Expand Up @@ -123,6 +128,7 @@ public function actionDelete($id)
return $this->redirect(['index']);
}


/**
* Finds the Article model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
Expand Down
4 changes: 4 additions & 0 deletions controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function actions()
'responseUrlParam'=> 'filelink',
'multiple' => false,
'disableCsrf' => true
],
'toggle-status' => [
'class' => 'centigen\i18ncontent\actions\ToggleStatusAction',
'model' => 'centigen\i18ncontent\models\Page',
]
];
}
Expand Down
Loading

0 comments on commit 2200eb0

Please sign in to comment.