Appframe Knowledge Base


48 hits
2

How to use the appframe confirm dialog

af.controls.confirm({
                title: "title",
                message: "message",
                buttons: ["Yes", "No"],
				escape: 1,
                callback: function(index) {
                    if (index === 0) {
						//your code
                    }
                }
            });

components web · Perma link post comment Posted by: Peter Øren (14-jan-2013)

1

How to set background color on cell in afGrid

gridMyGrid.attachEvent("onFormatCellValue", function(pCell) {
	pCell.css.backgroundColor = "#f00";
});

components web · Perma link post comment Posted by: Jan Henrik H. Meling (27-nov-2012)

1

How to make a URL column into a link to that url

gridSomething.attachEvent("onFormatCellValue", function(pCell) {
    if (pCell.fieldName === "URL") {
        var vEscapedURL = af.common.htmlEscape(pCell.dataRow.URL);
        pCell.value = '<a href="' + vEscapedURL  + '">' + vEscapedURL + '</a>';
    }
});

components web · Perma link post comment Posted by: Jan Henrik H. Meling (21-okt-2013)

1

Repeater / Template Syntax

<!-- Everything inside <% %> is JavaScript, so you can use variables and if statements.
     If you want to use values from the current row, you can use the variable "row".
     If you want to have logic based on the row index, "i" is the zero based index.
     If you want to have logic based of the previous or next row, "data" is the array of rows. -->

<%if (row.SomeBitField === true) {%>
	<p>The variable is true</p>
<%} else {%>
	<p>The variable is not true</p>
<%}%>

<!-- Normally if you just want the escaped value of a field, you use this syntax: -->

<p><%=MyFieldName%></p>

<!-- If you need to replace something or process the value, you need to prefix the field name
     with "row.", as the un-prefixed version is only a shorthand that escapes for you.
     Make sure you escape the value before outputting it when using row.FieldName: -->

<p><%=af.common.htmlEscape(row.SomeField.replace("foo", "bar"))%></p>
<p><%=af.common.stringifyValue(row.FieldA || row.FieldB)%></p>

components web · Perma link post comment Posted by: Martin Vaaden (11-jun-2014)

0

How to use the filter object in javascript

// some variables to be used as part of filter criteria
var vCurrentMonday = new XDate(+$("#weeks").val()),
	vOrderItem = $("#orders").val();

// defining the filter object
dsTimesheet.setParameter("filterObject", {
	type: "group", mode: "and", items: [
		{ type: "expression", column: "WeekStarting", operator: "equals", valueType: "datetime", value: vCurrentMonday },
		{ type: "expression", column: "OrderItemTemplate", operator: "equals", valueType: "string", value: vOrderItem }
	]
});

// refresh the data source to get data using the filter
dsTimesheet.refreshDataSource();

// Alternatively you can build the filter string yourself,
// but then you need to make sure you escape and format the values properly
dsTimesheet.recordSource.setFilterString("WeekStarting = '" + af.common.formatByMask(vCurrentMonday, "sql_date_time") + "' AND OrderItemTemplate = '" + vOrderItem.replace(/'/g, "''") + "'");

components dataobject web · Perma link post comment Posted by: Torgeir Fredriksen (29-nov-2012)

0

How to navigate between pages using tab control (pages mode)

<!-- In order to navigate to other tab pages in your app you need to set the href attribute
     on the on the anchor element to the page you would like to navigate to.
     In addition you should also add the fieldname as part of the url (to generate a permalink).
     It should be set on the same element as used for currency binding. -->

<a href="#tabsMain_Page2&IssueID=<%=IssueID%>" data-index="<%=i%>">

components web · Perma link post comment Posted by: Peter Øren (27-feb-2014)

0

Align the text in a grid with the top due to multi-line text expanding box

/* Align the text in the bottom grid with the top due to multiline text expading the box  */
#gridAttachmentLog div.afGridBody table tbody tr td {
	padding-top: 2px;
	vertical-align: top;
}
#gridAttachmentLog div.afGridBody table tbody tr.selected td {
	padding-top: 2px;
	vertical-align: top;
}

/* note #gridAttachmentLog needs to be altered to be the name of the grid object */

components web · Perma link post comment Posted by: Luke Simcock (25-nov-2013)

0

Binding ComboBox in a form to show items from a custom data object

// For how to define an array data object, see: http://kb.omega.no/kb/1240

