Related
The expected XML format is as per below:
<c:condition>
<a:condition>
<fieldname>fieldName</fieldname>
<fieldtest>fieldTest</fieldtest>
<fieldvalues>
<fieldvalue>fieldValue</fieldvalue>
</fieldvalues>
</a:condition>
<operator>operator</operator>
<a:condition>
...<some>
</a:condition>
</c:condition>
The <a:condition> and the <operator> both needs to be in a collection as both can have as many as required by the XML request.
EDITED Type:elements code as below:
{{
var MyModule = {
name: 'MyModule',
typeInfos: [{
type: 'classInfo',
localName: 'ElementsType',
propertyInfos: [{
type: 'elements',
name: 'c:condition',
wrapperElementName: {
localPart: 'condition',
namespaceURI: 'http://us.xomplex',
prefix: 'c'
},
collection: true,
elementTypeInfos: [{
elementName: {
localPart: 'condition',
namespaceURI: 'http://us.xomplexio',
prefix: 'a'
},
typeInfo: 'MyModule.SubAtomic'
}, {
elementName: 'operator',
typeInfo: 'String'
}]
}]
},
{
type: 'classInfo',
localName: 'SubAtomic',
propertyInfos:[{
type: 'element',
name: 'fieldName',
elementName: 'fieldName',
typeInfo: 'String'
},
{
type: 'element',
name: 'fieldTest',
elementName: 'fieldTest',
typeInfo: 'String'
}]
}],
elementInfos: [{
elementName: 'root',
typeInfo: 'MyModule.ElementsType'
}]
};
console.log("creating unmarsaller");
var context = new Jsonix.Context([MyModule]);
var unmarshaller = context.createUnmarshaller();
var unmarshalled = unmarshaller.unmarshalString('<root><c:condition xmlns:c="http://us.xomplex"><a:condition xmlns:a="http://us.xomplexio">one</a:condition><operator>2</operator><a:condition xmlns:a="http://us.xomplexio"><fieldName>unmra</fieldName><fieldTest>Beneed</fieldTest></a:condition><a:condition xmlns:a="http://us.xomplexio">four</a:condition><operator>AND</operator><operator>4</operator></c:condition></root>');
console.log("unmarshalled");
console.log(unmarshalled);
var marshaller = context.createMarshaller();
var marshalled = marshaller.marshalString({
name: {
localPart: 'root'
},
//Marshalling - not working....
value: {
//'c:condition': ['one', 2, 'unmra', 'four', 10,4]
'c:condition': [
['Field','Test'],9
]
}
});
console.log(marshalled);
}}
EDITED Looks like elements can fulfill my requirements. Unmarshalling works too. Now I only need to figure out how to marshall it from Json format. Any advice will be greatly appreciated
Not exactly as you want it.
You can use elements or elementReferences property to declare a collection property which would contain different elements as items. Something like:
{
type: 'elementRefs',
name: 'acondition',
collection: true,
elementTypeInfos: [{
elementName: 'condition',
typeInfo: 'DOXML.Atomicon'
}, {
elementName: 'operator',
typeInfo: 'String'
}]
}
This property would contain condition or operator ins any quantity or order. But this does not guarantee that you have the same number of them or that it's always condition followed by operator. If this is what you want, consider wrapping condition and operator pair into an element like conditionalOperator.
This is my solution to the problem:
var MyModule = {
name: 'MyModule',
typeInfos: [{
type: 'classInfo',
localName: 'ElementsType',
propertyInfos: [{
type: 'elements',
name: 'c:condition',
wrapperElementName: {
localPart: 'condition',
namespaceURI: 'http://us.xomplex',
prefix: 'c'
},
collection: true,
elementTypeInfos: [{
elementName: {
localPart: 'condition',
namespaceURI: 'http://us.xomplexio',
prefix: 'a'
},
typeInfo: 'MyModule.SubAtomic'
}, {
elementName: 'operator',
typeInfo: 'String'
}]
}]
},
{
type: 'classInfo',
localName: 'SubAtomic',
propertyInfos:[{
type: 'element',
name: 'fieldName',
elementName: 'fieldName',
typeInfo: 'String'
},
{
type: 'element',
name: 'fieldTest',
elementName: 'fieldTest',
typeInfo: 'String'
},
{
type: 'element',
name: 'fieldValues',
elementName: 'fieldValues',
typeInfo: 'MyModule.SubSubAtoms'
}]
},
{
type: 'classInfo',
localName: 'SubSubAtoms',
propertyInfos:[
{
type: 'element',
name: 'fieldValue',
collection: true,
elementName: 'fieldValue',
typeInfo: 'String'
}
]
}
],
elementInfos: [{
elementName: 'root',
typeInfo: 'MyModule.ElementsType',
},
{
elementName: 'atoms',
typeInfo:'MyModule.SubAtomic'
}
]
};
console.log("creating unmarsaller");
var context = new Jsonix.Context([MyModule]);
var unmarshaller = context.createUnmarshaller();
var unmarshalled = unmarshaller.unmarshalString('<root><c:condition xmlns:c="http://us.xomplex"><a:condition xmlns:a="http://us.xomplexio">one</a:condition><operator>2</operator><a:condition xmlns:a="http://us.xomplexio"><fieldName>unmra</fieldName><fieldTest>Beneed</fieldTest></a:condition><a:condition xmlns:a="http://us.xomplexio">four</a:condition><operator>AND</operator><operator>4</operator></c:condition></root>');
console.log("unmarshalled");
console.log(unmarshalled);
var marshaller = context.createMarshaller();
var marshalled = marshaller.marshalString({
name: {
localPart: 'root'
},
value: {
'c:condition': [
"9",
{ name:
{
localPart: 'atoms'
},
fieldName: "rating",
fieldTest: "equals",
fieldValues: {
fieldValue: ["563"]
} ,
TYPE_NAME: 'MyModule.SubAtomic'
},
"AND",
{ name:
{
localPart: 'atoms'
},
fieldName: "price",
fieldTest: "between",
fieldValues: {
fieldValue: ["150", "300"]
} ,
TYPE_NAME: 'MyModule.SubAtomic'
}] //end of c:condition value
}
});
console.log(marshalled);
Done! Thank you #lexicore, your guides were a great help!
I have been trying to get a form in an Aukai dashlet to work for over a week now. It was realativly easy to get it to appear on the dashboard but nothing I have done has resulted in any this being sent to the server!
Has anyone or know of anyone that has a form fully working in a Dashlet?
Mine will not read from the OPtionsService (does not fill the dropdown of a select) nor post to any topic on submit, just sits there and does nothing. I can see the events in the debug window but on chrome and firefox debug view there is no network activity and server does nothing.
dashlet get js
model.jsonModel = {
rootNodeId: args.htmlid,
pubSubScope: instance.object.id,
bodyHeight: "400px",
services: [
{ name: "alfresco/services/LoggingService",
config: {
loggingPreferences:{
enabled: true,
all: true
}
}
},
"alfresco/services/OptionsService"
],
widgets: [
{
name: "alfresco/dashlets/Dashlet",
config: {
title: "My Messages",
bodyHeight: args.height || null,
componentId: instance.object.id,
widgetsForTitleBarActions: [
{
id: "MESSAGING_DASHLET_ACTIONS",
name: "alfresco/html/Label",
config: {
label: "Title-bar actions"
}
}
],
widgetsForToolbar: [
{
id: "MESSAGING_DASHLET_TOOLBAR",
name: "alfresco/html/Label",
config: {
label: "Toolbar"
}
}
],
widgetsForBody: [
{
id: "HELLO_DASHLET_VERTICAL_LAYOUT",
name: "alfresco/layout/VerticalWidgets",
config: {
widgetWidth: "350px",
widgets: [
{ name: "alfresco/forms/Form",
config: {
showOkButton: true,
okButtonLabel: "Send",
showCancelButton: false,
okButtonPublishTopic: "PUBLISH_TOPIC_MESSAGE",
okButtonPublishGlobal: true,
widgets: [{
name: "alfresco/forms/controls/TinyMCE",
config: {
fieldId: "MESSAGE_TEXT",
name: "message",
label: "Message",
widgetWidth: 200
}
},
{
name: "alfresco/forms/controls/Select",
config: {
fieldId: "RECIPENT",
name: "recipient",
label: "Send to",
optionsConfig:{
publishTopic: "ALF_GET_FORM_CONTROL_OPTIONS",
publishPayload: {
url: url.context + "/proxy/alfresco/api/people",
itemsAttribute: "people",
labelAttribute: "firstName",
valueAttribute: "userName"
}
}
}
}]
}
}
]
}
},
{
name: "alfresco/logging/DebugLog",
}
]
}
}
]
};
dashlet get html ftl
<#markup id="widgets">
<#processJsonModel group="share-dashlets" rootModule="alfresco/core/Page"/>
</#>
<#markup id="html">
<div id="${args.htmlid?html}"></div>
</#>
dashlet get desc xml
<webscript>
<shortname>Dashlet</shortname>
<description>An Aikau dashlet</description>
<family>dashlet</family>
<url>/dashlets/messaging</url>
</webscript>
I slightly modified your code to fetch the users and displaying ina dropdown.
Let me try with Option Service and will update you.
Created a new function getUserList and called /api/people to get the data and displayed in the dropdown.
Hope this helps you now.
model.jsonModel = {
rootNodeId: args.htmlid,
pubSubScope: instance.object.id,
bodyHeight: "400px",
services: [
{ name: "alfresco/services/LoggingService",
config: {
loggingPreferences:{
enabled: false,
all: true
}
}
},
"alfresco/services/OptionsService"
],
widgets: [
{
name: "alfresco/dashlets/Dashlet",
config: {
title: "My Messages",
bodyHeight: args.height || null,
componentId: instance.object.id,
widgetsForTitleBarActions: [
{
id: "MESSAGING_DASHLET_ACTIONS",
name: "alfresco/html/Label",
config: {
label: "Title-bar actions"
}
}
],
widgetsForToolbar: [
{
id: "MESSAGING_DASHLET_TOOLBAR",
name: "alfresco/html/Label",
config: {
label: "Toolbar"
}
}
],
widgetsForBody: [
{
id: "HELLO_DASHLET_VERTICAL_LAYOUT",
name: "alfresco/layout/VerticalWidgets",
config: {
widgetWidth: "350px",
widgets: [
{ name: "alfresco/forms/Form",
config: {
showOkButton: true,
okButtonLabel: "Send",
showCancelButton: false,
okButtonPublishTopic: "PUBLISH_TOPIC_MESSAGE",
okButtonPublishGlobal: true,
widgets: [{
name: "alfresco/forms/controls/TinyMCE",
config: {
fieldId: "MESSAGE_TEXT",
name: "message",
label: "Message",
widgetWidth: 200
}
},
{
name: "alfresco/forms/controls/Select",
config: {
fieldId: "RECIPENT",
name: "recipient",
label: "Send to",
optionsConfig: {
fixed: getUsersList()
},
requirementConfig: {
initialValue: true
}
}
}
]
}
}
]
}
},
{
name: "alfresco/logging/DebugLog",
}
]
}
}
]
};
function getUsersList() {
try {
var result = remote.call("/api/people?sortBy=fullName&dir=asc");
var userList = [];
if (result.status == status.STATUS_OK) {
var rawData = JSON.parse(result);
if (rawData && rawData.people) {
var dummyPerson = {
label: "Select Recipient",
value: " ",
selected: true
};
userList.push(dummyPerson);
for (var x = 0; x < rawData.people.length; x++) {
var item = rawData.people[x];
if (item.firstName != null && item.firstName != "" && item.userName.indexOf("#") == -1 && item.enabled == true) {
var displayName = item.firstName + " " + item.lastName;
var person = {
label: displayName,
value: item.userName
};
userList.push(person);
}
}
}
} else {
throw new Error("Unable to fetch User List " + result.status);
}
return userList;
} catch(err) {
throw new Error(err);
}
}
I have a Meteor application with a Mongo database containing documents with the following structure:
_id: "1234567890",
blocks: [{
type: "block",
block_id: "foobar",
items: [
{
type: "sub",
sub_id: "111",
items: [
{
type: "question",
question_id: "aaa"
},
{
type: "question",
question_id: "bbb"
}
]
},
{
type: "question",
question_id: "aaa"
}
]
}]
I want to be able to find all the questions with a question_id of 'aaa'. So far I have tried these queries, but am struggling to return any results:
questions = MyColl.find({
$or: [{
blocks: {
items: {
$elemMatch: {question_id: 'aaa'}
}
}
},{
blocks: {
items: {
type: "sub",
items: {
question_id: 'aaa'
}
}
}
}]
}).count();
Any ideas?
This is how I mananged it:
questions = MyColl.find({
$or: [{
'blocks.items': {
$elemMatch: {question_id: 'aaa'}
}
},{
'blocks.items.items': {
$elemMatch: {question_id: 'aaa'}
}
}]
}).count();
I have combo box with some values. When i click the combo listed down the data. but there not align with combo box and popup listed.
any help
/**
* This is the combo box with common values
*/
var combo_1 = Ext.extend(Ext.form.ComboBox, {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px'
});
/**
* This is the form panal
*/
var form_panal = new Ext.form.FormPanel({
id:'form_panal',
frame:true,
bodyStyle:'padding:10px 10px 10px 10px',
buttonAlign:'center',
items: [
combo_1,
combo_2,
combo_3,
combo_4
],
buttons: [ {
text: 'Save',
handler : function(){
}
},
{text: 'Cancel',
handler : function() {
}
}
]
});
enter image description here
Here is the sample code
Ext.application({
name : 'Fiddle',
launch : function() {
var combo_1 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name',
valueField: 'name',
store: {
fields: [{
name: 'name'
}],
proxy: {
type: 'memory'
},
data: [{
name: 'Android'
},{
name: 'iOS'
}, {
name: 'Windows'
}]
}
});
var combo_2 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name1',
valueField: 'name1',
store: {
fields: [{
name: 'name1'
}],
proxy: {
type: 'memory'
},
data: [{
name1: 'Blue Star'
},{
name1: 'LLoyd'
}, {
name1: 'Samsung'
}]
}
});
var combo_3 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name2',
valueField: 'name2',
store: {
fields: [{
name: 'name2'
}],
proxy: {
type: 'memory'
},
data: [{
name2: 'Andhra pradesh'
},{
name2: 'Telangana'
}, {
name2: 'Karnataka'
}]
}
});
/**
* This is the form panal
*/
Ext.create('Ext.form.FormPanel',{
frame:true,
bodyStyle:'padding:10px 10px 10px 10px',
buttonAlign:'center',
items: [
combo_1,
combo_2,
combo_3
],
buttons: [ {
text: 'Save',
handler : function(){
}
},{
text: 'Cancel',
handler : function() {
}
}],
renderTo: document.body
});
}
});
I'm trying to call a function from initComponent. However, I'm unable to get the scope of this object, thus running into ReferenceErrors.
The function I'm calling is getFileType and it's missing the scope and I'm unable to get it. (line nos: 204).
Is there a way to change scope inside the handler.
Also, by adding scope:this inside the button, I'm losing scope to pick the form data...
Any help here would be awesome!
Ext.define('D.application.component.de.AddConnectionPanel', {
extend: 'Ext.form.FieldSet',
initComponent : function()
{
var databaseConnDetails = Ext.create('Ext.form.Panel',{
bodyPadding: 15,
// width:'auto',
region:'center',
layout:{
align: 'center',
},
defaults: {
anchor: '100%',
},
title: 'Database Details',
items: [{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqcombobox',
name: 'DB_TYPE',
emptyText: 'DB Type',
flex: 1,
fieldID: 'Field-1',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_1',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_URL',
emptyText: 'DB Url',
flex: 1,
fieldID: 'Field-2',
},
{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_PORT',
emptyText: 'DB Port',
flex: 1,
fieldID: 'Field-3',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_2',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_SCHEMA',
emptyText: 'Schema Name',
flex: 1,
fieldID: 'Field-4',
},
{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_LABEL',
emptyText: 'Schema Label',
flex: 1,
fieldID: 'Field-6',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_4',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqtextarea',
name: 'DB_DESCRIPTION',
emptyText: 'Connection Description',
flex: 1,
fieldID: 'Field-6',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_6',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_USERNAME',
emptyText: 'DB Username',
flex: 1,
fieldID: 'Field-5',
},
{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_PASSWORD',
inputType: 'password',
emptyText: 'DB Password',
flex: 1,
fieldID: 'Field-6',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_7',
},
{
defaults: {
},
items: [{
readOnly: true,
hidden: true,
xtype: 'dsqtextfield',
name: 'ID',
emptyText: 'Connection ID',
flex: 1,
fieldID: 'Field-6',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_8',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
width:70,
xtype: 'dsqbutton',
name: 'save',
fieldLabel: 'Save',
fieldID:'Field-8',
}],
layout: {
type: 'hbox',
align: 'middle',
pack: 'center'
},
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_9',
}],
xtype: 'dsqfieldset',
layoutID: 'Connection Details'
});
var fileConnDetails = Ext.create('Ext.form.Panel', {
bodyPadding:15,
defaults: {
anchor:'100%',
},
width:500,
title: 'File Details',
bodyPadding: 10,
frame: true,
renderTo: Ext.getBody(),
items: [{
xtype: 'filefield',
name: 'InputFile',
id:'filefield',
emptyText: 'File',
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Browse...'
}],
buttons: [{
text: 'Upload',
layout:{
pack:'center',
align:'middle',
},
handler: function() {
var form = this.up('form').getForm(); // Get form details
if(form.isValid()){
var fileName = form.findField('filefield').getSubmitValue();
// Check to see if file type is supported
var retVal = getFileType(fileName);
if (retVal != DSQ_SUCCESS){
Ext.Msg.alert('Unsupported File Type');
return;
}
// Parse file and read data
retVal = parseInputFile(fileName, fileArray);
if (retVal != DSQ_SUCCESS) {
Ext.Msg.alert('Error! unable to read file');
return;
}
form.submit({
success: function(fp, action) {
Ext.Msg.alert('Success', 'Your file "' + action.result.file + '" has been uploaded.');
},
failure: function(fp, action) {
Ext.Msg.alert('Failed', 'File "' + action.result.file + '" upload failed');
}
});
}
}
}]
});
var connectionInfo = Ext.create('Ext.container.Container', {
autoEl:'div',
width:700,
bodyPadding: 5, // Don't want content to crunch against the borders
layout:'card',
items:[{
id:'file_card',
items:[fileConnDetails],
},{
id:'db_card',
items:[databaseConnDetails],
}],
});
var DataSourceOptionsContainer = Ext.create('Ext.container.Container',{
region:'center',
layout:{
type:'vbox',
align: 'center',
},
items : [{
xtype:'radiogroup',
vertical:false,
columns:2,
items: [{
boxLabel: 'Flat-File',
name:'datasource',
inputValue:'flatfile',
width:80,
checked:true,
},{
boxLabel: 'Database',
name:'datasource',
inputValue:'database',
width:80
}],
listeners: {
change: function(radiogroup, newVal, oldVal) {
var listenerObj = newVal.datasource;
switch(listenerObj) {
case 'database':
connectionInfo.getLayout().setActiveItem('db_card');
break;
case 'flatfile':
connectionInfo.getLayout().setActiveItem('file_card');
break;
default:
console.log("No such Object in connection group");
break;
}
}
}
}],
});
var config = {
items: [DataSourceOptionsContainer, connectionInfo]
};
Ext.apply(this,config);
this.callParent(arguments);
},
getFileType: function(fileName)
{
var fileTypesAllowed = [".csv", ".xls", ".xlsb"];
alert("File Type verification");
if(!Ext.Array.contains(fileTypesAllowed, fileName)) {
return 1;
}
return 1;
},
parseInputFile: function(fileName, fileArray)
{
return 1;
},
onRender : function()
{
this.callParent(arguments);
}
});
Store the reference to the form panel object in this instead of using a local variable:
this.fileConnDetails = Ext.create('Ext.form.Panel', {
(you'll also have to replace further references to that variable in initComponent with this.fileConnDetails)
Then, as you suggested, add scope: this to your button. You'll then have both the form panel and your functions in the same scope:
buttons: [{
text: 'Upload',
layout:{
pack:'center',
align:'middle',
},
handler: function() {
var form = this.fileConnDetails.getForm(); // Get form details
if(form.isValid()){
var fileName = form.findField('filefield').getSubmitValue();
// Check to see if file type is supported
var retVal = this.getFileType(fileName);
if (retVal != DSQ_SUCCESS){
Ext.Msg.alert('Unsupported File Type');
return;
}
// Parse file and read data
retVal = this.parseInputFile(fileName, fileArray);
if (retVal != DSQ_SUCCESS) {
Ext.Msg.alert('Error! unable to read file');
return;
}
form.submit({
success: function(fp, action) {
Ext.Msg.alert('Success', 'Your file "' + action.result.file + '" has been uploaded.');
},
failure: function(fp, action) {
Ext.Msg.alert('Failed', 'File "' + action.result.file + '" upload failed');
}
});
}
},
scope: this
}]
getFileType is part of your class. You need to add:
scope: this,
handler: function() {
// ....
this.getFileType();
}