Sample Script 7
Script that will take an entry from a pop-up folder list and check the matching check-mark folder while un-checking the non-matching ones . See Notes below.
Code
- function SetCategoryFolder(item_id)
- tCategories={"Car","Computer","Duty","Education","Family","Finance","Fun","Health","Home","Investment","JobSearch","JobDo","Legal","Tax","Make$","Other","UnAssigned"}
- Category=get_folder_value("Category", item_id)
- if Category~="" then
- for index,TestCategory in ipairs(tCategories) do
- CurrCategory=get_folder_value("Category", item_id)
- if CurrCategory==TestCategory then
- set_folder_value(CurrCategory,item_id,1)
- else
- set_folder_value(TestCategory,item_id,0)
- end
- end
- else
- set_folder_value("UnAssigned",item_id,1)
- set_folder_value("Category",item_id,"UnAssigned")
- end
Code Description
- the laucmd.lua header for the script (function)
- set up a list of categories in a tCategories Table. Note: these values should be the same as the Category check-mark folders and the pop-up values in the pop-up folder (see Notes 1 & 2 below)
- assign the variable Category the current item's Category pop-up value (e.g. "Computer")
- conditional if statement to determine if the Category variable is empty ("")
- if Category has a value (is not empty), then iterate over all Categories in the tCategories Table Note: the index variable contains the Table index, and TestCategory variable contains the corresponding Category value (e.g. "Car" for the first index)
- assign the variable CurrCategory the current item's Category pop-up value (e.g. "Computer")
- conditional if statement to determine if the item's pop-up value (e.g. "Computer") matches the current (during the iteration) Table value (e.g. "Car")
- if it does, then the check-mark folder in the CurrCategory variable is set to 1 (true or checked)
- the else statement for conditional on line 7, and if line 7 is false then
- set the check-mark folder in the TestCategory variable to 0 (false or unchecked). Note that this will un-check all check-mark folders except the matching one as the Table is iterated.
- end of conditional on line 7
- end of the loop on line 5
- the else statement for the conditional on line 4
- set the item's check-mark folder "Unassigned" to 1 or checked. Note: This means that no Category has been assigned by the user
- also set the item's pop-up "Category" folder value to "Unassigned" Note: This means that no Category has been assigned by the user
- the end statement for the function on line 1
Notes
- Create several Category folders as check-mark folders (e.g. "Car","Computer","Duty", etc)
- Create a Popup Folder called "Categories" with values corresponding to the same Categories as the check-mark folders
- Create a text file "luacmd.lua" in the Ecco program directory (if it does not already exist)
- Add the function/Script as shown in the code above (w/o the numbers) to "luacmd.lua" file and save (The Script lists examples of Categories - modify as desired).
- In any folder (I have a check-mark folder called "LUA Scripts"), create the following rule (The rule will call the function in the "luacmd.lua" file as soon as an item is added or changed):
++:L:SetCategoryFolder(item_id) - How it works:
- When you set the popup value, the corresponding check-mark folder will be checked.
- Changing the popup value changes the check-mark Folder.
- Note that the reverse is not working, i.e. it is not possible to change the check-mark folder to change the popup value. This can be done but it is a bit complicated.
- Thus, trying to change the check-mark Folders is prevented. It will simply revert back according to the value set in the popup folder.
- If a new item is created w/o a popup category value, the popup will get the value "Unassigned" and the Unassigned check-mark folder will be checked.
- Note that only one category/item is permitted (because only one popup value can be set in an Ecco popup Folder)
Contributors
This script is taken from the
http://tech.groups.yahoo.com/group/ecco_pro/message/7270 thread started by Jim Witherspoon and with the assistance of the following:
Jim Witherspoon
rbrandis
Albert Schepers
viking