// For this to work properly, the field must be defined without LookupID and ListBoxID
// in the form panel designer in the app designer.

// Get a reference to the field
var vMyField = formMain.getFields("IssueType");

// Define the ComboBox instance and pass in the data object
vMyField.comboBox = new af.controls.ComboBox({
    input: vMyField.getInput(),
    limitToList: true,
    dropdown: af.controls.DropdownList,
    dataObject: vDataObject,
    displayMember: "Type",
    valueMember: "Type",
    clearable: false
});

// Push the selected value into the form's data object, or call the form's callback
vMyField.comboBox.attachEvent("onValueChanged", function (pValue) {
    if (vMyField.validDataObjectField) {
        vDO.currentRow(vMyField.data.FieldName, pValue);
    } else if (typeof vMyField.callback === "function") {
        vMyField.callback();
    }
});

// Makes the ComboBox not broken
$(vMyField.getInput()).attr("type", "afComboBox");

components web · Perma link post comment Posted by: Jan Henrik H. Meling (13-nov-2013)

0

How to define a DataObject which reflects the contents of an Array

// Define the array containing the initial data 
var vArrayOfObjects = [
    { Type: "Issue" },
    { Type: "Suggestion" }
];

// Define the array data handler that uses the array we just declared
var vArrayDataHandler = new af.data.ArrayDataHandler(vArrayOfObjects, ["Type"]);

// Define the data object that uses the array data handler we just defined
var vArrayDataObject = new af.DataObject({
    dataHandler: vArrayDataHandler,
    selectFirstRow: false,
    fields: [{ name: "Type", type: "string" }]
});

// If you want to add items:
vArrayOfObjects.push({ Type: "Secret Type" });
vArrayDataObject.refreshDataSource();

// If you want to remove items:
vArrayOfObjects.splice(0, 1);
vArrayDataObject.refreshDataSource();

// If you want to modify items:
vArrayOfObjects[0] += " Item";
vArrayDataObject.refreshDataSource();

components web · Perma link post comment Posted by: Jan Henrik H. Meling (13-nov-2013)

0

How to manipulate form fields

// Get and set the caption of a field
var vOldCaption = formMain.getFields("FieldName").caption();
formMain.getFields("FieldName").caption("New caption");

// Get and set the disabled state of a field
formMain.getFields("FieldName").disabled();
formMain.getFields("FieldName").disabled(true || false);

// Get and set the visible state of a field
formMain.getFields("FieldName").display();
formMain.getFields("FieldName").display(true || false);

// Hide and show a field
formMain.getFields("FieldName").hide();
formMain.getFields("FieldName").show();

// Get and set the value of a field
formMain.getFields("FieldName").value();
formMain.getFields("FieldName").value("New value");

// Get a reference to the af.controls.ComboBox instance of a field
var vComboBox = formMain.getFields("SomeComboBoxField").comboBox;

// Get references to the different html-elements of a field
// Normally you should not have to do things directly on the html element
// but it you really have to, this is the way to do it
var vFieldElement = formMain.getFields("FieldName").getElement();
var vLabelElement = formMain.getFields("FieldName").getLabel();
var vInputElement = formMain.getFields("FieldName").getInput();

components web · Perma link post comment Posted by: Jan Henrik H. Meling (22-okt-2013)

0

How to set caption of field in form

formSomething.getFields("FieldName").caption("Your new caption");

components web · Perma link post comment Posted by: Jan Henrik H. Meling (22-okt-2013)

0

How to define a filter object in JavaScript

// For the filter to be compatible with the filter builder it must be 
// an or-group containing and-groups containing filter expressions.
// If you do not need to support opening the defined filter in the filter builder,
// you can use any structure and it will work when applied to a data object.

