var login = af.userSession.login; var name = af.userSession.name; // Surname, Firstname var emailAdress = af.userSession.email; var currentDomain = af.userSession.domain;
common web · Perma link post comment Posted by: Jarl Erik Schmidt (10-mai-2012)
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: "Omega", width: 1200, height: 650, content: "http://www.omega.no/", destroyOnClose: true // will dispose of the dialog after it closes }); vDialog.show();
common web · Perma link post comment Posted by: Jan Henrik Høiland Meling (14-mai-2012)
/* If localStorage is not supported by your browser, the settings will be kept in memory and reset on reload. If you need to check if your settings will be persisted, you can use this command to test for support: */ af.common.localStorage.isPersisted(); // > true /* When getting a setting and the value does not exist you can specify a default value as the second parameter and that value will be returned if no data is in the localStorage */ af.common.localStorage.get("mySetting", "myDefaultValue"); // > "myDefaultValue" /* Values that are stored in localStorage gets stored per article by reading the af.article.id value, so make sure this is correct */ af.common.localStorage.set("mySetting", "someOtherValue"); // > undefined /* You can also remove individual keys */ af.common.localStorage.remove("mySetting"); // > true /* Or you can clear everything beeing stored for the active article */ af.common.localStorage.clear(); // > undefined
common web · Perma link post comment Posted by: Jan Henrik Høiland Meling (14-mai-2012)
// Shows a "busy" indicator and returns a function that hides it: var hideIndicator = af.controls.working("Doing lengthy operation..."); // Normally you'd call hideIndicator() in the complete/error function // of jQuery.ajax, pCallBack/pOnError in af.data.execProcedure, etc. // Here we just call it after 3000 milliseconds: var afterWorkComplete = function() { hideIndicator(); } setTimeout(afterWorkComplete, 1000);
common web · Perma link post comment Posted by: Jarl Erik Schmidt (10-mai-2012)
//used to copy/clone a value (supports values/arrays/objects) //note : if you know the type you should use copyArray/copyObject instead var firstValue = 'test', newValue = af.common.copyValue(firstValue);
common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)
// Used for making a copy/clone of an existing object var firstObject = { id: "myObject", title: "test" }, newObject = af.common.copyObject(firstObject); // newObject will now be a clone of firstObject // The function clones recursively, so be careful to // not pass in objects that have a reference to them selves.
common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)
// Used for making a copy/clone of an existing array var firstArray = ["A", "B", "C"], newArray = af.common.copyArray(firstArray); // newArray will now be a clone of firstArray // The function clones recursively, so be careful to // not pass in arrays that have a reference to them selves.
common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)
//Called without any parameters creates a totally empty object // (even without the Object prototype if your browser supports it) var vEmptyObject = af.common.createObject(); // vEmptyObject.hasOwnProperty will not be present here in modern browsers // You can also create an object based on another object var vOtherObject = { foo: 1, bar: 2 }; af.common.createObject(vOtherObject); // Returns an object with the keys and values of the object passed in // Can also be used to make an array into an object var vArray = ["a", "b", "c"]; af.common.createObject(vArray); // Returns the array as an object {0: "a", 1: "b", 2: "c"}
common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)
var myArray = [1,2,3,4,5]; //[1, 2, 3, 4, 5] af.common.arrayRemoveAt(myArray,2,3); //Removes items 3 and 4 from the array [1, 2, 5] af.common.arrayRemoveAt(myArray, 1); // Removes item at position 1 from the array [1, 5];
common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)
//Format string var vRecord = 7,vTotalRecords=10; af.common.formatString("Viewing record {0} of {1}", vRecord, vTotalRecords); //Returns Viewing record 7 of 10
common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)
//----- Format as date ----- //Format dates using default format af.common.format(new Date(),{type:'date'}); //Returns date formatted as dd-MMM-yyyy (i.e 10-apr-2013) //Format dates using custom format af.common.format(new Date(),{type:'date',format:'dd-MM-yy'}); //Returns date formatted as dd-MM-yy (i.e 10-04-13) //Format date including time (UTC is used by default if not specified) af.common.format(new Date(),{type:'date',format:'dd-MM-yy hh:mm'}); //Returns UTC date and time formatted as dd-MM-yy hh:mm (i.e 10-04-13 04:41) //Format date including time and not using UTC format (UTC is used by default if not specified) af.common.format(new Date(),{type:'date',format:'dd-MM-yy hh:mm',utc:false}); //Returns non-UTC date formatted as dd-MM-yy hh:mm (i.e 10-04-13 04:41) //----- Format as filesize (specified in byte) note: only supports up to 1000 TB ----- af.common.format('1.2345',{type:'filesize',decimals:2}); //Returns 1.23 B af.common.format('1024',{type:'filesize',decimals:2}); //Returns 1 KB (decimals will not be shown when 0 is returned for all decimals, so 1.00 but will be shown as 1) af.common.format('1048576',{type:'filesize'}); //Returns 1 MB //----- Format strings ----- // Can be used to format strings that for example have been translated af.common.format("Record {0} of {1}", vIndex + 1, vTotal); // Calling when vIndex = 0 and vTotal = 100 returns: // "Record 1 of 100"
common web · Perma link post comment Posted by: Øystein Kaldestad (12-apr-2013)
/* Calling af.common.runTemplate passing a template and an object containing the data you want in your template and/or an object of custom handlers that should be run when the templates is replacing the field having that name. Values in the data object get escaped, while the return values of any custom handlers do not. Custom handlers are used instead of data if present. */ var vTemplate, vResult, vData = { ID: "TheDivId", Text: "A test text string" }; vTemplate = '<span id="<%=ID%>"><%=Text%> - <a href="<%=Link%>">Click me</a></span>'; vResult = af.common.runTemplate(vTemplate, vData, { Link: function(data) { // Note: passing data from database into a javascript link like this // could result in XSS security holes if not escaped. Be careful! return "javascript:alert('" + data.Text + "');"; } });
common web · Perma link post comment Posted by: Jan Henrik Høiland Meling (05-okt-2012)
/* Calling the af.common.unFormatByMask function, passing a date string and format mask will try to parse the date string into a date object using the passed format mask. */ var vDateString = "Saturday the 6th of October 2012 at 09:30:00"; af.common.unFormatByMask(vDateString, "dddd 'the' dS 'of' MMMM yyyy 'at' HH:mm:ss"); // Returns a date object: Sat, 06 Oct 2012 09:30:00 GMT
common web · Perma link post comment Posted by: Jan Henrik Høiland Meling (05-okt-2012)
var vDate = new XDate(2012, 9, 6, true); /* Calling the af.common.formatByMask, passing a date and a format string, will look for the format alias in af.userSession and use that if present. */ af.common.formatByMask(vDate, "Short Date"); // Returns: "06.10.2012" (or whatever the short-date format is for your culture) /* Calling the af.common.formatByMask function, passing a date and format string which is not in af.userSession will just use the provided format string. */ af.common.formatByMask(vDate , "dddd 'the' dS 'of' MMMM yyyy"); // Returns: "Saturday the 6th of October 2012" /* Calling the af.common.formatByMask, passing a number and a format alias, will look for the format alias in af.userSession and use that if present. */ af.common.formatByMask(0.53, "%"); // Returns: "53%" af.common.formatByMask(1.25e6, "123.12k"); // Returns: "1.25M" af.common.formatByMask(5123.24, "1 234.1"); // Returns: "5 123,2"
common web · Perma link post comment Posted by: Jan Henrik Høiland Meling (05-okt-2012)
/* Calling the af.common.getObjValues function on an object will return all its values as an array. The order of the values is the order they were added to the object. */ af.common.getObjKeys({ a: 1, b: 2, c: 3 }); // Returns: [1, 2, 3]
common web · Perma link post comment Posted by: Jan Henrik Høiland Meling (05-okt-2012)
/* Calling the af.common.getObjKeys function on an object will return all its keys as an array of strings. The order of the strings is the order they were added to the object. */ af.common.getObjKeys({ a: 1, b: 2, c: 3 }); // Returns: ["a", "b", "c"]
common web · Perma link post comment Posted by: Jan Henrik Høiland Meling (05-okt-2012)
/* Calling af.common.extend will take the first object, and merge any subsequent objects into the first one, overwriting any previous values having the same key. The function returns the modified first parameter. */ var vMyObject = { myItem: true, secondItem: 1 }; af.common.extend(vMyObject, { secondItem: 2, newItem: "Hi" }); // vMyObject is now: { myItem: true, secondItem: 2, newItem: "Hi" }
common web · Perma link post comment Posted by: Jan Henrik Høiland Meling (05-okt-2012)
Private Shared Function FindBoundControl(ByVal fieldName As String, ByVal ctrl As Control) As Control If ctrl.DataBindings.Count > 0 AndAlso ctrl.DataBindings(0).BindingMemberInfo.BindingField = fieldName Then Return ctrl End If For Each child As Control In ctrl.Controls If child.DataBindings.Count > 0 AndAlso child.DataBindings(0).BindingMemberInfo.BindingField = fieldName Then Return child End If Dim childResult As Control = FindBoundControl(fieldName, child) If childResult IsNot Nothing Then Return childResult End If Next Return Nothing End Function
common win · Perma link post comment Posted by: Stian Gundersen Skjerveggen (22-aug-2012)