PersistantData

PersistantData

new PersistantData(url)

Description:
  • Implements the interface with a persistent data mechanism.

    • This is the client side of a simple client/server mechanism.

    • The interface is used in HTML page, using a construct of the form:

    <script type='text/javascript' src='.../aideweb.js'></script>
    <script type='text/javascript'>
    
     var persistantData = New PersistantData("http://localhost:8080/_persistantData/upload");
    
     // Using, e.g., getNewID
     persistantData.getNewID(true, true, "", function(value) { 
       console.log("Testing getNewID: " + value);
     });
    
Parameters:
Name Type Description
url string

The service URL.

Methods

loadJSON(filename, default_value, callback)

Description:
  • Loads a structured value from a given filename.

Parameters:
Name Type Description
filename string

The data file base name without extension.

default_value object

The default value stored into the file if it does not yet exists.

callback callback

The callback that handles the loaded value.

  • Runs the callback(value: object) function with the loaded or the default value.
  • If a syntax error occurs, the value is given as a string.

saveJSON(filename, value, backupopt, callback)

Description:
  • Saves a structured value in a given filename.

Parameters:
Name Type Attributes Default Description
filename string

The data file base name without extension.

value object

The value to save as a JSON data structure.

backup boolean <optional>
true

If true, backup the file, with date.

callback callback

The callback that handles the next action after saving.

  • Runs the callback() function after the value is saved.

list(The, callback)

Description:
  • Lists all data file names, and runs the callback function for each file name.

Parameters:
Name Type Description
The string

file format.

callback callback

The callback that handles each data file name.

  • Runs the callback(value: array(string)) function with the loaded or the default value.
  • The list of the data file base name without extension is given.

getNewID(whenopt, whereopt, suffixopt, callback)

Description:
  • Returns a new ID built from the date in standard format and optionnally the local machine MAC address.

Parameters:
Name Type Attributes Default Description
when boolean <optional>
true

If true, appends the local machine MAC address.

where boolean <optional>
true

If true, appends the local machine MAC address.

suffix string <optional>
""

If not empty, appends the suffix to the proposed ID.

callback callback

The callback that handles the new ID value.

  • Runs the callback(value: string) function with this ID.