var vFilterObject = {
    type: "group",
    mode: "and" || "or",
    items: [
        { /* Groups can be nested in groups to get all possible "and/or" combinations */
            type: "group",
            mode: "and" || "or",
            items: [/* and so on */]
        },
        { /* Expressions having one of these operators must have a single value and its corresponding valueType */
            type: "expression",
            column: "MyColumnName",
            operator:   "equals"
                    ||  "notequals"
                    ||  "greaterthan"
                    ||  "greaterthanorequal"
                    ||  "lessthan"
                    ||  "lessthanorequal"
                    ||  "beginswith"
                    ||  "notbeginswith"
                    ||  "endswith"
                    ||  "notendswith"
                    ||  "contains"
                    ||  "notcontains"
                    ||  "like"
                    ||  "notlike"
                    ||  "dateequals"
                    ||  "timeequals"
                    ||  "timebefore"
                    ||  "timeafter",
            value: "Some value" || 12345 || new Date(),
            valueType: "string" || "number" || "datetime" || "uniqueidentifier"
        },
        { /* Expressions having one of these operators must have value = null and valueType = "null" */
            type: "expression",
            column: "MyColumnName",
            operator:   "isnull"
                    ||  "isnotnull"
                    ||  "istrue"
                    ||  "isfalse"
                    ||  "isblank"
                    ||  "isnotblank",
            value: null,
            valueType: "null"
        },
        { /* Expressions having one of these operators must have an array of two values of a common valueType */
            type: "expression",
            column: "MyColumnName",
            operator:   "between"
                    ||  "notbetween"
                    ||  "timebetween"
                    ||  "timenotbetween",
            value: [
                "a" || 1 || new Date(Date.now() - 1000*60*60*24),
                "z" || 1000 || new Date()
            ],
            valueType: "string" || "number" || "datetime" || "uniqueidentifier"
        },
        { /* Expressions having one of these operators can have one of more values in an array of a common valueType */
            type: "expression",
            column: "MyColumnName",
            operator:   "inlist"
                    ||  "notinlist",
            value: [
                "a" || 1 || new Date(Date.now() - 1000*60*60*24*1),
                "b" || 2 || new Date(Date.now() - 1000*60*60*24*2),
                "c" || 3 || new Date(Date.now() - 1000*60*60*24*3),
                "d" || 4 || new Date(Date.now() - 1000*60*60*24*4),
                "e" || 5 || new Date(Date.now() - 1000*60*60*24*5),
            ],
            valueType: "string" || "number" || "datetime" || "uniqueidentifier"
        }
    ]
};

// NOTE: All the pipes ( | ), are just there to indicate your possibilities,
// and should not actually be present in your filters
        
// If you want to validate the filter, turn it into SQL client-side, or apply it on an array, you can use the af.Filter class
var vFilterInstance = new af.Filter(vFilterObject);

vFilterInstance.toSQL(); // returns the filter as an SQL

var vArrayOfRows = [{ MyColumnName: "Some value" }];
vFilterInstance.filter(vArrayOfRows); // would filter the array using the defined filter

components web · Perma link post comment Posted by: Jan Henrik H. Meling (18-okt-2013)

0

afGridLookup vs afGridLookupEdit vs afLookupEdit

<u>afGridLookup (Preferred):</u> <ul> <li>RecordSource in Lookup / onDemand</li> <li>DevExpress Grid Functionality</li> </ul> <u>afGridLookupEdit:</u> <ul> <li>DevExpress Grid functionality</li> <li>RecordSource bound in application</li> </ul> <u>afLookupEdit</u> <ul> <li>Standard Lookup without DevExpress grid functionality</li> <li>RecordSource bound in application</li> </ul>

components win · Perma link post comment Posted by: Jan Christian Brataas (09-okt-2013)

0

How to set currency binding on repeater

In order to get currency binding on a repeater you need to use the attribute named data-index.
By utilizing this property currenty binding will be enabled. Once an repeating element is clicked the underlaying 
dataobject will change it's index.

<div  data-index="<%=i%>">
	This is the repeating element
</div>

components web · Perma link post comment Posted by: Peter Øren (31-jul-2013)

0

How to update and save current data object row in JavaScript

// First update the values you want to save
dsSomething.currentRow("SomeField", "NewValue");
dsSomething.currentRow("OtherField", "OtherValue");

// The use one of the following depending on the situation
dsSomething.endEdit(); // Fire and forget
dsSomething.endEdit(function() { /* do something after */ }); // Asynchronously
dsSomething.endEdit(function() { /* do something after */ }, true); // Synchronously

components dataobject web · Perma link post comment Posted by: Torbjørn Mevik (15-jul-2013)

D. Young Hoang :
dsSomething.endEdit(function(eErr, eData) { if (eErr === null) { alert('Successfully saved.'); } else { alert('Something went wrong. Please try again(' + eErr + ')'); } }, true); (06-jul-2018)
0

How to get toolbar buttons

//get top level buttons 
myToolbar.getButtons('ParentID');

//get nested buttons
myToolbar.getButtons('ParentID').getButtons('ChildID');

