Making button not visible in CJuiDialog - yii

I have a problem with my CJuiDialog in yii. I want to set the 'delete'-Button to 'not visible',but that does not work, the button is still displayed.
Here is my code:
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dlg_EventCal',
'options' => array(
'title' => Yii::t('CalModule.fullCal', 'Event detail'),
'modal' => true,
'autoOpen' => false,
'hide' => 'slide',
'show' => 'slide',
'width'=> 400,
'buttons' => array(
array(
'text' => Yii::t('CalModule.fullCal', 'OK'),
'click' => "js:function() { eventDialogOK(); }"
),
array(
'text' => Yii::t('CalModule.fullCal', 'Cancel'),
'click' => 'js:function() { $(this).dialog("close"); }',
),
array(
'text' => Yii::t('CalModule.fullCal', 'Delete'),
'click' => 'js:function() { eventDialogDelete(); }',
'visible'=>Yii::app()->user->checkAccess('deleteAllEvents'),
),
))));

CJuiDialog only passes data to the jQuery.dialog plugin
Look at this function (from https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.dialog.js#L322):
_createButtons: function( buttons ) {
var that = this,
hasButtons = false;
// if we already have a button pane, remove it
this.uiDialogButtonPane.remove();
this.uiButtonSet.empty();
if ( typeof buttons === "object" && buttons !== null ) {
$.each( buttons, function() {
return !(hasButtons = true);
});
}
if ( hasButtons ) {
$.each( buttons, function( name, props ) {
var button, click;
props = $.isFunction( props ) ?
{ click: props, text: name } :
props;
// Default to a non-submitting button
props = $.extend( { type: "button" }, props );
// Change the context for the click callback to be the main element
click = props.click;
props.click = function() {
click.apply( that.element[0], arguments );
};
button = $( "<button></button>", props )
.appendTo( that.uiButtonSet );
if ( $.fn.button ) {
button.button();
}
});
this.uiDialog.addClass( "ui-dialog-buttons" );
this.uiDialogButtonPane.appendTo( this.uiDialog );
} else {
this.uiDialog.removeClass( "ui-dialog-buttons" );
}
}
All of your properties will be passed into props object and after that will used as properties for the button element:
button = $( "<button></button>", props )
So you need such code:
array(
'text' => Yii::t('CalModule.fullCal', 'Delete'),
'click' => 'js:function() { eventDialogDelete(); }',
'style' => Yii::app()->user->checkAccess('deleteAllEvents') ? '' : 'display: none;',
)
But in that case you need an additional check of the permissions on server-side!

Related

Vue.js updating text in a modal

I have a modal and I am trying to dynamically update the text.
in my data
return {
count: {
value: 5
},
}
then I have a method
bulkUserImport: function() {
this.isLoading = true;
let _this = this;
axios.post('bulkUpdate', {'csv': this.importData})
.then((r) => console.log(r))
.then(() => this.isLoading = false)
.then(function() {
_this.$modal.show('dialog', {
title: 'Adding your new Clients',
text: `Jobscan is now provisioning your accounts, page will refresh in ${_this.count.value} seconds.`,
buttons: [
{
default: true,
handler: () => _this.$emit('close'),
}
]
});
_this.test()
})
.then(() => this.reloadClients());
},
Then the test method
test: function(){
if(this.count.value > 0){
this.count.value = this.count.value - 1;
console.log(this.count.value);
let temp = this;
setTimeout(function(count){
temp.test();
}, 1000);
}
},
In the text in the modal I have a variable _this.count.value that prints out 5. Then I have a call to _this.test() to update the variable.
In test(). I console.log the results and the number does go down
However, it is not updating the _this.count.value in the text. What am I doing wrong?
Here is the modal

By default no column is showed in kendo grid and when i select column from ColumnMenu then only show data in grid for selected column?

Here is my Grid Code
#(Html.Kendo().Grid<VendorModel>()
.Name("grid").HtmlAttributes(new {style = "height:600px;" })
.EnableCustomBinding(true)
.Columns(columns =>
{
columns.Bound(p => p.VendorCode).Title("Vendor Code").Width(150).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(p => p.VendorName).Title("Vendor Name").Width(250).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(p => p.BuyerName).Title("Buyer Name").Width(150).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(p => p.CommodityCode).Title("Commodity Code").Width(200).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
columns.Bound(p => p.IncludeInReport).Title("Include In report").Width(180).HeaderHtmlAttributes(new { style = "font-weight:bold;" });
})
.ToolBar(toolbar =>
{
toolbar.Create().HtmlAttributes(new { #class = "btn btn-info" });
toolbar.Custom().Text("Download Template").Name("Vtemplate").Action("DownloadVendorBlank_Templates", "Setting").HtmlAttributes(new { Id = "Vtemplate", title = "Download Template for importing data through excel", #class = "btn btn-info" });
toolbar.Custom().Text("Import Excel").Name("ImportVendor").HtmlAttributes(new { Id = "ImportVendor", title = "Import vendor throug excel", #class = "btn btn-info" });
})
.Excel(excel => excel
.FileName("Vendors.xlsx")
.Filterable(true)
)
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Scrollable(sorting => sorting.Enabled(true))
.Resizable(m => m.Columns(true))
.ColumnMenu()
.Reorderable(m => m.Columns(true))
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Read(read => read.Action("Vendor_Read", "Setting"))
)
)
Grid have 5 column. But i want by default only 3 column to show and when i click on checkbox in ColumnMenu => Column filter then only checked column should be displayed.
Please help me.
Thanks in advance..
By default hiding/ (dont show) column in grid then you have to set .Hidden(true) at each column.
i.e- columns.Bound(c =>
c.Country).Title("Country").Width(150).Hidden(true);
And when you see check box list in Column Menu filter from there you can again select that column as view in grid.

ASP.NET WebAPI KendoUI can't update or delete data, 404 (Not Found)

I'm using ASP.NET WebApi in conjunction with KendoUI. Json is successfully displayed in the grid, so GET works. But I can't UPDATE, CREATE or DELETE data. Something wrong with routing.
#(Html.Kendo().Grid<User>()
.Name("Grid")
.EnableCustomBinding(false)
.Columns(columns =>
{
columns.Bound(u => u.UserName);
columns.Bound(u => u.FullName);
columns.Bound(u => u.Email);
columns.Bound(u => u.Address);
columns.Bound(u => u.Phone);
columns.Command(c =>
{
c.Edit();
c.Destroy();
});
})
.ToolBar(tools => tools.Create())
.Sortable()
.Pageable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(u => u.Id);
model.Field(u => u.Id).Editable(false);
})
.Events(events => events.Error("error_handler"))
.Read(read => read.Url(Url.HttpRouteUrl("DefaultApi", new{controller="users"})).Type(HttpVerbs.Get))
.Create(create => create.Url(Url.HttpRouteUrl("DefaultApi", new{controller="users"})).Type(HttpVerbs.Post))
.Update(update => update.Url(Url.HttpRouteUrl("DefaultApi", new{controller="users"})).Type(HttpVerbs.Put))
.Destroy(destroy => destroy.Url(Url.HttpRouteUrl("DefaultApi", new{controller="users"})).Type(HttpVerbs.Delete))
)
)
<script type="text/javascript">
$(function () {
var grid = $("#Grid").data("kendoGrid");
grid.dataSource.transport.options.update.url = function (data) {
return "api/users/" + data.Id;
};
grid.dataSource.transport.options.destroy.url = function (data) {
return "api/users/" + data.Id;
};
});
</script>
Chrome gives me a 404 (Not Found) error: "DELETE http://localhost:6128/Home/api/users/2 404 (Not Found) ". How to change url to "http://localhost:6128/api/users/2" without prefix Home?
Just modify your routeconfig.cs as :
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute((
name: "Default",
routeTemplate: "api/{action}/{id}", <---Change this only
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } //this will remain same as there in your config file.
);
}

