Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Yii formatted URL #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions js_plugins/jstree.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ $(function () {
"html_data":{
"ajax":{
"type":"POST",
"url":Yii_js.baseUrl + "/" + JsTreeBehavior.controllerID + "/fetchTree",
"url":JsTreeBehavior.url.fetchTree,
"data":function (n) {
return {
id:n.attr ? n.attr("id") : 0,
"YII_CSRF_TOKEN":Yii_js.csrf
"YII_CSRF_TOKEN":JsTreeBehavior.csrfToken
};
}
}
Expand All @@ -69,10 +69,10 @@ $(function () {
id = obj.attr("id").replace("node_", "");
$.ajax({
type:"POST",
url:Yii_js.baseUrl + "/" + JsTreeBehavior.controllerID + "/returnForm",
url:JsTreeBehavior.url.returnForm,
data:{
'update_id':id,
"YII_CSRF_TOKEN":Yii_js.csrf
"YII_CSRF_TOKEN":JsTreeBehavior.csrfToken
},
'beforeSend':function () {
spinner.spin(spinnertarget);
Expand Down Expand Up @@ -102,10 +102,10 @@ $(function () {
id = obj.attr("id").replace("node_", "")
$.ajax({
type:"POST",
url:Yii_js.baseUrl + "/" + JsTreeBehavior.controllerID + "/returnView",
url:JsTreeBehavior.url.returnView,
data:{
"id":id,
"YII_CSRF_TOKEN":Yii_js.csrf
"YII_CSRF_TOKEN":JsTreeBehavior.csrfToken
},
beforeSend:function () {
spinner.spin(spinnertarget);
Expand Down Expand Up @@ -181,11 +181,11 @@ $(function () {
.bind("rename.jstree", function (e, data) {
$.ajax({
type:"POST",
url:Yii_js.baseUrl + "/" + JsTreeBehavior.controllerID + "/rename",
url:JsTreeBehavior.url.rename,
data:{
"id":data.rslt.obj.attr("id").replace("node_", ""),
"new_name":data.rslt.new_name,
"YII_CSRF_TOKEN":Yii_js.csrf
"YII_CSRF_TOKEN":JsTreeBehavior.csrfToken
},
beforeSend:function () {
spinner.spin(spinnertarget);
Expand All @@ -208,10 +208,10 @@ $(function () {
.bind("remove.jstree", function (e, data) {
$.ajax({
type:"POST",
url:Yii_js.baseUrl + "/" + JsTreeBehavior.controllerID + "/remove",
url:JsTreeBehavior.url.remove,
data:{
"id":data.rslt.obj.attr("id").replace("node_", ""),
"YII_CSRF_TOKEN":Yii_js.csrf
"YII_CSRF_TOKEN":JsTreeBehavior.csrfToken
},
beforeSend:function () {
spinner.spin(spinnertarget);
Expand All @@ -234,10 +234,10 @@ $(function () {
parent_id = data.rslt.parent.attr("id").replace("node_", "");
$.ajax({
type:"POST",
url:Yii_js.baseUrl + "/" + JsTreeBehavior.controllerID + "/returnForm",
url:JsTreeBehavior.url.returnForm,
data:{ 'name':newname,
'parent_id':parent_id,
"YII_CSRF_TOKEN":Yii_js.csrf
"YII_CSRF_TOKEN":JsTreeBehavior.csrfToken
},
beforeSend:function () {
spinner.spin(spinnertarget);
Expand Down Expand Up @@ -307,7 +307,7 @@ $(function () {
$.ajax({
async:false,
type:'POST',
url:Yii_js.baseUrl + "/" + JsTreeBehavior.controllerID + "/moveCopy",
url:JsTreeBehavior.url.moveCopy,

data:{
"moved_node":moved_node,
Expand All @@ -320,7 +320,7 @@ $(function () {
"copy":copy,
"copied_node":copied_node,
"replaced_node":replaced_node,
"YII_CSRF_TOKEN":Yii_js.csrf
"YII_CSRF_TOKEN":JsTreeBehavior.csrfToken
},
beforeSend:function () {
spinner.spin(spinnertarget);
Expand Down Expand Up @@ -356,10 +356,10 @@ $(function () {
$("#add_root").click(function () {
$.ajax({
type:'POST',
url:Yii_js.baseUrl + "/" + JsTreeBehavior.controllerID + "/returnForm",
url:JsTreeBehavior.url.returnForm,
data:{
"create_root":true,
"YII_CSRF_TOKEN":Yii_js.csrf
"YII_CSRF_TOKEN":JsTreeBehavior.csrfToken
},
beforeSend:function () {
spinner.spin(spinnertarget);
Expand Down Expand Up @@ -389,4 +389,4 @@ $(function () {
$("#reload").click(function () {
jQuery("#" + JsTreeBehavior.container_ID).jstree("refresh");
});
});
});
73 changes: 36 additions & 37 deletions widgets/JsTreeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ public function init()
private function register_Js_Css()
{

$baseUrl = Yii::app()->baseUrl;
$csrf = Yii::app()->request->csrfToken;
$open_nodes = $this->getOpenNodes();
$themes = json_encode($this->themes);
$plugins = json_encode($this->plugins);

//assuming that we use the widget in controller with JsTreeBehavior
if(isset($this->controller->module)){
$controllerID = $this->controller->module->id."/".$this->controller->id;
Expand All @@ -63,50 +57,55 @@ private function register_Js_Css()
}

//pass php variables to javascript
$jstree_behavior_js = <<<EOD
(function ($) {
JsTreeBehavior = {
controllerID:'$controllerID',
container_ID:'$this->jstree_container_ID',
open_nodes:$open_nodes,
themes:$themes,
plugins:$plugins,
},
Yii_js = {
baseUrl:'$baseUrl',
csrf:'$csrf'
}
}(jQuery));
EOD;
$jstree_behavior_js = '(function ($) { JsTreeBehavior = ' . json_encode(array(
'controllerID' => $controllerID,
'container_ID' => $this->id,
'open_nodes' => $this->getOpenNodes(),
'themes' => $this->themes,
'plugins' => $this->plugins,
'urlFormat' => Yii::app()->urlManager->urlFormat,
'csrfToken' => Yii::app()->request->csrfToken,
'url' => array(
'fetchTree' => Yii::app()->createUrl($controllerID . '/fetchTree'),
'returnForm' => Yii::app()->createUrl($controllerID . '/returnForm'),
'returnView' => Yii::app()->createUrl($controllerID . '/returnView'),
'rename' => Yii::app()->createUrl($controllerID . '/rename'),
'remove' => Yii::app()->createUrl($controllerID . '/remove'),
'moveCopy' => Yii::app()->createUrl($controllerID . '/moveCopy'),
),
)) . '; }(jQuery));';

$baseUrl = Yii::app()->baseUrl;
$clientScript = Yii::app()->clientScript;

//uncomment to register jquery only if you have not already registered it somewhere else in your application
//Yii::app()->clientScript->registerCoreScript('jquery');
//$clientScript->registerCoreScript('jquery');

//uncomment to register bootstrap css if you have not already included it (optional),or else you will have to style the html by yourself.
//Yii::app()->clientScript->registerCssFile($baseUrl . '/js_plugins/bootstrap/css/bootstrap.css');
Yii::app()->clientScript->registerCoreScript('cookie');
Yii::app()->clientScript->registerScript(__CLASS__ . 'jstree_behavior_params', $jstree_behavior_js, CClientScript::POS_END);
//$clientScript->registerCssFile($baseUrl . '/js_plugins/bootstrap/css/bootstrap.css');
$clientScript->registerCoreScript('cookie');
$clientScript->registerScript(__CLASS__ . 'jstree_behavior_params', $jstree_behavior_js, CClientScript::POS_END);

//modal dialog with noty.js
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/noty/js/noty/jquery.noty.js', CClientScript::POS_END);
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/noty/js/noty/layouts/center.js', CClientScript::POS_END);
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/noty/js/noty/themes/default.js', CClientScript::POS_END);
$clientScript->registerScriptFile($baseUrl . '/js_plugins/noty/js/noty/jquery.noty.js', CClientScript::POS_END);
$clientScript->registerScriptFile($baseUrl . '/js_plugins/noty/js/noty/layouts/center.js', CClientScript::POS_END);
$clientScript->registerScriptFile($baseUrl . '/js_plugins/noty/js/noty/themes/default.js', CClientScript::POS_END);
//js spinner
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/spin.min.js', CClientScript::POS_END);
$clientScript->registerScriptFile($baseUrl . '/js_plugins/spin.min.js', CClientScript::POS_END);
//fancybox
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/fancybox2/jquery.fancybox.js', CClientScript::POS_END);
Yii::app()->clientScript->registerCssFile($baseUrl . '/js_plugins/fancybox2/jquery.fancybox.css');
$clientScript->registerScriptFile($baseUrl . '/js_plugins/fancybox2/jquery.fancybox.js', CClientScript::POS_END);
$clientScript->registerCssFile($baseUrl . '/js_plugins/fancybox2/jquery.fancybox.css');

Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/json2/json2.js');
$clientScript->registerScriptFile($baseUrl . '/js_plugins/json2/json2.js');

Yii::app()->clientScript->registerCoreScript('yiiactiveform');
$clientScript->registerCoreScript('yiiactiveform');

// jquery.form.js plugin http://malsup.com/jquery/form/
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/ajaxform/jquery.form.js', CClientScript::POS_END);
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/ajaxform/form.js', CClientScript::POS_END);
$clientScript->registerScriptFile($baseUrl . '/js_plugins/ajaxform/jquery.form.js', CClientScript::POS_END);
$clientScript->registerScriptFile($baseUrl . '/js_plugins/ajaxform/form.js', CClientScript::POS_END);
//jstree
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/jstree/jquery.jstree.js', CClientScript::POS_END);
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js_plugins/jstree.behavior.js', CClientScript::POS_END);
$clientScript->registerScriptFile($baseUrl . '/js_plugins/jstree/jquery.jstree.js', CClientScript::POS_END);
$clientScript->registerScriptFile($baseUrl . '/js_plugins/jstree.behavior.js', CClientScript::POS_END);
}

/**
Expand Down