components web · Perma link post comment Posted by: Øystein Kaldestad (15-apr-2013)

0

How to set filterString, whereClause, filterObject and whereObject on a data object in JavaScript

// Setting of whereClause and filterString as strings is no longer recommended and may be removed in the near future.
// If an AppSetting called DisableClientSideFilterStrings is set to true, filterString and whereClause will be ignored.

// To set filterString
ds.setParameter("filterString", vFilter);
ds.recordSource.setFilterString(vFilter);

// To set whereClause
ds.setParameter("whereClause", vFilter);
ds.recordSource.setWhereClause(vFilter);

// NOTE: There is a separate kb article on how to define a filter object

// To set filterObject
ds.setParameter("filterObject", vFilterObject);
ds.recordSource.setFilterObject(vFilterObject);

// To set whereObject
ds.setParameter("whereObject", vFilterObject);
ds.recordSource.setWhereObject(vFilterObject);

// Setting filter will not automatically refresh the datasource
// So you will have to call refreshDataSource after setting the filter
ds.refreshDataSource();

components dataobject web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to show/hide toolbar buttons

//hide button
myToolbar.getButtons("MyButton").hide();

//show button
myToolbar.getButtons("MyButton").show();

components web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to change caption on toolbar buttons

//change caption if a button have a dependency
toolbarMain.getButtons("myButton").caption("newCaption");

components web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to remove toolbar buttons

myToolbar.removeButton("ButtonName");

components web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to add new buttons to the toolbar

// Settings ActionID,ButtonStyle,Caption,HasSeparator,Icon,ParentID,Tooltip,Type
myToolbar.addButton({ActionID:'NewButton',Type:'Button',Tooltip:'New button!',Caption:'New Button'});

components web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to enable/disable toolbar buttons

myToolbar.getButtons("buttonID").disabled(true); // true/false

components web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

Show sharing dialog

var myshareDialog = new af.controls.ShareDialog({
    panes: ["Reader", "Editor", "Manager"],
    searcher: searchfunction,
    callback: callbackfunction,
    readOnly: false //true/false
});

myshareDialog.show();

components web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to prompt user with a short message

//Display notification (click the notification text to close)
af.controls.notify('Mail sent!');
// notify returns a function which you can call at a later point to close the notification

//Display notification for a certain duration
setTimeout(af.controls.notify('This message will be displayed for 3 seconds.'), 3000);

components web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to get number of rows

//will return the number of rows available / loaded
//it will not return the total number of rows the table/view contains
//if you want the total number of rows, you need to set maxRecords to -1 and reload first
ds.getDataLength();

// ds.getData() is a heavy operation, so if you are going to iterate over a limited number of rows,
// use ds.getDataLength() and ds.getData(index) for much better performance.

components dataobject web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to set field value on current row

//Set value of a field in the current row
ds.currentRow(vFieldName, vNewValue);

components dataobject web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to get current row's data

//Get the whole current row as an object
ds.currentRow();

//Get value of a specific field in the current row
ds.currentRow("SomeField");

components dataobject web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to get current row index

//Get current Index
ds.getCurrentIndex();

components dataobject web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to set current row index

//Set Current Index
ds.setCurrentIndex(vIndex);

components dataobject web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)

0

How to make buttons float to right in Toolbar

/* Not recommended, but if you really want to: */
ul#toolbarMain.afToolbar.Horizontal {
	li.group, li.item, li.separator {
		float: right;
	}
}

components web · Perma link post comment Posted by: Jan Henrik H. Meling (10-apr-2013)

0

Listen for changes on a field

// The listener is attached to the data object, and will not be
// triggered when the current index is changed.

dsStuff.attachEvent("onFieldChanged", function (pField) {
	if (pField.name === "FieldName") {
		// Do stuff
	}
});

components dataobject web · Perma link post comment Posted by: Jarl Erik Schmidt (20-feb-2013)

0

Show and hide Form items

// Hide single item
formSomething.getFields('InputOne').hide();

// Hide multiple items
formSomething.getFields(['InputOne', 'InputTwo', ..., 'InputOneHundred']).hide();

// Show single item
formSomething.getFields('InputOne').show();

// Hide multiple items
formSomething.getFields(['InputOne', 'InputTwo', ..., 'InputOneHundred']).show();

components web · Perma link post comment Posted by: Jarl Erik Schmidt (19-feb-2013)