Only allow to tick a record using check box in kendo ui grid

How i can prevent the user only check one record at a time when the tick checkbox. Currently the user can tick more than one record. Please advise, thank you
#(Html.Kendo().Grid<TRC.Models.ProductModel>()
.Name("Product")
.HtmlAttributes(new { #Style = "align:center; font-size:12px; width:470px; height:100%" })
.Columns(columns =>
{
columns.Template(p => p.Id).ClientTemplate("<input type='checkbox' class='chkbx'/> ").Width(25);
columns.Bound(p => p.ProductId).Width(220);
columns.Bound(p => p.ProductName).Width(220);
columns.Bound(p => p.ProductCreateDate).EditorTemplateName("Date").Format("{0:dd/MM/yyyy}").Width(120);
//columns.Command(commands => commands.Edit()).Width(100);
columns.Command(commands => commands.Destroy());
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Sortable()
.Selectable()
.Scrollable(scrollable => scrollable.Virtual(true))
.ColumnMenu(c => c.Columns(false))
.DataSource(dataSource => dataSource
.Ajax()//bind with Ajax instead server bind
.ServerOperation(true)
.Model(model =>
{
model.Id(p => p.ProductId);
model.Field(p => p.ProductCreateDate).DefaultValue(DateTime.Now);
model.Field(p => p.ProductCreateDate).Editable(false);
})
.Sort(sort => sort
.Add(x => x.ProductCreateDate).Descending()
)
.Read(read => read.Action("GetProduct", "ProductDetails").Type(HttpVerbs.Get))
.Destroy("DeleteProduct", "ProductDetails")
)
)
Let's say you have the following logic that handles the clicking. Then you can turn the other model fields to false like this:
$('#grid').on('click', '.chkbx', function () {
var checked = $(this).is(':checked');
var grid = $('#grid').data().kendoGrid;
//clearAll all other checked
if(checked){
$.each(grid.dataSource.view(),function(){
this.isAdmin = false;
})
}
var dataItem = grid.dataItem($(this).closest('tr'));
dataItem.set('IsAdmin', checked);
})

unable to login in cakephp using different table

i have problem in login form $this->Auth->login() always returns false. i am using different table name for user account. the below is my code
HgAdminscontroller.php
<?php
// app/Controller/UsersController.php
class HgAdminsController extends AppController
{
public function beforeFilter()
{
parent::beforeFilter();
//$this->Auth->allow('add', 'logout');
}
public function index() {
$this->HgAdmin->recursive = 0;
$this->set('users', $this->paginate());
}
/*
public function add() {
if ($this->request->is('post')) {
$this->HgAdmin->create();
if ($this->HgAdmin->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}*/
public function login() {
if ($this->request->is('post')) {
echo AuthComponent::password($this->data['password']);
debug($this->data);
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
public function logout() {
$this->redirect($this->Auth->logout());
}
}
?>
appController.php
App::uses('Controller', 'Controller');
/**
* Application Controller
*
* Add your application-wide methods in the class below, your controllers
* will inherit them.
*
* #package app.Controller
* #link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
*/
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
// Security::setHash('md5');
$this->Auth->userModel = 'hg_admins';
$this->Auth->loginAction = array( 'controller' => 'HgAdmins', 'action' => 'login' );
}
//...
}
HgAdmin.php //model
<?php
class HgAdmin extends AppModel {
var $name= "hg_admin";
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
)
),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
)
)
);
?>
Login view
<h2>Login Here</h2>
<?php echo $this->Session->flash('auth');
echo $this->form->create('HgAdmin');
echo $this->Form->input("username");
echo $this->Form->input("password");
echo $this->form->end(__("Login"));
?>
i have checked the database password value is same as comming from AuthComponent::password($this->data['password']); so dont know why it is fialing. if i use add function of cakephp to add user the user is added with the same password but not able to login with that.
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'writers',
'action' => 'login'
),
'loginRedirect' => array(
'controller' => 'home',
'action' => 'index'
),
'logoutRedirect' =>array (
'controller' => 'home',
'action' => 'index'
),
'authError' => 'You have to login to access this page',
'authenticate' => array(
'Form' => array(
'userModel' =>'Writer',
'fields' => array('username' => 'email')
)
),
'scope' =>array('User.status' => '1'),
'authorize' => array('Controller')
),
'Session',
);
You have to use the name of the Model on which you want to apply authentication i.e i ahve used Writer for my table writers in db.Check changing that!
#huzefam answer is correct, but I just want to add in case anyone who use Bcrypt authentication. Here I use Accounts table. Should add something like this. Hope this help
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'accounts',
'action' => 'admin_login'
),
'loginRedirect' => array(
'controller' => 'orders',
'action' => 'admin_index'
),
'logoutRedirect' =>array (
'controller' => 'accounts',
'action' => 'admin_login'
),
'authError' => 'You have to login to access this page!',
'authenticate' => array(
'Blowfish' => array(
'userModel' =>'Account',
'fields' => array('password' => 'password')
)
),
'authorize' => array('Controller')
),
'RequestHandler',
'Paginator',
'Session'
);