ExtJS 4 / 5 - Set the correct CSS for a Drag and Drop that is not allowed with custom rules - css

I have two grids side by side.
The left grid has a list of tags the user can select, and the grid on the right is empty so the user can drag the tags he wants there.
The plugin code for both grids is:
viewConfig: {
plugins: [
Ext.create('Ext.grid.plugin.DragDrop', {
ddGroup: 'selectedTags'
})
]
}
So, as I wanted to limit the user to be able to drag only 5 tags, I've added the following code to the grid on the right:
listeners: {
beforedrop: {
fn: function() {
if (grid.getStore().data.items.length > 4) {
dropHandlers.cancelDrop();
}
},
scope: me
}
}
This is working perfectly but what I wanted is to show the NO-DROP icon when the items are dragged over the grid instead of showing the green line as if the action was allowed.
Thanks,

After looking for this solution for a while, I finally figured it out.
You must add two methods to the dropZone in the Target Grid:
notifyOver and onNodeDrop
The solution for my problem would be the code below:
Ext.create('Ext.grid.Panel', {
store: myStore,
columns: [columns],
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
dragText: 'Drag and drop to reorganize',
pluginId : 'dragNdrop',
dropZone:{
notifyOver:function(source, e, data){
var store = this.view.ownerCt.getStore();
return store.getCount()<5?this.dropAllowed:this.dropNotAllowed
},
onNodeDrop:function(targetNode,dragZone,e,data){
var sourceStore = dragZone.view.ownerCt.getStore(),
targetStore = this.view.ownerCt.getStore(),
isDropValid = targetStore.getCount()<5;
if(isDropValid){
sourceStore.remove(data.records[0])
targetStore.add(data.records[0]);
}
return isDropValid;
}
}
}
},
height: 200,
width: 400,
renderTo: Ext.getBody()
});

Lopes, you can use column renderer in grid where you can check the items count and display appropriate icon. Code snippet for your reference:
gridCheckboxRenderer: function(value, meta, rec, rowInd, colInd, store){
var cssPrefix = Ext.baseCSSPrefix, cls = [cssPrefix + 'grid-checkheader'];
if (condition == false) {
cls.push(cssPrefix + 'grid-checkheader-checked-disabled');
return '<div class="' + cls.join(' ') + '"> </div>';
}
return '<div class="x-grid-row-checker"> </div>';
}
Hope it helps.

Related

Chart.JS - Polar area - Legend hover style and margin

Hi all,
Hopefully this is an easy one. I've set up a legend with an onclick event but would like the mouse cursor to change to "pointer" when I hover over the labels (see chart screenshot above). Currently it's hard to tell that the labels are links because the mouse cursor doesn't change when I hover over them.
Also how do I add some margin/padding between the legend and chart (space below the legend).
Many thanks!
You can achieve the desired behavior using a combination of the legend onHover config option (to change the pointer style to pointer) and the custom tooltips config option (to change the pointer style back to default).
Here is an example config demonstrating a working solution. I wasn't sure if you were using jQuery or not so I decided not to use it. Feel free to change accordingly.
options: {
legend: {
position: 'top',
labels: {
fontColor: 'rgb(255, 99, 132)'
},
onHover: function(event, legendItem) {
document.getElementById("canvas").style.cursor = 'pointer';
}
},
tooltips: {
custom: function(tooltip) {
if (!tooltip.opacity) {
document.getElementById("canvas").style.cursor = 'default';
return;
}
}
}
}
I found a different way to make this work. This lines up more literally in my mind. Perhaps the framework was updated in the interim since this was initially answered.
// This event fires anytime you mouse over the chart canvas.
onHover: function (event) {
event.target.style.cursor = 'default';
},
responsive: true,
maintainAspectRatio: false,
legend: {
display: true,
position: 'bottom',
onHover: function (event, legendItem) {
// There is only a legendItem when your mouse is positioned over one
if (legendItem) {
event.target.style.cursor = 'pointer';
}
}
}
In case anyone wants to know more, here are the docs for events and the legend.
Faster, without scanning the DOM every time, you find the target under native in the hover event
Tested in version 3.2.1 and 3.3.2 (latest on 2021 jun 22)
options: {
plugins : {
legend: {
labels: {
onHover: function (e) {
e.native.target.style.cursor = 'pointer';
},
onLeave: function (e) {
e.native.target.style.cursor = 'default';
}
}
}
}
}
The accepted answer did not work for me because my tooltips are always visible (position: "nearest"). So I use a timeout to change and revert the cursor style:
onHover: function(event, legendItem) {
document.getElementById("canvas").style.cursor = "pointer";
clearTimeout(hoverTimeout); // global var
hoverTimeout = setTimeout(function() {
document.getElementById("canvas").style.cursor = "default";
}, 100);
}
It's a dirty trick but it works.