0

How to use prompt in Appframe

	af.controls.prompt({
            title: "Add Period",
            message: "Enter period for monthly points",
            defaultValue: ((new Date()).getFullYear() * 100) + (new Date()).getMonth()+1,
            callback: function(pPeriod) {
				af.article.procedures.procAddMontlyPoints.execute({"Period": pPeriod}, function (e,res){
					alert("Montly points added");
				}, "", true);
            }
        });

components web · Perma link post comment Posted by: Peter Øren (29-jan-2013)

0

How to trigger loading of data object

dsMyDataObject.refreshDataSource();

components dataobject web · Perma link post comment Posted by: Peter Øren (05-okt-2012)

0

Ho to use a DropdownBase sub-class instance

var vComboBox = new af.controls.ComboBox({
    dropdown: null // Replace null with a reference to an instance of a dropdown
});

/*
// Example code to replace the combobox into the dom
$($0).replaceWith(vComboBox.getElement())
*/

components web · Perma link post comment Posted by: Jan Henrik H. Meling (05-okt-2012)

0

Sub for applying filesize formatting to controls [afFileGrid]

    Private Sub ApplyFileSizeFormatting(ByRef FSGridColumn As Appframe3.Win.Controls.Utils.afGrid.afGridColumn)
        FSGridColumn.DisplayFormat.Format = New Appframe3.Win.afFileGrid.Utils.afFileGridFileSizeFormat()
        FSGridColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom
        FSGridColumn.DisplayFormat.FormatString = "FileSize"
    End Sub

components win · Perma link post comment Posted by: Aleksander Hansen Birkeland (12-sep-2012)

0

Resetting values to their saved state in data object

/* To set reset values to their saved state you only need to call 
   cancelEdit if you want to reset all fields, or
   cancelField if you want to reset just one field */

dsMyDataObject.cancelEdit();

dsMyDataObject.cancelField("MyFieldName");

components dataobject web · Perma link post comment Posted by: Jan Henrik H. Meling (30-jul-2012)

0

Setting default values when moving to a new record in data object

/* To set default values when focusing "new row",
   attach an event to the data object's onCurrentIndexChanged event
   and set the default values using this.currentRow(pFieldName, pValue); */

dsDataObject.attachEvent("onCurrentIndexChanged", function(pIndex) {
    if(pIndex === -1) { // index is -1 when "new row" is active
        // "this" is a reference to the data object inside this scope
        this.currentRow("FieldName", "My Default Value");
    }
});

components dataobject web · Perma link post comment Posted by: Jan Henrik H. Meling (14-mai-2012)

0

Using af.controls.Dialog - Accessing a Form or Grid inside a designer created dialog

/* Lets assume you have a dialog named MyDialog defined in your article, 
   and that dialog has a Form inside it. If you need to do something with the
   form when the dialog is shown, you can access the javascript object like this: */

MyDialog.show(function() {
    var vForm = this.content; // "this" is a reference to MyDialog when inside the show callback
    // Now you can do whatever you want to the form via the vForm reference

});

components web · Perma link post comment Posted by: Jan Henrik H. Meling (14-mai-2012)

0

Using af.controls.Dialog - Create via code with custom buttons and content

var vContent = $('<label style="display: inline-block; padding: 10px 20px 20px 20px;">First name:<input style="display: block;"></label>');
var vDialog = new af.controls.Dialog({
    overlay: { clickCloses: true }, // does what you'd expect
    buttons: { close: true }, // enables the close button in the header
    title: "My Test Dialog",
    content: vContent,
    destroyOnClose: true, // will dispose of the dialog after it closes
    buttonbar: [
        { text: "I have entered my first name", highlight: true,
            click: function() {
                alert("Your name is: " + $(vDialog.getElement()).find("label > input").val());
                vDialog.close();
            }
        },
        { text: "Get me out of here", click: function() { vDialog.close(); } }
    ]
});

vDialog.show();

components web · Perma link post comment Posted by: Jan Henrik H. Meling (14-mai-2012)

0

How to attach event on current-row changed in data object

dsDataObject.attachEvent("onCurrentIndexChanged", function (pIndex) {
	var row = this.currentRow();
});

components dataobject web · Perma link post comment Posted by: Torgeir Fredriksen (09-mai-2012)

0

Show a link in a grid that triggers a Javascript function when clicked

