Changing the color of date wheel in Mobiscroll's date & time scroller based on a condition - mobiscroll

In my organization, each day has one of four shifts (A - D) working, and shifts are associated with colors (red, blue, green, yellow).
I use jQuery UI's datepicker in the desktop view of my ASP.NET MVC app, and I can use the beforeShowDay option to change the background color of days on the calendar so that users can see at a glance what shift is working each day.
$(".datePicker").datepicker('option', 'beforeShowDay', colorDays);
function colorDays(date) {
var today = new Date();
// set object to midnight, for comparing against passed in date
today.setHours(0,0,0,0);
var shift = getShift(date);
var cssClass = "";
// don't style unpickable dates in the past
if (date >= today) {
cssClass = "datepicker-shift-" + shift.toLowerCase();
}
return new Array(true, cssClass, shift + " Shift");
}
Is it possible to do the same with Mobiscroll, such that the Day wheel background would change color based on the shift that was working that day?
Alternatively, if that's not possible, changing the Day Label to include the name of the shift (A - D) would be OK.
I tried adding onChange to my mobiscroll instance:
$(".datePicker").mobiscroll().date({
theme: 'jqm',
onChange: function (valueText, inst) {
var date = new Date(valueText);
var shift = getShift(date);
inst.init({ dayText: "Day - " + shift });
}
});
The onChange event fires, but the mobiscroll widget closes immediately. If you re-open, the dayText label has correctly changed. I can't figure out how to change the label while keeping the widget open.

While I didn't end up changing wheel color, I found a way to change the label some time ago, and wanted to share for anyone that may want to do something similar. When instantiating mobiscroll, I use the following code:
$(".datePicker").mobiscroll().date({
theme: 'jqm',
display: 'bottom',
onChange: function(valueText, inst) {
var selectedDate = new Date(valueText);
$('.dwv.ui-header').html(valueText + " - " + getShift(selectedDate) + " shift");
},
onShow: function (html, valueText, inst) {
var selectedDate = new Date(valueText);
$('.dwv.ui-header').html(valueText + " - " + getShift(selectedDate) + " shift");
}
});
That gives me a label for the date/datetime picker that looks like "04/09/2014 - B shift", that updates as the selected date changes.

Related

Where does a Table cell get styled when using focusCellOnPointerMove?

I have a qx.ui.table.Table that becomes hard to read when a row takes focus. I'm using qx.ui.table.cellrenderer.Date as a base class to override a cell's background color though it doesn't appear this method gets called when
focusCellOnPointerMove : true fires events.
So, where is the table getting styled at when a row takes focus?
Here is my override:
// Overridden
_getCellStyle : function(cellInfo)
{
var diff = 5; // Example
if (diff < 60)
{
var color = '#8cff5e';
return this.base(arguments, cellInfo) + "background-color:" + color + ";";
} else if (diff < 60 * 5)
{
var color = '#ffff00';
return this.base(arguments, cellInfo) + "background-color:" + color + ";";
} else
{
return cellInfo.style || "";
}
},
Using suggestion by scro34:
If you just want to change a table row's background color when it's pointed at you can use qooxdoo's theming capabilities and override the color declaration which comes with the theme you've applied to your application.
The table widget uses two color keys to control the background color when the pointer is hovering over a row: table-row-background-focused (unselected row) and table-row-background-focused-selected (selected row).
To override the predefined values, open Color.js which is located in the "theme" folder of your application and add two entries to the "colors" section of the file, e.g.:
qx.Theme.define("myApp.theme.Color",
{
extend : qx.theme.indigo.Color,
colors :
{
"table-row-background-focused" : "#8cff5e",
"table-row-background-focused-selected" : "#ffff00"
}
});
More information about theming in qooxdoo: http://www.qooxdoo.org/current/pages/desktop/ui_theming.html
Tutorial on table styling: http://www.qooxdoo.org/5.0.1/pages/desktop/ui_table_styling.html

CQ/AEM extjs get selection dropdown box text, and get page path

