Memento JavaScript Library: Difference between revisions

Tags: Mobile edit Mobile web edit
 
(30 intermediate revisions by 2 users not shown)
Line 22: Line 22:


:; Result: [[#Object DefaultEntry|'''''DefaultEntry''''' object]]
:; Result: [[#Object DefaultEntry|'''''DefaultEntry''''' object]]
==== buildDefaultEntry() ====
: The buildDefaultEntry() method is designed to facilitate the customization of default field values during the '''Creating an entry''' or '''Updating an entry''' trigger events, specifically in the '''Opening an Entry Edit card''' phase. When used in the "Creating an entry" trigger event, the buildDefaultEntry() method applies default values for new, copied, or prefilled entries.
:; Result: [[#Object DefaultEntry|'''''DefaultEntry''''' object]]
: '''Properties'''
: The buildDefaultEntry() method allows you to determine the method used by the user to create an entry. Use the following properties for this purpose:
::; buildDefaultEntry().created:  Indicates a new and empty entry.
::; buildDefaultEntry().duplicated: Indicates a duplicate of an existing entry.
::; buildDefaultEntry().prefilled:  Indicates the creation of an entry based on a template.
: '''Usage'''
: The typical usage pattern involves invoking the set() method on the result of buildDefaultEntry() to specify the field name and its corresponding default value.
:: <source lang="JavaScript">
buildDefaultEntry().set("Field name", "Field value");
</source>
: If you want to set default values only when duplicating an entry, you can use the following example:
:: <source lang="JavaScript">
if (buildDefaultEntry().duplicated) {
  buildDefaultEntry().set("Description", "Duplicated Entry")
}
</source>


==== exit() ====
==== exit() ====
Line 48: Line 73:
: Create a new entry in the library
: Create a new entry in the library
: '''Argument'''
: '''Argument'''
::; values: [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object '''''Object'''''] containing the field values
::; values: [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object '''''Object'''''] containing the field values as its properties
:; Result: [[#Object entry|'''''Entry''''' object]] &mdash; the new entry in the library
:; Result: [[#Object entry|'''''Entry''''' object]] &mdash; the new entry to create in the library


===== entries() =====
===== entries() =====
: Get all the entries of the library
: Get all the entries of the library
:; Result: Array object containing entries, sorted by the time of their creation, from newest to oldest
:; Result: Array object containing entries (Entry objects), sorted by the time of their creation, from newest to oldest
 
===== fields() =====
: Get some of the fieldnames of the library
:; Result: Array object containing the strings, in definition order. Only the names of the fields defined in the MAIN page and not appearing within a Subheader will be returned, as of Memento release 4.13.


===== find(query) =====
===== find(query) =====
Line 106: Line 135:
::; name: Name of the Link to Entry field to which to add the link
::; name: Name of the Link to Entry field to which to add the link
::; entry: Entry in the field's related library to which to link
::; entry: Entry in the field's related library to which to link
===== images(name) =====
: The images(name) method is designed to facilitate easy retrieval and manipulation of images associated with a specified field in the entry.
: '''Arguments'''
::; name: Name of the Image field
: '''Return Value'''
: An array of objects, each representing an image associated with the specified field.
::; caption: Get or set the caption for the image.
::; uri: Retrieve the URI (link) of the image.


===== recalc() =====
===== recalc() =====
Line 171: Line 210:
With scripts, you can read or write files located in the device's internal memory or on the SD card. All file operations are performed by the ''File'' object, which is obtained via a global function called ''file()''.
With scripts, you can read or write files located in the device's internal memory or on the SD card. All file operations are performed by the ''File'' object, which is obtained via a global function called ''file()''.


To work with the files, the library should have read/write file access.
To work with the files, the library should have read/write file access. Also, in the Android app, select a folder that your script will have access to. You can configure this folder in the script permission dialog.


=== ''File'' global functions ===
=== ''File'' global functions ===
Line 179: Line 218:


: '''Argument'''
: '''Argument'''
::; name: The name and the full path to the file. For example, if the file is located on the SD card, the path should be something like /sdcard/example.txt.
::; name: The name of the file in the chosen folder is accessible to scripts. In the Desktop app, you must specify the full file path.


:; Result
:; Result
Line 210: Line 249:


:; writeLine(text): Write strings and a newline to the file stream
:; writeLine(text): Write strings and a newline to the file stream
:; appendMode(): Switch the file to append mode, allowing data to be added to the end of the file without overwriting existing content.


==== ''File'' properties ====
==== ''File'' properties ====
Line 238: Line 279:
===== http() =====
===== http() =====
: Get the Http object
: Get the Http object
<br/>


===== get(url) =====
===== get(url) =====
Line 367: Line 409:
: '''Argument'''
: '''Argument'''
::; text: Text of the notification
::; text: Text of the notification
==== dialog() ====
: Create a builder for constructing and displaying a dialog
:; Result: [[#Object Dialog|'''''Dialog''''' object]]


==== system() ====
==== system() ====
Line 382: Line 428:
==== ''System'' properties ====
==== ''System'' properties ====
:; os: Name of the operating system executing the script
:; os: Name of the operating system executing the script
<br/>
=== Object ''Dialog'' ===
The Dialog object provides a set of methods to configure and customize the appearance and behavior of the dialog.
'''Usage'''
To use the Dialog object, instantiate it using dialog() method and then chain the available methods to configure the dialog as needed. Finally, call the show() method to display the constructed dialog to the user.
<source lang="javascript">
const myDialog = dialog()
myDialog.title("Hello")
        .text("Welcome to our application.")
        .positiveButton("OK", () => { /* Handle positive button click */ })
        .show();
</source>
'''Methods'''
:; title(string): Sets the title of the dialog. Accepts a string parameter that represents the title to be displayed.
:; text(string): Sets the main text content of the dialog. Accepts a string parameter that represents the primary message or content of the dialog.
:; view(ui object): Sets a custom view for the dialog. Accepts a [[Memento_JavaScript_UI|UI object]] that represents the custom view to be displayed within the dialog.
:; positiveButton(text, function()): Configures the positive button of the dialog. Accepts two parameters: the text to be displayed on the button and the function to be executed when the button is clicked.
:; negativeButton(text, function()): Configures the negative button of the dialog. Accepts two parameters: the text to be displayed on the button and the function to be executed when the button is clicked.
:; neutralButton(text, function()): Configures the neutral button of the dialog. Accepts two parameters: the text to be displayed on the button and the function to be executed when the button is clicked.
:; autoDismiss(bool): Sets whether the dialog should automatically dismiss when a button is clicked. Accepts a boolean parameter. If autoDismiss is set to false, the dialog will only close when a button function returns true.
:; show(): Displays the configured dialog to the user.
<br/>
<br/>


Line 494: Line 564:
<br/>
<br/>


[[Category:en]] [[Category:Spec]]
[[Category:en]] [[Category:Spec]] [[Category:Sc]]