Fullcalendar view columnFormat being igored

I'm having a challenge formatting the column headings for the following fullcalendar view.
views: {
timeline7Days: {
columnFormat: 'ddd D/M',
type: 'timelineWeek',
slotDuration: '24:00',
duration: { days: 7 },
buttonText: 'resource week',
resourceEditable: false
},
Basically, it ignores the column format of 'ddd D/M' and displays each column with the title of 'Mo 16' instead of 'Mon 1/16'. Any ideas?
click here for jsbin
Thanks, your example didn't exactly work, but it helped put me on the right track.
I ended up using the following code (replaced 'span' with 'a'.
'code'
if ((view.name == 'timeline7Days') || (view.name = 'timelineMonth'))
{
$("th[data-date]").each(function()
{
$(this).find('a').text(moment($(this).data().date).format('ddd M/D'))
});
}
There is definately something wrong with columnFormat for custom view. You could try such trick:
viewRender: function( view, element ) {
if (view.name == 'timeline7Days') {
$("th[data-date]").each(function(){
$(this).find('span').text(moment($(this).data().date).format('ddd M/D'));
});
}
}

Froala add custom pre code button

I'm trying to create a code button with the Froala editor which can basicly do the same thing as here on SO by pressing CNTRL+K. Now I think I have two choices.
The first one is to edit the froala-editor.js file, because Froala already has a 'code' button which only adds the <pre> tags. If I could somehow get it to also add the <code> tag, problem solved. Unfortunately I didn't get this to work.
The second option is to create a custom button, so far I have this piece of code:
$('textarea[name="description"]').editable({
//Settings here
customButtons: {
insertCode: {
title: 'Insert code',
icon: {
type: 'font',
value: 'fa fa-code'
},
callback: function() {
this.saveSelection();
if (!this.selectionInEditor()) {
this.$element.focus(); // Focus on editor if it's not.
}
var html = '<pre><code>' + this.text() + ' </code></pre>';
this.restoreSelection();
this.insertHTML(html);
this.saveUndoStep();
}
}
}
});
It works somehow, but it's buggy and produces strange html like so:
<p><code></code>
<pre><code>asdasdasdasd
</code></pre>
</p>
Any help with getting this done for either option one or two would be greatly appreciated.
If you upgrade to version 1.2.3 that is available on Github your code should work https://github.com/froala/wysiwyg-editor. It's not necessary to save/restore selection.
LATER EDIT:
Here is a jsFiddle for it http://jsfiddle.net/9pmmg1jk/.
customButtons: {
insertCode: {
title: 'Insert code',
icon: {
type: 'font',
value: 'fa fa-code'
},
callback: function() {
if (!this.selectionInEditor()) {
this.$element.focus(); // Focus on editor if it's not.
}
var html = '<code>' + (this.text() || '​') + '<span class="f-marker" data-type="false" data-id="0" data-fr-verified="true"></span><span class="f-marker" data-type="true" data-id="0" data-fr-verified="true"></span></code>';
this.insertHTML(html);
this.restoreSelectionByMarkers();
this.saveUndoStep();
}
}
}

How to use css in extjs to modify the "browse files" button?

I have created a menu with extjs where you click on it and can see menu items dropping down. The first item is open. This button is supposed to open a file from file-dialog. But the only way I can open the file dialog I found is to place the file dialog field in the menu by only showing the button.
Now I need help to make this button look like just regular menu item:
var item = Ext.create('Ext.form.field.File', {
buttonOnly: true,
buttonText: 'Open',
hideLabel: true,
// maybe to add some css class here
listeners: {
'change': function(fb, v){
Ext.Msg.alert('Status', item.getValue());
}
}
});
var mainmenu = Ext.create('Ext.menu.Menu', {
width: 200,
margin: '0 0 10 0',
items: [item]
});
You can add the attribute buttonConfig to the Ext.form.field.File item and then use the standard attributes to a button. For example, this might work:
var item = Ext.create('Ext.form.field.File', {
buttonOnly: true,
buttonText: 'Open',
hideLabel: true,
buttonConfig: {
style: {
background: "#f1f1f1",
border: 0
}
},
listeners: {
'change': function(fb, v){
Ext.Msg.alert('Status', item.getValue());
}
}
});
Try changing putting a cls instead of a style attribute in the buttonConfig to use a CSS class instead of inline CSS.

GMAP3 - Google map API3 trigger marker click event from external url

Using GMAP3 Google Map API 3 class. Cannot quite figure out how to trigger the click event on a marker from an external link via javascript. I have tried the v3 api syntax but suspect that I am missing something in relation to the GMAP3 library. Could anyone help me out here?
I am showing a map with markers and infobox data from an ajax request with a resulting JSON array. Works great. I assign a click event to the marker and it works fine. I am using parsing that same JSON array to populate a datatable with a Click Me
X is actually the incrementing marker counter I used when building the JSON array, so it would start with 0 and build to whatever value represents all my markers. I am expecting to use this value to tell GMAP3 which marker I want to pass the click event to... if this though process is wrong then I am really confused.
My JSON array object is stored in markerlist and passed to the function below... which works great but I cannot seem to trigger those clicks from my datatable links... (see my jquery code below to grab those clicks and attempt to pass them along to the map)
My map code is:
function display( markerlist ) {
$("#map").gmap3({action:'clear'});
$("#map").gmap3(
{action: 'init',
options:{
center:true,
zoom:13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
scrollwheel: true,
streetViewControl: true
}
},
{action: 'addMarkers',
radius:100,
markers: markerlist,
clusters:{
maxZoom: 10,
// This style will be used for clusters with more than 0 markers
20: {
content: '<div class="cluster cluster-1">CLUSTER_COUNT</div>',
width: 53,
height: 52
},
// This style will be used for clusters with more than 20 markers
50: {
content: '<div class="cluster cluster-2">CLUSTER_COUNT</div>',
width: 56,
height: 55
},
// This style will be used for clusters with more than 50 markers
100: {
content: '<div class="cluster cluster-3">CLUSTER_COUNT</div>',
width: 66,
height: 65
}
},
marker: {
options: {
clickable: true
},
events:{
click: function(marker,event,data) {
$(this).gmap3({action: 'clear', name : 'infowindow'});
$(this).gmap3({action: 'addinfowindow', anchor: marker, options: { content:
'<div class="text"><strong><div style="color:navy;">' + data.itype + '</strong><br/><div id="address" snum="' + data.streetnum + '" snam="' + data.streetnam + '" styp="' + data.streettyp + '">'+ data.iaddress +'</div><br/>' + data.inum + '<br/>'+ data.datetime +'</div><hr>'+data.notes+'</div>'} })
},
mouseover: function(marker, event, data){
$(this).gmap3(
{ action:'clear', name:'overlay'},
{ action:'addOverlay',
latLng: marker.getPosition(),
content: '<div class="infobulle">' +
'<div class="bg"></div>' +
'<div class="text">' + data.itype +'</div>' +
'</div>' +
'<div class="arrow"></div>',
offset: {
x:-46,
y:-73
}
});
},
mouseout: function(){
$(this).gmap3({action:'clear', name:'overlay'});
}
}, //end events
callback: function(result){
if (result){
//not doing anything with a callback at this time
} else {
alert('Bad callback...');
}
} //end callbacks
} // end marker
}
,{action:"autofit"} //end action
);
$("a#link").live('click',function(markerlist){ // this works and I can get my arid ok, but the trigger won't work
var arid = $(this).attr('arid');
google.maps.event.trigger(markerlist[arid], 'click');
return false;
});
};
Any help would really be appreciated and am sure will be useful to others!
I think the problem is markerlist is not a global variable, it's local to your display function? What do you get if you write markerlist to the console in your click event handler?

Resources