How to add a button in KeystoneJs Admin GUI to call function - keystonejs

Does anyone know if it's possible to add a button in the KeystonJs admin for example in the User model. I would like to have a set of fields and enable an admin to click "Add another" which will create a new field/row of fields.
So I just want that button to call a function. Something like this:
{ addItem: { type: Types.Button, label: 'Add another', actions: addItem() }}},

To add a button on KeystoneJs Admin GUI, you have to modify and build upon its's source. There is no way you can do that in this release (4.0).
There are discussions on their GitHub issues page and it may land in next version but no promises made yet.

Related

UI5 - OPA5 tests - simulate "right click" or "long press" or "context menu"

I am beginning with OPA5 tests in UI5 and I created a context menu that is shown when a button, label or an image is right-clicked or if user holds it on touch screen.
Now I need to write an OPA5 test for this. I can perform left-click using new sap.ui.test.actions.Press() but I am not able to do right-click or long-press.
https://sapui5.hana.ondemand.com/#/api/sap.ui.test.actions/overview
Can someone help, please?
I believe I would be able to write it in jQuery. And as UI5 is based on jQuery there should be a way but I do not know how to combine jQuery and UI5.
If your Control has an event for RightClick, Hold etc. you should be able to call this Event in an Opa test somehow like:
iRightClickMyControl: function () {
return this.waitFor({
id: "myControlId",
viewName: "myView",
actions: function (oControl) {
oControl.RightClick();
}
errorMessage: "myControl was not found."
});
}
See "Writing Your Own Action" in
https://openui5.hana.ondemand.com/#/topic/8615a0b9088645ae936dbb8bbce5d01d

Durandal view no more displayed if user click quickly on menus

I use Durandal 2.0 & Breeze in my SPA.
I have a sidebar menu for my drivers (Chauffeurs) where user can click on submenus (Récents, Disponibles, Indisponibles) for calling my view with different parameters. This will fill a koGrid with data. The data is fetched in the activate call and the binding of the koGrid is done in the compositionComplete.
Everything goes well most of the time. Things goes wrong when I click very quickly on submenus (calling the same view). Example: I click on 'Récents' and immediately (without waiting for the view to display) I click on 'Disponibles'.
I have the following for the activate:
var activate = function (filterParam) {
filter(filterParam);
pagedDataSource.getDataFunction = getData;
pagedDataSource.getPredicatesFunction = getPredicates;
return pagedDataSource.reload();
};
And I have the following code for the compositionComplete:
var compositionComplete = function (view) {
bindEventToList(view, '.kgCellText', gotoDetails);
$('#mySearchGrid').attr('data-bind', 'koGrid: gridOptions');
ko.applyBindings(vm, document.getElementById('mySearchGrid'));
};
When I trace the activity, I noted that if user click quickly on submenus, the activate does not have the time to finish and is called again (for the second click of the user) and the compositionComplete does not execute. Then after that, nothing more happened visually. It seems blocked.
Any idea how can I prevent this problem?
Thanks.
The migration to the latest Durandal version 2.0.1 fixed the problem.

XPages: how to create a dialog box with callback to the caller

I have an XPage with 2 custom controls. The 1st custom control has a repeat control and the second is used just as a dialog box.
The user can delete a row from the repeat control by clicking on a delete link. then i use rowVar.getDocument.getNoteID and i delete the document.
What i want is to ask the user first: "are you sure you want to delete it?"
I used "window.confirm()" in CSJS but i dont like the default prompt box. So then i used dojo dialog box but i cant use rowVar of repeat control in it to get the documentId.
Currently i have code in the OK button of the dialog but i want to use OK/Cancel buttons only as a true/false and execute the code in the main custom control. Is there a way of passing the value of the button back to the caller?
I have done this in many ways. Basically, write the information you need to find the document to delete to a viewScope variable. Then create a stand alone event handler that is called from the OK or Cancel buttons of the dialog.
So the eventHandler looks like this post by Jeremey Hodge:
<xp:eventHandler
event="onfubar"
id="eventHandler1"
submit="false">
<xp:this.action><![CDATA[#{javascript:
// write the ssjs to save the doc base on viewScope parameters
}]]></xp:this.action>
</xp:eventHandler>
Then the dialog buttons look something like this (based on the Mastering XPages book and many other sources):
XSP.partialRefreshGet("#{id:eventHandler1}", {
params : {action :"OK" },
onComplete : function () {
// do something else if needed
},
onError : function() {
alert("no soup for you!");
}
});

