I have an alloy ui timepicker in my form. I want to only display Hours in the Input Fields. But the problem is Alloy UI divides Timeslots in 30 minutes each. So thats my input fields displays same hour 2 times
A.use('aui-timepicker', function(A) {
new A.TimePicker({
trigger : 'input#<portlet:namespace/>endTime',
mask : '%H',
popover : {
zIndex : 1011
},
on : {
selectionChange : function(event) {
console.log(event.newSelection)
}
}
});
});
With Minutes & Time
00:00
00:30
01:00
01:30
Only Hours
00
00
01
01
Unfortunately, the AlloyUI TimePicker API docs do not document any feature to change the step between time elements besides the values attribute. The solution is to set the values attribute to the values you want. One simple way to do this is to create an array that has the values you want:
var values = [];
for (var i = 0; i < 24; i++) {
values.push(i.toString());
}
Then just set the values attribute to the created array:
YUI().use('aui-timepicker', function(Y) {
new Y.TimePicker({
/* Your code here... */
mask: '%H',
values: values
});
});
Here's a runnable example:
var values = [];
for (var i = 0; i < 24; i++) {
values.push(i.toString());
}
YUI().use('aui-timepicker', function(Y) {
new Y.TimePicker({
mask: '%H',
trigger: '#input',
values: values,
popover: {
zIndex: 1
}
});
});
<script src="http://cdn.alloyui.com/2.0.0/aui/aui-min.js"></script>
<link href="http://cdn.alloyui.com/2.0.0/aui-css/css/bootstrap.min.css" rel="stylesheet"></link>
<input id="input" />
Related
I need your help with the import of a set from an excel spreadsheet to CPLEX.
The set looks like this:
enter image description here
As you see there are two values for j = 2 and j = 11 each.
The goal is to import it as {int} to CPLEX so that it has the following structure:
enter image description here
I would be very thankful, if anybody could help me out with this.
Sincerely
you could rely on javascript within OPL
See https://github.com/AlexFleischerParis/oplexcel/blob/main/readsetincells.mod
{int} x=...;
{int} y=...;
{string} figures={"0","1","2","3","4","5","6","7","8","9"};
string cells[x][y]=...;
{int} values[x][y];
execute // parsing
{
for(var i in x) for(var j in y)
{
var s=cells[i][j];
var buffer="";
for(var k=0;k<s.length;k++)
{
if (figures.contains(s.charAt(k))) buffer=buffer+s.charAt(k);
else
{
if (buffer!="")
{
var value=Opl.intValue(buffer);
values[i][j].add(value);
buffer="";
}
}
}
}
}
execute display
{
for(var i in x) for(var j in y) if (Opl.card(values[i][j])!=0) writeln(i,",",j," => ",values[i][j]);
}
/*
which gives
2,12 => {4 5}
10,40 => {6}
*/
I'm trying to load multiple sliders using noUISlider and it's not working. When using the first slider, the values changes for the second and third. How do I go about refactoring the code for one slider so I can easily add additional sliders with different options?
Here's a fiddle and below is my code.
// noUISlider
var actSlider = document.getElementById('act-slider');
noUiSlider.create(actSlider, {
start: [0, 50],
connect: false,
step: 1,
range: {
'min': 0,
'max': 50
},
format: {
to: function (value) {
return value + '';
},
from: function (value) {
return value.replace('', '');
}
}
});
// Connect bar
var connectBar = document.createElement('div'),
connectBase = actSlider.getElementsByClassName('noUi-base')[0],
connectHandles = actSlider.getElementsByClassName('noUi-origin');
// Give the bar a class for styling and add it to the slider.
connectBar.className += 'connect';
connectBase.appendChild(connectBar);
actSlider.noUiSlider.on('update', function (values, handle) {
// Pick left for the first handle, right for the second.
var side = handle ? 'right' : 'left',
// Get the handle position and trim the '%' sign.
offset = (connectHandles[handle].style.left).slice(0, -1);
// Right offset is 100% - left offset
if (handle === 1) {
offset = 100 - offset;
}
connectBar.style[side] = offset + '%';
});
// Value tooltips
var tipHandles = actSlider.getElementsByClassName('noUi-handle'),
tooltips = [];
// Add divs to the slider handles.
for (var i = 0; i < tipHandles.length; i++) {
tooltips[i] = document.createElement('div');
tooltips[i].className += 'value-tooltip';
tipHandles[i].appendChild(tooltips[i]);
}
// When the slider changes, write the value to the tooltips.
actSlider.noUiSlider.on('update', function (values, handle) {
tooltips[handle].innerHTML = values[handle];
});
You can wrap your slider creation in a function, and call it for all elements where you want a slider created.
noUiSlider also supports tooltips (from version 8.1.0) and connect options, so you don't have to implement those yourself if you don't want to make very specific changes.
As for different options for every slider, there are several ways to do this. I've added an example using data attributes for the step option.
The following code initializes a slider on all elements with a .slider class.
function data ( element, key ) {
return element.getAttribute('data-' + key);
}
function createSlider ( slider ) {
noUiSlider.create(slider, {
start: [0, 50],
connect: false,
step: Number(data(slider, 'step')) || 1,
range: {
'min': 0,
'max': 50
},
tooltips: true,
connect: true,
format: {
to: function (value) {
return value + '';
},
from: function (value) {
return value.replace('', '');
}
}
});
}
Array.prototype.forEach.call(document.querySelectorAll('.slider'), createSlider);
Here's a jsFiddle demonstrating this code.
I have a primary Entity (Self-Insurance) and a secondary entity (Compensation). They have a 1:N relationship. So in my main form of Self Insurance I have a sub-grid with the name 'Worker_Compensation' where i am adding up some payroll values.
I have 2 questions. . .
1: The thing I want is that when I add some values in the sub-grid. I need to show a sum of all payrolls in the text below of my main form named as 'TOTAL'.
2: Where should i call this java script(On which event) Onload or Onsave of form ? or else where because I can seems to locate the events on Subgrid.
I am using a java script for this purpose.
enter code here
function setupGridRefresh() {
var targetgrid = document.getElementById("Worker_Compensation");
// If already loaded
if (targetgrid.readyState == 'complete') {
targetgrid.attachEvent("onrefresh", subGridOnload);
}
else {
targetgrid.onreadystatechange = function applyRefreshEvent() {
var targetgrid = document.getElementById("Worker_Compensation");
if (targetgrid.readyState == 'complete') {
targetgrid.attachEvent("onrefresh", subGridOnload);
}
}
}
subGridOnload();
}
function subGridOnload() {
//debugger;
var grid = Xrm.Page.ui.controls.get('Worker_Compensation')._control;
var sum = 0.00;
if (grid.get_innerControl() == null) {
setTimeout(subGridOnload, 1000);
return;
}
else if (grid.get_innerControl()._element.innerText.search("Loading") != -1) {
setTimeout(subGridOnload, 1000);
return;
}
var ids = grid.get_innerControl().get_allRecordIds();
var cellValue;
for (i = 0; i < ids.length; i++) {
if (grid.get_innerControl().getCellValue('new_estannualpayroll', ids[i]) != "") {
cellValue = grid.get_innerControl().getCellValue('new_estannualpayroll', ids[i]);
cellValue = cellValue.substring(2);
cellValue = parseFloat(cellValue);
sum = sum + cellValue;
}
}
var currentSum = Xrm.Page.getAttribute('new_payrolltotal').getValue();
if (sum > 0 || (currentSum != sum && currentSum != null)) {
Xrm.Page.getAttribute('new_payrolltotal').setValue(sum);
}
}
This piece of code is not working. after i add values in the grid my textbox remains empty!
Thanks in advance
If you are upgrading to Microsoft CRM 2015 soon or are already on Microsoft CRM 2015, you can do this without any JavaScript by simply creating a new calculated rollup field and placing that underneath the sub grid, or wherever you wish to place it on the form. Note that this field is calculated ever 12 hours, but if you wish to, it could be calculated on form load via JavaScript. You can see details about that at https://msdn.microsoft.com/en-us/library/dn817863.aspx -"Calculated and Rollup Attributes". The TechNet document, "Define rollup fields" at https://technet.microsoft.com/library/dn832162.aspx has some good examples, scenarios, and discussion about the limitations of the rollup fields.
You can do it with subgrid's onRefresh. This is also unsupportted way but it works. You must add this functions to your javascript
function AddEventToGridRefresh(gridName, functionToCall) {
// retrieve the subgrid
var grid = document.getElementById(gridName);
// if the subgrid still not available we try again after 1 second
if (grid == null) {
setTimeout(function () {AddEventToGridRefresh(gridName, functionToCall);}, 1000);
return;
}
// add the function to the onRefresh event
grid.control.add_onRefresh(functionToCall);
}
// function used in this example
function AdviseUser() {
alert("Sub-Grid refreshed");
}
For more information, here is the link
I'm trying to get a table in Titanium where each row has a static text and a textField where I can input something.
So I go and create a row where it's left part is the static text and the right part it's my input text field.
Just a small problem, I can't hide the keyboard by clicking outside of it.
If it was a normal textField outside a table I would just use the blur method, but in this case I can't get that to work.
This is my code so far:
Any idea on how this works and if the solution is valid for both iOS and Android?
var winAddObjectView = Titanium.UI.currentWindow;
var tableAddObjectData = [
{title:'name', hintText:'item name (optional)'},
{title:'track no.', hintText:'object tracking code'}
];
var tableAddObjectRowData = [];
for (var i = 0; i < tableAddObjectData.length; i++) {
var title = Ti.UI.createLabel({
text:tableAddObjectData[i].title,
textAlign:"right",
left:"20",
height:'auto',
width:'68',
color:'#526691',
font:{fontSize:12, fontWeight:'bold'},
});
var textField = Ti.UI.createTextField({
hintText:tableAddObjectData[i].hintText,
textAlign:"left",
left:"96",
height:'auto',
width:'184',
color:'#4C4C4C',
font:{fontSize:12, fontWeight:'bold'},
});
winAddObjectView.addEventListener("click", function(e){
textField.blur();
});
var row = Ti.UI.createTableViewRow({
height:"45",
});
row.add(title);
row.add(textField);
tableAddObjectRowData.push(row);
}
var tableAddObjectView = Ti.UI.createTableView({
headerTitle:'Enter Tracking Information',
style:Titanium.UI.iPhone.TableViewStyle.GROUPED,
backgroundColor:'transparent',
data:tableAddObjectRowData,
});
winAddObjectView.add(tableAddObjectView)
I have made a few changes in your code. Please try this
var tableAddObjectRowData = [];
var textFields = []; //Created an array of textFields
for (var i = 0; i < tableAddObjectData.length; i++) {
var title = Ti.UI.createLabel({
text:tableAddObjectData[i].title,
textAlign:"right",
left:"20",
height:'auto',
width:'68',
color:'#526691',
font:{fontSize:12, fontWeight:'bold'},
});
textFields[i] = Ti.UI.createTextField({ //Creating the textField
hintText:tableAddObjectData[i].hintText,
textAlign:"left",
left:"96",
height:'auto',
width:'184',
color:'#4C4C4C',
font:{fontSize:12, fontWeight:'bold'},
});
var row = Ti.UI.createTableViewRow({
height:"45",
});
row.add(title);
row.add(textFields[i]);
tableAddObjectRowData.push(row);
}
var tableAddObjectView = Ti.UI.createTableView({
headerTitle:'Enter Tracking Information',
style:Titanium.UI.iPhone.TableViewStyle.GROUPED,
backgroundColor:'transparent',
data:tableAddObjectRowData,
height : (tableAddObjectRowData.length * 45) + 60 //Added the height property for the tableView
});
winAddObjectView.addEventListener("click", hideSoftKeyboard); //added event listener to the window, moved this to out of the loop
function hideSoftKeyboard(){ //Added function to hide the keyboard
for(var i=0; i<textFields.length; i++){
textFields[i].blur(); //Hiding each keyboards
}
}
winAddObjectView.add(tableAddObjectView);
Explanation
winAddObjectView.addEventListener("click", function(e){
textField.blur();
});
The above code segment in your program didn't worked because the click event for the window was not firing due to the height of tableView, the window was hidden and your clicks were firing on the tableView. You can see the difference if you set the backgroundColor property for your tableView. So I adjusted the height of the tableView and hence the click fired in the window and the keyboard has gone.
Creation of textField array : You can do the same without creating the textField array and inside the for loop you can create the textField as var textField = Ti.UI.createTextField();. But if you do so, you cannot hide keayboard all the times, since event will be fired for the last textField only. Hence I created the textField array
For Android you can also use Ti.UI.android.hideSoftKeybaord() method. For that just change the hideSoftkeyboard() method in our code as follows
function hideSoftKeyboard(){ //Added function to hide the keyboard
if(Ti.Platform.osname === 'android'){
Ti.UI.Android.hideSoftKeyboard();
} else {
for(var i=0; i<textFields.length; i++){
textFields[i].blur(); //Hiding each keayboards
}
}
}
I am using PrimeFaces 3.4.1 to plot time chart (Date on x-axis, int value on y-axis).
At the moment I have something like that:
xhtml:
<p:lineChart id="timeChart" value="#{myGraphBean.model}" legendPosition="e" title="Time Chart" minY="0" maxY="25" style="height:300px"/>
Java bean:
private final static int MAX_VALUE = 20;
private final static int NUMBER_OF_POINTS = 20;
private final static DateFormat dateFormat = new SimpleDateFormat("dd-MM-yy");
private void createLinearModel() {
model = new CartesianChartModel();
Calendar day = Calendar.getInstance();
day.set(Calendar.HOUR_OF_DAY, 0);
day.set(Calendar.MINUTE, 0);
day.set(Calendar.SECOND, 0);
day.set(Calendar.MILLISECOND, 0);
LineChartSeries series = new LineChartSeries();
series.setLabel("My series");
for (int i = 0; i < NUMBER_OF_POINTS; i++) {
series.set(dateFormat.format(day.getTime()), getRandomValue());
day.add(Calendar.DAY_OF_MONTH, 1);
}
model.addSeries(series);
}
private int getRandomValue() {
return rand.nextInt(MAX_VALUE);
}
So my bean just creates some random int value for each day. (My application produces actual data points, this is just a dummy example)
In my application, I am generating data over a long time, for example 6 months. With the way I am doing things now, I get horrible graphs like that:
What I would like to do:
I'd like to be able to keep my data point but only display a tick, let's say every month.
I have tried to change the tick on the x-axis following a few other posts (ex1, ex2) but I couldn't get it work.
Using the primefaces extender, I tried to use things like tickInterval: '1 month', setting the min attributes but nothing worked. In most of the case it would just break the graph
Questions:
In the jqPlot doc, it says "Note, although jqPlot will parse most any human readable date, it is safest to use javascript time stamps when possible. Also, it is best to specify a date and time and not just a date alone. This is due to inconsistent browser handling of local time vs. UTC with bare dates."
In my graph bean, shall I populate the series using a formatted date (String) following the javascript time stamp ("yyyy-MM-dd h:mma") or using a java.util.Date directly?
How can I change the x-axis tick (for let's say 1 month), having a marker only every month, but still have the graph going through all the day points (i.e. I don't want to average my the points over the month)?
In Java, fill your LineChartSeries objects with times in milliseconds using Date#getTime().
On the facelets side, download from jqPlot site and import the following jqPlot plugins:
<h:outputScript name="Javascript/jqplot.canvasAxisTickRenderer.js" />
<h:outputScript name="Javascript/jqplot.canvasAxisTickRenderer.min.js" />
<h:outputScript name="Javascript/jqplot.dateAxisRenderer.js" />
<h:outputScript name="Javascript/jqplot.dateAxisRenderer.min.js" />
And use this js extender for p:lineChart component:
function chartExtender() {
this.cfg.axes = {
xaxis : {
renderer : $.jqplot.DateAxisRenderer,
rendererOptions : {
tickRenderer:$.jqplot.CanvasAxisTickRenderer
},
tickOptions : {
fontSize:'10pt',
fontFamily:'Tahoma',
angle:-40
}
},
yaxis : {
rendererOptions : {
tickRenderer:$.jqplot.CanvasAxisTickRenderer
},
tickOptions: {
fontSize:'10pt',
fontFamily:'Tahoma',
angle:30
}
}
};
this.cfg.axes.xaxis.ticks = this.cfg.categories;
}
Useful links:
http://forum.primefaces.org/viewtopic.php?f=3&t=25289#p79916
http://forum.primefaces.org/viewtopic.php?f=3&t=23891&p=78637#p78637