// Attach to onFormatCellValue to produce an anchor element with a class
gridName.attachEvent("onFormatCellValue", function(pCell) {
    var vEscaped = af.common.stringifyValue(pCell.dataRow.Name);
	pCell.value = '<a class="myLink" href="#">' + vEscaped '</a>');
});

// You can abstract out the things you want to do when you click the link
// in a separate function that takes the arguments you need
function sayHi(pName) {
	alert('Hello there from row with name ' + pName + '!');
}

// Create a jQuery delegate/event on the root element of the grid
// and have the selector for the anchor element with that class
$(gridName.getElement()).on("click", "a.myLink", function(e) {
    // Go from the triggering element up to the nearest <tr>, and determine the index
    var vTr = $(this).closest("tr"),
        vDataIndex = vTr.data("index"),
        vDataObject = myGrid.getDataObject(),
        vRowData;
    
    // If you only need one field it is adviced to use getData(index, fieldName)
    sayHi(vDataObject.getData(vDataIndex, "Name"));
    
    // If you need many fields, you can exclude the fieldName parameter and get the whole row object
    vRowData = vDataObject.getData(vDataIndex);
    sayHi(vRowData.Name, vRowData.SomeOtherColumn);    
        
    return false; // Prevents browser from following the link
});

components web · Perma link post comment Posted by: Jarl Erik Schmidt (19-apr-2012)

0

JavaScript Conventions - Article Script

// Now support importing of templates or other scripts like this:
"import /static/template/af.common.templates.someTemplate.js";

// Standard function scope. Not really necessary when debugging.
(function(scope,undef){
	var w = scope.window, $ = w.jQuery,
		vAny, vVariables, vYou, vMight, vNeed;

	function anyCommonFunctions(pYouMightNeed) {
		return "somethingUseful";
	}

	$("div.someClass").append(c.runTemplate(af.common.templates.someTemplate, {
		TemplateField: "someValue",
		OtherField: 12345
	}, {
		CustomField: function(pData) {
			return pData.TemplateField + pData.OtherField;
		}
	}));

	// Remember to include some comments for non-obvious things

}(this));

components web · Perma link post comment Posted by: Jan Henrik H. Meling (08-mar-2012)

0

JavaScript Conventions - Inheritance

(function(scope, undef) {
    "use strict";
	
	var w = scope.window, af = w.af, c = af.common;

	function MyChildControl() {
        var that = this, priv = {
            myVariable: 54321
        };
    }
	/* The line below will create an instance of the control you want to inherit from,
       and assign it to the prototype property of your constructor. */
	MyChildControl.prototype = new af.controls.MyControl();
	
	// Remember to only expose what you want exposed
	c.expose("af.controls", MyChildControl);
	
}(this));

components web · Perma link post comment Posted by: Jarl Erik Schmidt (08-mar-2012)

0

JavaScript Conventions - Controls

/* First we create a function scope with two parameters, one is the scope ("this" in this context),
   the other is undefined, which will always be undefined even if someone does window.undefined = true; */
