-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
23 changed files
with
465 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})($); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.