28 oktober 2010

VMWare Tools upgrading

After upgrading VMWare tools on a windows guest, run this:

set devmgr_show_nonpresent_devices=1
devmgmt.msc

then uninstall all devices that arent used any more.

7 oktober 2010

in_array++

function in_array_depth($needle,$haystack) {
if (!isset($needle) || !isset($haystack)) {
trigger_error("Nothing to do.");
}
else if (!is_array($haystack)) {
trigger_error("Input must be of type: array.");
}
else if ($needle == "") {
trigger_error("Searchstring must not be an empty string.");
}
else {
foreach ($haystack as $key => $array) {
if (is_array($array[key($array)])) {
return in_array_depth($needle,$array[key($array)]);
}
else if (strtoupper($array[key($array)]) == $needle) {
return true;
}
}
return false;
}
}

19 maj 2010

Deploying a SproutCore app

So im about to deploy an app, i use sc-build to finalize my app. This gives me a directory under "$PATHTOAPP/tmp/static" this directory is symlinked to where apache reads files.

Here is what i did to make it work:

ln -s $PATHTOAPP/tmp/static/ /var/www/html/static
ln -s $PATHTOAPP/tmp/static/my_app/index.html /var/www/html/myapp.html

It works great BUT it cant fetch my data from the datastore hence i am proxying this in the Buildfile. So i need to tell apache to fetch the data for me by doing the same thing i do in the Buildfile:

RewriteEngine On
RewriteBase /data/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /mydata http://other-host.com/pathtothedata [P]

this all goes into a .htaccess file or in your serverconfig. For the .htaccess file to work u need to set the option AllowOverride to what u might need, i use AllowOverride All in /etc/httpd/conf/httpd.conf

Now my app works!

28 mars 2010

Boldness and alignment of SC.LabelView

the available properties fontWeight: and textAlign:

SC.ALIGN_LEFT
SC.ALIGN_RIGHT
SC.ALIGN_CENTER

SC.REGULAR_WEIGHT
SC.BOLD_WEIGHT

Size of the text in a SC.LabelView

to change the size of the value in a SC.LabelView simply add the following property:
controlSize:

available settings:

SC.HUGE_CONTROL_SIZE
SC.LARGE_CONTROL_SIZE
SC.REGULAR_CONTROL_SIZE
SC.SMALL_CONTROL_SIZE
SC.TINY_CONTROL_SIZE

16 mars 2010

SproutCore Datasource

So i built my first application in SproutCore. An IP-Management application which fetches available IP-addresses from the inventorysystem my department uses.

It was really easy to build the application using fixtures and when my datasource and backend was ready i just switched the store to "store: SC.Store.create().from("MyApp.DataSource")," and i had real data in my application!

Basically MyApp.DataSource is a base set of functions which is called when certain functions are called. As i dont have any need to write data back to the server in this application i only have use for fetch().

My fetch-function passes what store made the request and what query was used:

fetch: function(store, query) {
// Check what query was used. Add more else if, if your application handles more data-models
if (query === SC.Query.remote(MyApp.Subnet)) {
//Initiate a server request for all the subnets available in JSON-format
var serverRequest = SC.Request.getUrl('/data/subnet').json();
//Tell SproutCore what object and what function it should call up a response, pass query and store
serverRequest.notify(this, this._didFetchAllSubnets, { query: query, store: store });
//I want all my data loaded before continuing
serverRequest.set('isAsynchronous', NO);
//Finally, send the request
serverRequest.send();
//return YES (true) to indicate we handled the fetch.
return YES;
}
}

The function which will be called upon a response is "_didFetchAllSubnets" as specified in the .notify() function above. This function needs to call at least 2 functions upon reading the data, check out this function:

_didFetchAllSubnets: function(response, params) {
//Get the parameters passed from the request
var store = params.store;
var query = params.query;
// Only if the response is ok we would want to read it into the store
if (SC.$ok(response)) {

// load the data into the store and save the storeKeys
storeKeys = store.loadRecords(MyApp.Subnet, response.get('body').content);

// notify store that we handled the fetch and hand it the storeKeys
store.dataSourceDidFetchQuery(query,storeKeys);

// handle error case
} else store.dataSourceDidErrorQuery(query, response);
},


And that reads the data into the local store and can be presented. One thing i learned is that if ur missing one of the specified fields in the data-model, it wont be able to use the data. I missed out on the guid (this was generated just before sending the data from my php-script), i had it commented for some reason. This generated an error of "dataHashes.len is not a function".


Almost every line of this code is taken from http://wiki.sproutcore.com/DataStore-Introduction

Attaching an event to a view

myView: SC.ListView.design({
eventToHandle: function() {
return YES;
}
})


This attaches an event to a view. I havent found a list of available events yet but i shall post it as soon as i find one.