(function (scope, undef) {
    "use strict"; // This will enable ES5 strict-mode for browsers that support this

	/* Then we have this one line which should contain any needed references to other libraries
       and any shared variables that should be shared between instances of your control.
       af.common contains common functions used everywhere in web4, and should always be present */
    var w = scope.window, d = w.document, af = scope.af, c = af.common, shared = { instanceCount: 0 };
	// is using jQuery, you should add   $ = scope.jQuery,   as a variable above

    /* We capitalize first letter for constructors and use camelCasing for the rest
       If your constructor takes options, they should always be object literals:
       { myOption: "hello", important: true } */
	/* By including a comment using the format shown below, documentation can be automatically generated for your control */
    function MyControl(pOptions) {
        /**
         * A short description of your control, for use in documentation
         * or just so others know when looking at your code.
         * @param {object} pOptions An object literal containing options for your control
         * @return {MyControl} Returns an instance of MyControl when called using the new operator
         * @constructor
         */

        /* "that" refers to the instance of this constructor, and is used for exposing or accessing public
           properties or functions. "priv" is an object literal containing any local variables. */
        var that = this, priv = {
			options: new c.Options({ // instantiate the common Options class
				defaults: {
					myOption: "hey",
					otherOption: 2
				},
				required: ["important"], /* this will make your constructor throw an exception if the
                                           option called "important" is not passed to pOptions */
				// deepMerge: ["data"], // If you need to merge in depth
				// mergeDepth: 2, // you can use these two options
				passed: pOptions // this sends in the passed options to the Options class for checking
			}),
			eventHandler: new c.EventHandler(that, { // Include this if you need events for your control
                onSomething: { abortable: false } /* Setting abortable to true will allow an event to
                                                    stop execution of subsequent events by returning false. */
			}),
			element: null, /* If you are making a visual control, it is good to have a private variable
                              to keep a reference to the generated root element of your control. */
			someOtherVariable: 12345
        };

		/* The three functions below are shortcut functions, and should be included and used when using events */
        function fireEvent(pEvent, pArgs, pModifiableArgs) { return priv.eventHandler.fire(pEvent, pArgs, pModifiableArgs); }
        function attachEvent(pEvent, pFunc) { return priv.eventHandler.attach(pEvent, pFunc); }
        function detachEvent(pEvent, pFunc) { return priv.eventHandler.detach(pEvent, pFunc); }

		/* All functions that are not constructors should be camelCased.
           Try to keep the size of a function under 40 lines if possible
           by refactoring into smaller functions and reusing code. */
        function someFunctionWeKeepToOurselves() {
			return 123;
		}

		/* By including a comment using the format shown below, documentation can be automatically generated for your control */
		function someFunctionWeWantExposed(pSomeParameter) {
            /**
             * A function that returns a fixed string joined with the passed string using a dash.
             * @param {string} pSomeParameter The string you want appended to the fixed string
             * @return {string} A fixed string and the passed string joined with a dash.
             */
			var vSomeVariable = "used only by code in this function";
			return [vSomeVariable, pSomeParameter].join(" - ");
		}

		function initialize() { // Initialization code
			// Use of shared variable inside the instance
			shared.instanceCount++;

			// Use of private variable inside the instnace
			priv.myPublicVariable += 50;
		}

		// Expose the functions you want available on the instance here
		that.someFunctionWeWantExposed = someFunctionWeWantExposed;
		// If you have many functions, use this method instead
		//c.expose(this, [attachEvent, detachEvent, someFunctionWeWantExposed, andSoOn];

		initialize(); // Finally we run the initialization code
	}

	c.expose("af.someNameSpace", MyControl); // Expose you control to a namespace

}(this)); // This will refer to window when using a browser

components web · Perma link post comment Posted by: Jarl Erik Schmidt (08-mar-2012)

0

How to upload files using javascript (plupload)

var vUploader = new af.controls.Uploader({
    autoUpload: true,
    showUploadButton: false,
    dataSourceId: "dsSomething",
    initialize: true
});

vUploader.show();
vUploader.setBindings({ IssueId : dsIssues.currentRow("IssueID") });

vUploader.attachEvent('onUploadComplete', function() {
    dsFiles.refreshDataSource();
    vUploader.close();
});

components web · Perma link post comment Posted by: Peter Øren (18-jan-2012)

0

How to set sortorder on dataobject

dsKnowledge.recordSource.setSortOrder([{Created:'desc'}]);
dsKnowledge.setParameter("sortOrder", [{Created:'desc'}]);

components dataobject web · Perma link post comment Posted by: Peter Øren (17-jan-2012)

0

How to execute a procedure from javascript

// Fire without parameters
procMyProcedure.execute();

// Fire without parameters synchronously
procMyProcedure.execute(true);

// Fire without parameters with callback
procMyProcedure.execute(function(err, data) {
    if (err === null) {
        // use data
    } else {
        alert(err);
    }
});

// Fire without parameters synchronously with callback
procMyProcedure.execute(function(err, data) {
    if (err === null) {
        // use data
    } else {
        alert(err);
    }
}, true);

// Fire and forget
procMyProcedure.execute({
    Param1: "foo",
    param1: 12345
});

// Fire using callback
procMyProcedure.execute({
    Param1: "foo",
    param1: 12345
}, function(err, data) {
    if (err === null) {
        // use data
    } else {
        alert(err);
    }
});

// Fire synchronously
procMyProcedure.execute({
    Param1: "foo",
    param1: 12345
}, true);

// Fire synchronously with callback
procMyProcedure.execute({
    Param1: "foo",
    param1: 12345
}, function(err, data) {
    if (err === null) {
        // use data
    } else {
        alert(err);
    }
}, true);

components web · Perma link post comment Posted by: Peter Øren (16-jan-2012)