Say I have a component with dialog drop to parsys on a content page /content/phonegap/ss/en_gb/login/home/test1/jcr:content/par/productimage
now inside the dialog i have something like
I wish to get $PATH append to URL and send selected device e.g the text 'Device ID:HTC_10_GOLD', to servlet in this dialog listener extjs:
<deviceAndColour
jcr:primaryType="cq:Widget"
allowBlank="{Boolean}false"
fieldLabel="Device and Colour"
name="./deviceAndColour"
options="/bin/reference/data/device.devices.json$PATH"
type="select"
xtype="selection">
<listeners
jcr:primaryType="nt:unstructured"
selectionchanged="function(pathfield) {
var selected = this.findParentByType('form').find('name', './deviceAndColour')[0].getText();
console.log( this.findParentByType('form').find('name', './deviceAndColour')[0].getText());
$.getJSON('/bin/reference/data/device/availablecolour.availablecolour.json$PATH?selectedDevice=' + selected + '&colour=red', function(jsonData){
selectBox.setOptions(jsonData);
});
}" />
</deviceAndColour>
So bascially, the console.log( this.findParentByType('form').find('name', './deviceAndColour')[0].getText()); is not working as I expected, neither the $PATH inside the dialog listener js, it does not retrieve the path at all.
Apart from above attempt, I know var selected = this.findParentByType('form').find('name', './deviceAndColour')[0].getValue(); this will get the value asscociated with the select correctly, but I do not need value, I just wish to getText(), and get the current $PATH in extjs.
another questions, you may noticed $.getJSON('/bin/reference/data/device/availablecolour.availablecolour.json$PATH?selectedDevice=' + selected + '&colour=red'
how do I skip the & in this listner, as if i use & directly, project won't even build. there must be someway to skip & and let extjs treat as part of the string to send request
Anyone expereinced this before? please suggest with code example.
Thanks
Getting the text of the option selected:
function(field,value){
for(var i = 0; i < field.options.length; i++) {
if(field.options[i].value === value) {
console.log('Selected: ' + field.options[i].text);
break;
}
}
}
Getting the path to the resource being edited:
function(field,value){
console.log("Resource:" + field.findParentByType("dialog").path);
}
Documentation: https://docs.adobe.com/docs/en/cq/5-6/widgets-api/index.html?class=CQ.form.Selection
UPDATE
Please try the following code adapted to your scenario (I also refactored the code to make use of params when providing query parameters. There is no reason why this shouldn't work.
function(field, value) {
var selected = '';
var path = field.findParentByType("dialog").path;
// get text of option selected
for(var i = 0; i < field.options.length; i++) {
if(field.options[i].value === value) {
selected = field.options[i].text;
break;
}
}
var params = {
selectedDevice: selected,
colour: 'red'
}
$.getJSON('/bin/reference/data/device/availablecolour.availablecolour.json'+path, params, function(jsonData){
// FIXME: how are you getting the "selectBox" reference?
selectBox.setOptions(jsonData);
});
}

Bootstrap Datetime Picker in Backgrid Cell Not Rendering Correctly

I'm trying to use this Bootstrap Datetime Picker (version 4.17.37) inside a Backgrid cell, but I'm having a problem with the way the widget is rendering. The widget appears as a thin popup right below the cell, but seems to have no content inside. However, if you log the widget's inner html to the console, the content is there. It seems to me that there is something unusual going on inside the place function of the datetime picker, shown here.
This is my code for the custom Backgrid cell and its editor.
// Editor for the datetime picker cell.
var DatetimePickerCellEditor = Backgrid.InputCellEditor.extend({
events: {},
initialize: function() {
Backgrid.InputCellEditor.prototype.initialize.apply(this, arguments);
var input = this;
var timezone = 'America/Lima',
format = 'YYYY-MM-DD HH:mm';
this.$el.datetimepicker({
format: format,
timeZone: timezone
}).on('dp.show', function(event) {
event.preventDefault();
var column = input.column.get('name'),
date = input.model.get(column);
input.$el.data("DateTimePicker").date(date);
}).on('dp.hide', function(event) {
event.preventDefault();
var dateObj = event.date,
dateLocal = null;
if (dateObj) {
var dateString = dateObj.format(format);
dateLocal = moment.tz(dateString, timezone);
}
var command = new Backgrid.Command({}),
column = input.column.get("name");
// Save date in model as string in local time.
input.model.set(column, dateLocal.format());
input.model.trigger("backgrid:edited",
input.model,
input.column,
command);
command = input = null;
}).on('dp.error', function(error) {
console.log(error)
});
}
});
// Cell to display the datetime picker.
var DatetimePickerCell = Backgrid.Cell.extend({
editor: DatetimePickerCellEditor
});
This produces the following result:
Upon inspection, the element that the datetime picker was using as a parent is an ancestor <div class="col-lg-12 col-md-12">. I then tried to solve the problem by giving the cell a { position: relative } CSS property. That indeed made the datetime picker use the cell as a parent, but produced the following result visually:
You can see that the picker appears to be below the cell, but is not visible.
Playing around with other properties, such as widgetParent and widgetPositioning gave similar results.
I had same problem.
(I know that this is an old question, but I use backbone/backgrid today. I have a lot of additional issues with angular, vue or react on data grids, I find that this combo is the best, and simplest, until these days).
well, You only must add this after backbone/backgrid css to your th, td containers.
.backgrid th,
.backgrid td {
display: table-cell;
position: relative;
overflow: visible;
}
I use it in an backbone/backgrid project and it works perfect.
It's incredible, there is and display: none style overrrided, but, for any reason it continues makeing this fail.
I hope this could help some one else.
one capture:

AngularJS data binding not working with ui-date component

I'm using the ui-date component as a dropdown datepicker in an AngularJS project. The problem I'm having is that the data binding between the model and the datepicker is only one-way, not two-way as I expect it to be.
My HTML has a Prev and Next button to allow the user to adjust the date backwards and fowards one day at a time. Or they can click in the date box itself to show the dropdown datepicker and specify any date they want.
Plunker here.
HTML:
ThisDate: {{ ThisDate }}
<p>
<button ng-click="PrevDay()">< Prev</button>
<button ng-click="NextDay()">Next ></button>
<p>
Set Date: <input ui-date ng-model="ThisDate" id="ThisDate">
Javascript:
var app = angular.module('app', ['ui.date']);
app.controller('MyController', function($scope) {
$scope.ThisDate = new Date();
$scope.PrevDay = function() {
$scope.ThisDate = DateOffset($scope.ThisDate, -1);
};
$scope.NextDay = function() {
$scope.ThisDate = DateOffset($scope.ThisDate, 1);
};
function DateOffset(ThisDate, NumDays) {
var d = ThisDate;
d.setDate(d.getDate() + NumDays);
return d
}
});
Problem:
If you change the date using the dropdown datepicker, the date box will change and {{ ThisDate }} will update properly. But if you click the Prev or Next buttons, only the bound {{ ThisDate }} will change... not the date box which is bound to "ThisDate" in the model.
Steps to Reproduce:
Run the Plunker. Notice that if you click in the date box, you can change the date from the dropdown and the date box will change accordingly AND the text area at the top which is bound to ThisDate will also change. Now click the Next or Prev button. Notice that ONLY the bound ThisDate text will change, NOT the date box. The date box should also change since it is bound to ThisDate.
Any ideas on why the ui-date datepicker isn't registering the changes in the model to ThisDate?
Plunker here.
It's not seeing the date object change. If you assign a new date object it works:
function DateOffset(ThisDate, NumDays) {
var d = new Date();
d.setTime(ThisDate.getTime() + (NumDays * 1000 * 60 * 60 * 24));
return d
}

problem in using appendchild in IE7

Find below the js function that I'm using to add a new date field & 'Select Venue' link to an existing div with id 'coursedates' . Problem is this works fine in FF 3 & IE 8.
It doesnt work in IE7. If I alert the count(length) of 'dts' it always says 1, though it IE developer toolbar shows that the new date div is added to coursedates.
I tried using innerHtml instead of appendchild, but in that case, the listeners of the old coursedt div's elements like selven+new_course_dt_index are lost.
Is there a solution for this.
Thanks in advance.
addnewcoursedate: function () {
var dts = yud.getElementsByClassName('coursedt', 'div', 'coursedates');
var new_course_dt_index = parseInt(dts[parseInt(dts.length, 10)-1].id.split('coursedt')[1],10)+1;
var newdt = document.createElement('div');
newdt.setAttribute('class','coursedt');
newdt.setAttribute('id','coursedt'+new_course_dt_index);
var coursedt_htm =
"<div class='clearfix flt_left'><label for='coursestartdt"+new_course_dt_index+"'>Start Date & Time </label><a href='javascript:NewCssCal(\"coursestartdt"+new_course_dt_index+"\",\"ddmmyyyy\",\"arrow\",true,12,false);'><img src='calbtn.gif' width='16' height='16' border='0' alt='Pick a start date & time'></a><br/>"+
"<input type='text' id='coursestartdt"+new_course_dt_index+"' name='coursestartdt"+new_course_dt_index+"' value=''> </div>"+
"<div class='flt_left'><a href='#' class='selven' id='selven"+new_course_dt_index+"'>Select Venues</a><br/><input type='hidden' name='venues"+new_course_dt_index+"' id='venues"+new_course_dt_index+"'><div class='selvenue' id='venueshw"+new_course_dt_index+"'> </div></div>"+
"<div class='flt_rght clr_lft'><a href='javascript:YAHOO.modname.event_js.removecoursedate(\""+new_course_dt_index+"\");'><img title=\"Remove date\" src=\"clear_field.gif\" /></a></div>";
newdt.innerHTML = coursedt_htm;
var crsdts = yud.get('coursedates');
crsdts.appendChild(newdt);
var newbr = document.createElement('br');
newbr.setAttribute('class','lstclr');
newbr.setAttribute('id','lstclr'+new_course_dt_index);
crsdts.appendChild(newbr);
if ( YAHOO.modname.event_js.ven_dlgs[new_course_dt_index] == null ) {
YAHOO.modname.event_js.ven_dlgs[new_course_dt_index] = _createVenueDialog(new_course_dt_index);
}
},
note: yud : YAHOO.util.Dom
Found the problem.
For some reason, IE7 was not recognising the class 'coursedt' added to the new div.
newdt.setAttribute('class','coursedt')
But it worked when I changed the code to the following :
var attr = document.createAttribute('class');
attr.value = 'coursedt';
newdt.setAttributeNode(attr);
This works for FF & IE 6,7,8.
I also found that this problem can happen when a function on one window tries to call appendChild on an element in another window, this means that both elements have to be on the same document (which is quite obvious), but at least IE should say something about this.

Resources