ExtJS DatePicker Allow Dates Only by Ajax - ajax

I have an interesting task that I am trying to do. I want to display a datepicker field on ExtJS allow certain days to be picked only though so for example:
09/12/2018
09/11/2018
09/10/2018
09/07/2018
09/06/2018
As you see, I am not allowing the user to select 8th or 9th. I can pull these dates using Ajax but I am not sure how to connect them to the datepicker field so it will only allow dates that it picks up using Ajax.
So far I have below calendar but minDate and maxDate only won't do the trick for me...
title: 'Choose a future date:',
width: 330,
bodyPadding: 10,
items: [{
xtype: 'datepicker',
maxDate: new Date(),
handler: function (picker, date) {
// do something with the selected date
}
}]
https://docs.sencha.com/extjs/6.2.1/classic/Ext.picker.Date.html

Assuming you know which dates to be disabled. It can be achieved by different ways as follows:
1] You can use 'disabledDates' config property which may have array of dates to be disabled. You can use it as follows:
title: 'Choose a future date:',
width: 330,
bodyPadding: 10,
items: [{
xtype: 'datepicker',
maxDate: new Date(),
disabledDates: ['09/08', '09/09'],
handler: function (picker, date) {
// do something with the selected date
}
}]
Or
2] You can use 'disabledDatesRE' config property which may have RegExp with dates to be disabled. You can use it as follows:
title: 'Choose a future date:',
width: 330,
bodyPadding: 10,
items: [{
xtype: 'datepicker',
maxDate: new Date(),
disabledDatesRE: new RegExp("(?:09/08/2018|09/09/2018)"),
handler: function (picker, date) {
// do something with the selected date
}
}]
You can use your own logic by using above code as per the requirement.

