Mhttpd.js

From MidasWiki
Revision as of 23:25, 15 August 2013 by Olchansk (talk | contribs) (→‎ODBCopy)
Jump to navigation Jump to search

About

mhttpd.js contains javascript function wrappers for most MIDAS AJAX functions typically used for implementing interactive custom pages for MIDAS experiments.

AJAX is a set of web development techniques used to construct interactive web applications:

mhttpd.js is typically served by mhttpd from $MIDASSYS/resources/mhttpd.js

<html>
<head>
...
<script src='mhttpd.js'></script>
...
</head>
...
</html>

A mostly up to date copy of mhttpd.js is linked here:

An example for using all mhttpd.js functions is included in the MIDAS distribution under examples/javascript1:

MIDAS AJAX functions can be accessed directly without using mhttpd.js wrappers (i.e. using the JSON-P script-tag method)

  • AJAX - MIDAS AJAX functions

Functions

Helper functions:

  • function getMouseXY(e)
  • function XMLHttpRequestGeneric()
  • function ODBExtractRecord(record, key)
  • function ODBEdit(path)
  • function ODBFinishInlineEdit(...)
  • function ODBInlineEditKeydown(...)
  • function ODBInlineEdit(...)

ODB access functions:

  • function ODBSet(path, value, pwdname)
  • function ODBGet(path, format, defval, len, type)
  • function ODBMGet(paths, callback, formats)
  • function ODBGetRecord(path)
  • function ODBKey(path)
  • function ODBCopy(path, format)
  • function ODBMCopy(paths, callback, format)

MIDAS access functions:

  • function ODBRpc_rev0(name, rpc, args)
  • function ODBRpc_rev1(name, rpc, max_reply_length, args)
  • function ODBGetMsg(n)
  • function ODBGenerateMsg(m)
  • function ODBGetAlarms()

Summary table

Summary of mhttpd.js functions
Function XML JSON JSON-P async AJAX
ODBSet(path, value, pwdname) no no no no cmd=jset
ODBGet(path, format, defval, len, type) no no no no cmd=jget
ODBMGet(paths, callback, formats) no no no yes cmd=jget
ODBGetRecord(path) ? ? ? no cmd=jget
ODBKey(path) no yes no no cmd=jkey
ODBCopy(path, format) yes yes yes no cmd=jcopy
ODBMcopy(paths, callback, format) yes yes yes yes cmd=jcopy
ODBRpc_rev0(name, rpc, args) no no no no cmd=jrpc_rev0
ODBRpc_rev1(name, rpc, max_reply_length, args) no no no no cmd=jrpc_rev1
ODBRpc(...) yes yes yes yes cmd=jrpc
ODBGetMsg(n) no no no no cmd=jmsg
ODBGenerateMsg(m) no no no no cmd=jgenmsg
ODBGetAlarms() no no no no cmd=jalm

ODBSet

http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbset

ODBGet

http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbget

ODBMGet

http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbmget

ODBKey

(doc incomplete)

http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbkey

Usage:

var key = new ODBKey("/Equipment/RpcExample/Variables/SLOW");

Returns a javascript object with data fields corresponding to the data fields of MIDAS KEY (midas.h):

{"name":"SLOW","type":"TID_DOUBLE","num_values":"3","item_size":"8","last_written":"1376633931"}

ODBCopy

Usage:

var data_json = ODBCopy("/Equipment/RpcExample/Variables", "json");
var obj = JSON.parse(data_json);
document.getElementById('json_data0').innerHTML = obj.SLOW[0];

Return value:

{
  "SLOW/key" : { "type" : 10, "num_values" : 3, "last_written" : 1376634320 },
  "SLOW" : [ 2357, 1376634320, -8.6602540236010100e+01 ]
}

ODBMCopy

AAA