Alfresco dashlet post form - alfresco-share

I have been searching google for a few days now and cant find any solution to my problem.
I have created a custom Alfresco Aukai dashlet and placed a form in it thus:
define(["dojo/_base/declare",
"dijit/_WidgetBase",
"alfresco/core/Core",
"alfresco/core/I18nUtils",
"alfresco/dashlets/Dashlet"],
function(declare, AlfCore, I18nUtils, Dashlet) {
// First define a form...
var form = {
name: "alfresco/forms/Form",
config: {
showOkButton: true,
okButtonLabel: "Save",
showCancelButton: false,
cancelButtonLabel: "Doesn't Matter",
okButtonPublishTopic: "PUBLISH_TOPIC",
okButtonPublishGlobal: true,
widgets: []
}
};
// Define a text box...
var textBox = {
name: "alfresco/forms/controls/DojoValidationTextBox",
config: {
fieldId: "EMAIL",
name: "email",
label: "Contact",
description: "Your e-mail address",
placeHolder: "name#address.com",
validationConfig: [
{
validation: "regex",
regex: "^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*#([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+[a-zA-Z]{2,9})$",
errorMessage: "Valid E-mail Address Required"
}
]
}
};
form.config.widgets.push(textBox);
// Define a checkbox...
var checkbox = {
name: "alfresco/forms/controls/DojoCheckBox",
config: {
fieldId: "SHOW",
name: "showEmail",
label: "Show E-mail",
description: "Uncheck to hide the e-mail field",
value: true
}
};
form.config.widgets.push(checkbox);
// Update the textbox to respond to checkbox changes...
textBox.config.visibilityConfig = {
initialValue: true,
rules: [
{
targetId: "SHOW",
is: [true]
}
]
};
return declare([Dashlet], {
/*
* Add padding to the body.
* smallpad (4px padding), mediumpad (10px padding - recommended) and largepad (16px padding)
*/
additionalCssClasses: "mediumpad",
/**
* Explicit height in pixels of the Dashlet body.
*/
bodyHeight: 200,
/**
* Id that will be used to store properties for this Dashlet.
* i.e. the Dashlet height when using the resizer.
*/
componentId: "component.messaging-dashlet",
/**
* The i18n scope to use for this Dashlet.
*/
i18nScope: "dashlets.MessagingDashlet",
/**
* An array of the i18n files to use with this Dashlet.
*/
i18nRequirements: [{i18nFile: "./i18n/MessagingDashlet.properties"}],
/**
* The widgets to be acting as title bar actions.
*/
widgetsForTitleBarActions: [
{
id: "MESSAGING_DASHLET_ACTIONS",
name: "alfresco/html/Label",
config: {
label: "Title-bar actions"
}
}
],
/**
* The widgets to be placed in the top toolbar.
*/
widgetsForToolbar: [
{
id: "MESSAGING_DASHLET_TOOLBAR",
name: "alfresco/html/Label",
config: {
label: "Toolbar"
}
}
],
/**
* The widgets to be placed in the body of the dashlet.
*/
widgetsForBody: [
{
id: "HELLO_DASHLET_VERTICAL_LAYOUT",
name: "alfresco/layout/VerticalWidgets",
config: {
widgetWidth: 50,
widgets: [
form
]
}
}
]
});
});
The form is displayed but the Save button is inactive.
When checking with fire bug I am informed that there is no javascript on the page!
Apart from this every thing works fine even get the error message when an invalid email address is entered.
Any suggestions? Alternatively a working example of a form in a dashlet posting would be nice :)
I have looked into this further while trying to populate a select box with the OptionsService.
optionsConfig: {
publishTopic: "ALF_GET_FORM_CONTROL_OPTIONS",
publishPayload: {
url: url.context + "/proxy/alfresco/api/people",
itemsAttribute: "people",
labelAttribute: "firstName",
valueAttribute: "userName"
}
In the debug I can see this but nothing happens over the wire, there is not corresponding request sent to the server!
This is the same issue I am getting with the post so this would suggest a more fundamental problem with my code.

Your form does not have any widgets / controls defined.
okButtonPublishGlobal: true,
widgets: []
Please refer simple CRUD example using aikau, http://www.codingfreaks.net/2015/03/aikau-form-example-for-simple-student.html
https://github.com/Alfresco/Aikau/blob/develop/aikau/src/main/resources/alfresco/reports/TopSiteContributorReport.js
Can you please look at this link?
Alfresco share is using Site Contributor Breakdown Dashlet, with the input form controls using aikau.

Related

Getting Cannot execute "delete" on "Article" in CASL JS

I'm learning CASL JS and trying to delete an article with a condition but getting this error Cannot execute "delete" on "Article". Here is the CodeSandBox Link.
Here is the sample code:
const { createMongoAbility, ForbiddenError } = require("#casl/ability");
const rules = [
{
action: "read",
subject: "Article"
},
{
inverted: true,
action: "delete",
subject: "Article",
conditions: { published: true },
reason: "You are not allowed to delete this article"
}
];
const ability = createMongoAbility(rules);
// this can be pulled from a database
class Article {
constructor(attrs) {
Object.assign(this, attrs);
}
}
const anotherArticle = new Article({
authorId: 2,
published: false,
content: "Lorem Ipsum"
});
try {
// checking ability before taking some action
ForbiddenError.from(ability).throwUnlessCan("delete", anotherArticle);
} catch (error) {
console.log(error.message); // throwing `Cannot execute "delete" on "Article"`
}
Please help me out. Thanks
The creator of CASL JS has answered this:
you declared that it's not possible to delete published articles but you have never said that it's possible to delete articles at all. That's why you get the error
So this means that I already declared inverted permission and it's not possible to delete articles.

storybook argType and defaultValue with a select losing values when changing view in the sidebar

I am trying to use argTypes with a select to allow the user to change fields, I have this default export:
const themes = {
defaultTheme,
salesTheme,
cuttingTheme,
} as const;
export default {
title: 'atoms/Button',
component: Button,
argTypes: {
theme: {
options: Object.keys(themes), // iterator
mapping: Object.values(themes), // values
control: {
type: 'select',
labels: Object.keys(themes),
values: Object.values(themes), //
},
defaultValue: themes.defaultTheme,
},
},
} as ComponentMeta<typeof Button>;
defaultValue works fine when the page first loads but if I change a menu item on the sidebar pane it loses its value.

Meteorjs and autoform simple schema - How to validate simple checkbox

I'm using autoform and simple schema and I've defined a schema object with the following field:
confirm_nominee: {
type: Boolean,
autoform: {
type: "select-checkbox-inline",
options: function () {
return [
{
label: "Check here to certify that the volunteer nominated in the application is not a current member of the organization’s Board of Directors.",
value: 1
}
];
}
}
},
I just want it so if the box is left unchecked, the error reports "This field is required" and if it's checked, then the user is good to go.
This seems like it should be a really simple validation of whether the checkbox is checked or not. I've tried adding in a defaultValue of 0, but that doesn't work either.
Any thoughts?
Thanks so much.
Set in your schema rules the key allowedValues: [true] and the checkbox must be checked to be true and pass validation
confirm_nominee: {
type: Boolean,
autoform: {
type: "select-checkbox-inline",
allowedValues: [true],
options: function () {
return [
{
label: "Check here to certify that the volunteer nominated in the application is not a current member of the organization’s Board of Directors.",
value: 1
}
];
}
}

Multiple links in Bazinga Hateoas with Symfony

I am using Bazinga Hateoas with Fosrest in one of my SF2 project.
In one of API call, I want to display link of friends with current user or user id supplied like this:
{
"_links": {
"self": { "href": "/users/1" },
"friends": [
{ "href": "/users/2" },
{ "href": "/users/3" },
]
},
}
I am using below code in Entity.User.yml file:
relations:
-
rel: self
href:
route: api_1_get_users
parameters:
id: expr(object.getId())
absolute: true
-
rel: expr(object.findFriends(object.getId()))
href:
route: api_1_get_users
parameters:
id: expr(object.getId())
absolute: true
I have put "findFriends" method in repository but its not accessible inside yml file. I guess this is not the correct way of doing things.
I have gone through https://github.com/willdurand/Hateoas but not able to figure out how to do it. Please guide me how I can achieve this...
Any help would be much appreciated !
Please guide me how I can achieve this
This is how you work with #RelationProvider.
/**
* Note:
* ====
* RelationProvider takes the method name which returns the relations.
*
* #Hateoas\RelationProvider("addRelations")
*/
class LinkContainingResource
{
public function addRelations($object, ClassMetadataInterface $classMetadata)
{
/**
* Important Note:
* ===============
* Relation is actually an Hateoas\Configuration\Relation object,
* NOT \Hateoas\Configuration\Annotation\Relation
*/
return [new Relation('relation_name', 'link1'),
new Relation('relation_name', 'link2'),
new Relation('relation_name', 'link3')];
}
}
Json/Hal Result:
{
"_links": {
"relation_name": [
{"href": "link1"},
{"href": "link2"},
{"href": "link3"}
]
}
}

Kendo UI Grid with Drop down Template Not updating value after save to server

We are using a server based simple grid. The grid reads and updates data for a remote data source. It has two columns that are using drop down editors. Everything seems to work fine except that after saving, when editor closes, the changed values are not displayed in the edited row. It still shows the old value. When we try to refresh the grid using the sync event, it changes the order of the rows however, it does update the values on refresh.
It seems like the template function is not executed after the update is completed. How to edit the grid / code to ensure that the changed value is reflected in the grid?
Grid Definition code:
$("#servicetype-grid").kendoGrid({
pageable: true,
toolbar: [{name: "create", text: ""}, { template: kendo.template($("#servicetype-search-template").html())}],
columns: [
{
field: "serviceName", title: "Service Name"
},
{
field: "billCalculationTypeId",
editor: calculationTypeDropDownEditor,
template: function(dataItem) {
return kendo.htmlEncode(dataItem.billCalculationTypeName);
},
title: "Bill Calculation Type"
},
{
field: "payCalculationTypeId",
editor: calculationTypeDropDownEditor,
template: function(dataItem) {
return kendo.htmlEncode(dataItem.payCalculationTypeName);
},
title: "Pay Calculation Type"
},
{
command: [
{ name: "edit", text: { edit: "", cancel: "", update: "" }},
{ name: "destroy", text:""}
],
title: "Actions"
}
],
dataSource: dataSource,
sortable: {
mode: "single",
allowUnsort: false
},
dataBound: function(e) {
setToolTip();
},
edit: function(e) {
$('.k-grid-update').kendoTooltip({content: "Update"});
$('.k-grid-cancel').kendoTooltip({content: "Cancel"});
},
cancel: function(e) {
setToolTip();
},
editable: {
mode: "inline",
confirmation: "Are you sure that you want to delete this record?"
}
});
Drop down function is defined as:
function calculationTypeDropDownEditor(container, options) {
$('<input required data-text-field="name" data-value-field="id" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: {
transport: {
read: {
dataType: "jsonp",
url: baseURL + "rips/services/calculationType/lookupList"
}
}
}
});
}
After doing some search on Google and browsing through different examples on Kendo site, I finally was able to resolve this issue. Following is my understanding of the problem and solution:
When we are using drop down box or combo box as a custom editor, generally we have a different datasource that contains a list options with an id and a value to show. I defined the template as "#=field.property#" of the field that I was looking up. In my case it was calculation type. Following is my model:
model: {
id: "serviceId",
fields: {
serviceName: { field:"serviceName", type: "string", validation: { required: { message: "Service Name is required"}} },
billCalculationType: { field: "billCalculationType", validation: { required: true}},
payCalculationType: { field: "payCalculationType", validation: { required: true} }
}
In above, billCalculationType and payCalculationType are supposed to be drop down list values displaying the calculation type name but storing the id of the corresponding calculation type. So, in my grid definition, I added following:
{ field: "billCalculationType",
editor: calculationTypeDropDownEditor,
template:"#=billCalculationType.name#",
title: "Bill Calculation Type" },
Where calculation dropdown editor is a function that builds a drop down from external data source. So, it works fine. However, for the template definition to work in (field.property) format, the server must return the value as a class for this field and not a simple text. So, in my server service, I returned in following format:
{"billCalculationType":{"id":"4028828542b66b3a0142b66b3b780001","name":"Hourly","requiredDetails":false},"payCalculationType":{"id":"4028828542b66b3a0142b66b3b960002","name":"Kilometers","requiredDetails":false},"serviceId":"4028828542b66b3a0142b66b3c16000a","serviceName":"XYZ"}
Notice that the billCalculationType and payCalculationType are returned as objects with name and id as properties. This allows the template to work properly.
Hope this helps.

Resources