minDate starts from 42 days before today
maxDate ends at 7 days before today
disabledDays disables sundays and mondays
listener in place so when you select a date it will log it to the console.
items: [{
title: 'Please select a date:',
width: 330,
bodyPadding: 10,
items: [{
xtype: 'datepicker',
disabledDays: [0,6],
minDate: Ext.Date.add(new Date(), Ext.Date.DAY, -42),
maxDate: Ext.Date.add(new Date(), Ext.Date.DAY, -7),
listeners: {
select: function (picker, date) {
console.log(date);
}
}

Related

FullCalendar change color new event

I use fullcalendar and I need to now how to change the color of the new event, to differentiate it from the loaded events into the database. The person who puts the new event, has to difference from others by color.
The calendar uses everyone, no user control and events are stored in a database.
Your question leaves some questions of its own. Do you expect for the color of the new event to be rendered later? or is the color completely disposable and used only for differentiating between a new and old event?
Given the questions though - remember that you can set color is MANY different ways. You can set a static color for all items loaded from the database in your ajax call:
events: {
url: 'php/get-events.php',
error: function() {
$('#ajax-warning').show();
},
color: "yellow"
},
That will set the default color for all the events loaded from JSON.
In the json data itself, you can set the backgroundColor attribute to change the color of an individual item, e.g
{
"id": "999",
"title": "Repeating Event",
"start": "2016-05-09T16:00:00-05:00",
"backgroundColor": "purple"
},
You can set the event color in a form (if that is how you allow a user to create an event)
If you have a set of static events that can be added you can cycle through a list of colors and provide each one in the list with a different background.
--
If this doesn't answer your question, try poviding more information on what you have currently and what you'd like to accomplish.
/* initialize the calendar
-----------------------------------------------------------------*/
$('#calendar').fullCalendar({
events: JSON.parse(json_events),
height:447,
utc: true,
allDaySlot:false,
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaWeek,agendaDay'
},
eventConstraint: {
start: moment().format('YYYY-MM-DD'),
end: '2100-01-01'
},
firstDay: 1,
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miercoles',
'Jueves', 'Viernes', 'Sábado'],
dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'],
minTime:'09:00:00',
maxTime:'13:30:00',
buttonText: {
today: 'hoy',
month: 'mes',
week: 'semana',
day: 'dia'
},
eventStartEditable: false,
eventTextColor: '#AE413F',
defaultView: 'agendaWeek',
hiddenDays: [6, 0],
editable: true,
droppable:true,
eventDurationEditable:false,
slotDuration: '00:30:00',
defaultEventMinutes: 30,
defaultTimedEventDuration:'00:30:00',
forceEventDuration:true,
eventReceive: function(event){
var title = prompt('Nombre y Apellidos:');
var start = event.start.format("YYYY-MM-DD[T]HH:mm:SS");
var end = event.end.format("YYYY-MM-DD[T]HH:mm:SS");
var antena = 'ANTENA1';
var ssid = 'E18D93D0-B4B2-4802-8D04-CD2154B88A18';
if(title!=null){
$.ajax({
url: 'process.php',
data: 'type=new&title='+title+'&start='+start+'&end='+end+'&antena='+antena+'&SSID='+ssid+'&zone='+zone,
type: 'POST',
dataType: 'json',
success: function(response){
event.title = title;
$('#calendar').fullCalendar('updateEvent',event);
alert("Añadido: Atención NO marcar la casilla inferior si quiere guardar correctamente los datos");
},
error: function(e){
console.log(e.responseText);
if(error='true'){
alert('CITA YA ASIGNADA: Atención NO marcar la casilla inferior si quiere un funcionamiento correcto');
}//location.reload();
}
});}else{
location.reload();}
$('#cafireflendar').fullCalendar('updateEvent',event);
console.log(event);
//location.reload();
},

How to add holidays to kendo scheduler?

Is anybody know how to add holidays to kendo scheduler?
I mean in a holiday user shouldn't be able to add any events.
I suggest to add a custom class in my example i created class k-holiday or maybe utilize kendo class k-non-workhour and on dataBound function add this :
dataBound: function () {
var scheduler = this;
//get scheduler view
var schedulerView = this.view();
//loop through all slot/event/tile
schedulerView.table.find("td[role=gridcell]").each(function () {
//find start date
var slot = scheduler.slotByElement($(this));
var CONSTANT_HOLIDAY_DATE = new Date("2013/6/11");
CONSTANT_HOLIDAY_DATE.setHours(0, 0, 0, 0);
slot.startDate.setHours(0, 0, 0, 0);
//compare date curent event with holiday
if (slot.startDate.getTime() == CONSTANT_HOLIDAY_DATE.getTime()) {
$(this).addClass("k-holiday");
} else {
$(this).removeClass("k-holiday");
}
});
},
i created a holiday on this particular Date new Date("2013/6/11") where later on all event/slot on this date will have k-holiday class, then you want to add this to your edit function :
edit: function (e) {
var uid = e.container.attr('data-uid');
var element = e.sender.element.find('div.k-event[data-uid="' + uid + '"]');
var slot =$("#scheduler").data("kendoScheduler").slotByElement(element);
if($(slot.element).hasClass("k-holiday")){
e.preventDefault();
}
}
above condition will filter event that is double clicked / edited , where it will prevent the event that has k-holiday to open the popup. Please refer to this kendo dojo
Note : on that example you will notice that on tuesday 6/11 you can't trigger the edit/add new event, but on the day other than that you still can
You can use the all day event template to create holidays.
The message can be set through messages.allDay like this:
<div id="scheduler"></div>
<script>
$("#scheduler").kendoScheduler({
date: new Date("2013/6/6"),
messages: {
allDay: "Holiday"
},
dataSource: [
{
id: 1,
start: new Date("2013/6/6 08:00 AM"),
end: new Date("2013/6/6 09:00 AM"),
title: "Interview"
}
]
});
</script>
You can check this executable example with holiday details.
Edit
BorHunter: but in your example I can add new events into scheduler, but I don't need it. I mean user shoudn't be able to add event on that particular holiday/date.
Then you just disable that option by using editable like this example that has:
editable: false,
Or this one:
editable: {
create: false,
update: false,
resize: false,
move: false,
destroy: false
},

ExtJS4 dataView - Select node id

I have an ExtJS 4 dataView and i would like to catch the id of a selected node.
It is the first time that i'm using the dataView, then, there are some troubles.
The store is loaded correctly and i see the datas into the view very well. The problem which i'm having, concern the "classic" actions of update and delete, particularly getting the id of a selected item.
For example into a grid i click, then select a record and through a button's pressing i open a window (or other actions) with a loaded form (by sending in AJAX to the store, the id of the selected row) and i update the datas.
I'm not still able to do it with the ExtJS 4 dataView.
Below my dataView:
dataView_player = Ext.create('Ext.Panel', {
id: 'images-view',
frame: true,
collapsible: false,
autoWidth: true,
title: 'Giocatori (0 items selected)',
items: [ Ext.create('Ext.view.View', {
id:'players-view',
store: store_player,
multiSelect: true,
height: 310,
trackOver: true,
overItemCls: 'x-item-over',
itemSelector: 'div.thumb-wrap',
emptyText: 'Nessun giocatore visualizzato',
tpl: [
'<tpl for=".">',
'<div class="thumb-wrap" id="{id}-{name}">',
'<div class="thumb">',
'<img src="/img/players/{picture}" title="{name} {surname}" alt="{name} {surname}" style="">',
'</div>',
'<span class="" style="height:30px;">{general_description}{name} {surname}</span>',
'</div>',
'</tpl>',
'<div class="x-clear"></div>'
],
plugins: [
Ext.create('Ext.ux.DataView.DragSelector', {}),
Ext.create('Ext.ux.DataView.LabelEditor', {dataIndex: 'name'})
],
prepareData: function(data) {
Ext.apply(data, {
name: data.name,
surname: data.surname,
general_description: Ext.util.Format.ellipsis(data.general_description, 15)
});
return data;
},
listeners: {
'selectionchange': function(record, item, index, e) {
var node = this.getNode(record); //this.getNode(record);
console.log(node.get('id'));
}
}
}) ],
dockedItems: [{
xtype: 'toolbar',
items: [{
iconCls: 'delete',
text: 'Cancella Selezionati',
scale: 'medium',
tooltip: 'Per <b>cancellare</b> i giocatori selezionati',
tooltipType: 'qtip',
id: 'delete-player',
disabled: true,
handler: delete_news
}, '-', {
iconCls: 'edit',
text: 'Aggiorna Selezionata',
scale: 'medium',
tooltip: 'Per <b>aggiornare</b> un giocatore selezionato',
tooltipType: 'qtip',
disabled: false,
id: 'update-player',
handler: function(nodes) {
var l = nodes.get('id');
console.log(l);
}
}
}
]
}]
});
Of course, this is a wrong example (because the listeners don't work) but it's just to make an idea.
There are two main things what i would like to do:
1) Catch the id (and other store's fields) of the selected item on the action "selectionchange". Obviously, now it doesn't work because of this: node.get('id'). Of course it's a wrong syntax but make up the idea of my will.
2) Catch the id of the selected item on the handler event of the "update-player" button. As above, the issue is the nodes.get('id'). Further trouble, is how to pass the selected item's features. in handler: function(nodes) { the nodes variable does not assume any value and i don't know how to pass the params from the dataview to the handler function.
I hope that somebody will able to help me.
According to the docs the selectionchange event provides the selection model as well as the array of selected records, so you are probably assuming the wrong parameters in your listener.
Without doing further testing, I think it should be something like this:
listeners: {
'selectionchange': function(selModel, selection, eOpts) {
var node = selection[0];
console.log(node.get('id'));
}
}
Note that you're using multiSelect: true, so it could be more than one record in the selection array.
Answer for second part of the question:
In button handler, you need to get selection model of the view and from it get information about selected records:
handler: function(nodes) {
// find view component
var view = dataView_player.down('dataview');
// get all selected records
var records = view.getSelectionModel().getSelection();
// process selected records
for(var i = 0; i < records.length; i++) {
console.log(records[i].getId());
}
}

How to override the value() from a kendoDatePicker when this the DatePicker is used in Grid Filter menu customizatio

Currently, the grid is defined as this:
$('#gridManagers').kendoGrid({
dataSource: dataSourceManagers,
columns: [
{ field: 'First', title: 'FirstName' },
{
field: 'HireDate', format: "{0:dd-MM-yyyy}", filterable: {
ui: filterDate
}
},
],
filterable: true,
sortable: {
mode: 'multiple'
},
pageable: true
});
function filterDate(element) {
element.kendoDatePicker({
format: 'MM-dd-yyyy',
close: function (e) {
console.log("_value:"+this._value);
this._value = kendo.toString(this.value(), "MM-dd-yyyy");
console.log("this.value():" + this.value());
}
});
When I select a date from the DatePicker, the console logging shows this:
LOG: _value:Sat Nov 30 00:00:00 UTC+0100 2013
LOG: _current:11-14-2013
LOG: this.value():11-30-2013
The reason I do the conversion from 'Sat Nov 30 00:00:00 UTC+0100 2013' to '11-30-2013' is because the format is not recognized correctly on the server.
What I don't understand how the value from the DatePicker is retrieved by the grid and used to define the filter ?
Do not mess the value of the DatePicker and the Grid when converting it to string, it should be a Date.
If you want to send the value in different format then use the parameterMap function to transform it the way you need it on the server.

MVC3 JQGrid Set colmodel dynamically from controller

I've seen tons of examples about setting the colmodel in the view but I haven't been able to see the controller code!
I am trying to do it but the setup keep being wrong.
I am trying to reach this column formation:
colModel:
[
{ name: 'ID', index: 'ID', hidden: true },
{ name: 'Votes', index: 'Votes', width: 100, align: 'left' },
{ name: 'Question', index: 'Question', width: 300, align: 'left' },
{ name: 'my_clickable_checkbox', index: 'my_clickable_checkbox',
sortable: true,
formatter: chkFmatter, formatoptions: { disabled: false }, editable: true,
edittype: "checkbox"
}
],
This is my trial in the controller:
return Json(
new { colNames = new[] { "ID2", "Votes2", "Question2", "checkbox" },
colModel = new[] {
new { name = "ID", index = "ID", width = 0, formatter="",
edittype="", hidden = true },
new { name = "Votes", index = "Votes", width = 100, formatter="",
edittype="", hidden = false },
new { name = "Question", index = "Question", width = 300, formatter="",
edittype="", hidden = false },
new { name = "checkbox", index = "my_clickable_checkbox", width = 100,
formatter="chkFmatter", edittype="checkbox", hidden = false }
}
}, JsonRequestBehavior.AllowGet);
The creation of this array in the controller is forcing me to have the same number of properties in all rows. For example, I only need the ID to be hidden, but it forces me to supply a hidden property to all other columns.
Second problem, I need to call js function chkFmatter for the fourth column.
how can I reach that colModel formation in controller??
thanks much.
You might be interested in looking at jqGrid Importing and exporting functionality. It allows you to import or export the entire jqGrid configuration to or from another file format.
You can read this blog post:
jqGrid and ASP.NET MVC - Configuration Import/Export
to get the general idea on how to use those functionalities with ASP.NET MVC, but it`s a little bit out of date if it comes to ASP.NET MVC stuff (it is based on ASP.NET MVC 1).
You can also take a look at this jqGrid sample project:
jqGrid in ASP.NET MVC 3 and Razor
which (among other things) contains sample for configuration import/export.
Most imported thing to remember here is that you still need to set any jqGrid events/callbacks or call any additional methods like 'setFrozenColumns' after configuration import.

Resources