Blackberry Cascades Context Menu From Button Click

I'm using BlackBerry-10 Cascades to develop an app. I want a context menu to open on the right when I click a button. Currently I have it so that the menu opens after a press- hold of the button but I need it to open as soon as the button is tapped. I've tried finding a way to do this but cannot find it in the documentation. Is there any way I can invoke the context menu from the onclicked method of a button press?
BTW: this is all in QML
I am not really familiar with the controls available on blackberry-cascades, but, it seems like it should be as simple as moving the code from the onPressAndHold signal handler to the onClicked signal handler. For better help you should post the relevant snippets of your code along with the imports so we can find more info to help you in your particular scenario.
actions: [
//! [0]
ActionItem {
title: _webMaps.viewModeTitle
imageSource: "asset:///images/map.png"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
_webMaps.nextViewMode()
map.setMapType(_webMaps.viewMode);
}
},
//! [0]
ActionItem {
title: qsTr("Waterloo")
imageSource: "asset:///images/pin.png"
ActionBar.placement: ActionBarPlacement.InOverflow
onTriggered: {
map.setCenter(43.468245, -80.519603);
}
}
]
try this sample..
In theory you should be able to do it but there are two problems that I see with this idea:
A context menu is supposed to be posted in the context of another UI element. I'm not sure what context menu items you might have for a button. If you are posting the context menu in the context of some other control then you will confuse your users.
The age old issue of non-conformance with the UI style guide of the platform. You will be expecting your uses, who have invested time in learning how to operate the BB10 UI, to now learn a different set of interface semantics.
There is a Context menu api in the BlackBerry Platform Services (BPS) library that you can use.
https://developer.blackberry.com/native/reference/core/com.qnx.doc.bps.lib_ref/topic/manual/dialog.h_functionscontextmenufunctions.html?f=dialog
It is not "Cascades functionality" per se, but you can use it from within a Cascades application. Note that it is a C based api so you would have to create some kind of "helper class" and expose it to QML yourself.
Try this sample code for open context menu on button clicked.

Dynamic menu button items in TinyMCE

I have a custom menubutton in my tinyMCE editor that uses specific HTML elements elsewhere on the page as the menu items. I use a jQuery selector to get the list of elements and then add one each as a menu item:
c.onRenderMenu.add(function(c,m) {
m.add({ title: 'Pick One:', 'class': 'mceMenuItemTitle' }).setDisabled(1);
$('span[data-menuitem]').each(function() {
var val = $(this).html();
m.add({
title: $(this).attr("data-menuitem"),
onclick: function () { tinyMCE.activeEditor.execCommand('mceInsertContent', false, val) }
});
});
});
My problem is that this only happens once when the button is first clicked and the menu is first rendered. The HTML elements on the current page will change occasionally based on user clicks and some AJAX, so I need this selector code to run each time the menu is rendered to make sure the menu is fully up-to-date. Is that possible?
Failing that, is it possible to dynamically update the control from the end of my AJAX call elsewhere in the page? I'm not sure how to access the menu item and to update it. Something using tinyMCE.activeEditor.controlManager...?
Thanks!
I found a solution to this problem, though I'm not sure it's the best path.
It doesn't look like I can make tinyMCE re-render the menu, so instead I've added some code at the end of my AJAX call: after it has updated the DOM then it manually updates the tinymce drop menu.
The menu object is accessible using:
tinyMCE.activeEditor.controlManager.get('editor_mybutton_menu')
where mybutton is the name of my custom control. My quick-and-dirty solution is to call removeAll() on this menu object (to remove all the current menu items) and then to re-execute my selector code to find the matching elements in the (new) DOM and to add the menu items back based on the new state.
It seems to work just fine, though tweaks & ideas are always welcome!