Thursday, May 31, 2007

Browser bookmarks

Afraid you'll lose your bookmarks if your disk crashes, or when you jump to another computer? Some solutions I have found:

  • http://www.quickbookmarks.com This is basically an online repository for your bookmarks. Wherever you are in the world, you can log in and find that obscure bookmark you saved. The only downside I seen is you have to explicitly define each bookmark with no bulk import feature.
  • http://www.mybookmarks.com This page DOES allow importing of bookmarks but I'm not a big fan of the clunky interface. You just need to export you bookmarks to html (see below) and then import.
  • Firefox has a neat bookmark export feature that exports your bookmarks to an html page! Just go to Bookmarks/Organize and then File/Export and save to an HTML file for backup or stick it on your web page.

Wednesday, May 23, 2007

Using AjaxPro with Ext data store

As I posted on Ext forum I use the following modified code to use AjaxPro with Ext. It helps avoid emedding URLs in the proxy call.

ds = new Ext.data.Store({
proxy: new Ext.data.AjaxProxy(myAsp, "GetMovies"),
reader:reader,
remoteSort: true
});


And AjaxProProxy.js, modified from Rodiniz:

Ext.data.AjaxProxy = function(ajaxProObject, method) {
Ext.data.AjaxProxy.superclass.constructor.call(this);
this.ajaxProObject = ajaxProObject;
this.method = method;
};
Ext.extend(Ext.data.AjaxProxy, Ext.data.DataProxy, {

// Harley's load function
load: function(params, reader, callback, scope, arg) {
if(this.fireEvent("beforeload", this, params) !== false) {
var s = [];
for (var x in params) {
s[s.length] = "params[\"" + x + "\"]";
}
s = s.join(",");
var o = {
params: params || {},
request: {
callback : callback,
scope : scope,
arg : arg
},
reader: reader,
callback: this.loadResponse,
scope: this
};

eval("this.ajaxProObject[this.method](" + s + ", this.loadResponse, o)");

} else {
callback.call(scope||this, null, arg, false);
}
},


// Rodiniz's response handler

loadResponse: function(response, request) {

var o = response.context;

var result;
try {
result = o.reader.read(response.json);

}catch(e){
this.fireEvent("loadexception", this, o, response, e);
o.request.callback.call(o.request.scope, null, o.request.arg, false);
return;
}
o.request.callback.call(o.request.scope, result, o.request.arg, true);
},


slight mod in Rodiniz's reader....
read : function(response){

var r= new Object(); //to handle errors
var obj=response + "*/";
var doc = eval(obj);
if(r.error){
throw r.error;
}
return this.readRecords(doc);
},

Tuesday, May 15, 2007

Ext Combobox - Typeahead and mode local

The Ext combobox has a 'mode' property that can be either 'remote' or 'local'. These terms are somewhat misleading. They should really be called something like 'manual load' and 'auto load'. A 'remote' mode combobox gets its data store's load method called behind the scenes. A 'local' mode combo requires an explicit data store 'load' call to get the store and combobox loaded up with data.

Meanwhile, it seems that the only way to get 'typeahead' to work in a combobox is if mode:local. I'd also recommend Trigger:all and I'm not sure why anyone would not want to Trigger:all. This causes the entire combobox dropdown to be listed when the user clicks the down arrow.

var cb = new fm.ComboBox({
typeAhead: true,
mode:'local',
store: dsdevice,
forceSelection: true,
triggerAction: 'all',
displayField: 'fld1',
valueField: 'fld2',
lazyRender:true,
editable:true
});

Friday, May 11, 2007

dataset on the server....grow your own sql

I have spent some time trying to get the Ext datastore translated to a .Net dataset for updating but I've come to the conclusion that its just not worth the effort. I've heard others say that its not worth working with datasets except for simple out of the box applications and now I believe that too.

The dataset that gets sent to the server side routine needs to have its row's 'setmodified' or 'setadded' method set and then the dataset needs to be 'merged'. Then, it is just a black box in terms of what happens and it is difficult to get the underlying SQL when there are problems. I have done the following on the server side for the updates. I have a handler for the Ext data store 'update' event so that every field change on the grid will cause this code to fire. I added a timestamp column to the table to handle optimistic concurrency.

Code:

conn = new OleDbConnection(ads.ConnectionString);
conn.Open();

foreach (DataRow row in ds.Tables[0].Rows) // should always be one row
{

sqlcmd = "UPDATE TblOperations SET ";
sqlcmd += " Device = '" + row["Device"].ToString() + "', ";
sqlcmd += " Station = '" + row["Station"].ToString() + "' ";
sqlcmd += " where ID_key = " + row["ID_key"].ToString();
if (! row["timest"].ToString().Equals("") )
sqlcmd += " and timest = '" + row["timest"].ToString() + "' ";

cmd = new OleDbCommand(sqlcmd, conn);
affected += cmd.ExecuteNonQuery();
}

if ( affected == 1 )
return "";
else
return "error"



Now I need to get 'adds' and 'deletes' handled.

Dataset on the server.... ugh

I wrote the following to send the ext.datastore to the server, in response to a 'save button' click.

Code:
var editedds = myextdatastore.getModifiedRecords();

var ds4 = new Ajax.Web.DataSet();
var dt4 = new Ajax.Web.DataTable();

for(var i = 0, len = myextdatastore.fields.keys.length; i < i =" 0," len =" editedds.length;">


My C# routine correctly reads the dataset on the server but I'm disappointed that now I have to create all the insert/update/delete logic by creating 'insertcommand','updatecommand' etc. I thought the whole point of using ADO datasets was that it would handle all this logic. It seems like there is no way to get around having to code this on the server.

Below is my c# code. It returns no errors but it doesn't update either.....

Code:public static String SaveAll(System.Data.DataSet ds )
{
OleDbDataAdapter oda = getAccessAdapter();

OleDbCommandBuilder bld = new OleDbCommandBuilder(oda);
bld.GetInsertCommand(true);
OleDbCommand command;

command = new OleDbCommand(
"INSERT INTO TblOperations (Device,Operation) " +
"VALUES ( ?,?)");

command.Parameters.Add("@Device", OleDbType.VarChar, 40, "Device");
command.Parameters.Add("@Operation", OleDbType.VarChar, 40, "Operation");

oda.InsertCommand = command;

command = new OleDbCommand("UPDATE TblOperations SET Device=?, Operation=? WHERE ID_key=?");
command.Parameters.Add(new OleDbParameter("Device", OleDbType.VarChar , 50));
command.Parameters.Add(new OleDbParameter("Operation", OleDbType.VarChar, 50));
command.Parameters.Add(new OleDbParameter("ID_key", OleDbType.Numeric, 0));

oda.UpdateCommand=command;

oda.Update(ds, "Table1");

return " hello world " + oda.UpdateCommand.CommandText;

}

Ext - .Net dataset updating with grid

I am enjoying my Ext/ajaxpro grid and it seems to work great for viewing .net datasets. My next goal is to allow inline editing and updates to the dataset and of course return the modified dataset to the server for processing