將按鈕放置在 Scriptcase Form / Grid的任意位置
就 Scriptcase 而言,設計一個按鈕放在表頭、或是表尾,是一件非常簡單的事情。
但有時候,會希望將按鈕放在距離特定資料附近的位置,這樣比較直觀。
It’s easy to create a button on the top or bottom of a Scriptcase form or Grid application (as element of the toolbar).
But sometime you might need buttoms directly near certain elements within the form (or within the line of a grid).
1. Create a link for the action (if you click on the button)
One of the easiest ways is to use the Scriptcase macro:
sc_make_link(Application, Parameters)
example:
$string_link = sc_make_link(grid_images, ref_object_type='contact';ref_object_id={id});
The generates a string with the link to the Grid-application ‘grid_images’ and passes the parameters ‘ref_object_type’ and ‘ref_object_id’
2. Create a label field
Create a field of ‘Label’ type within the form / grid and insert it at the place the button will appear.
Our example uses a Label-field named ‘edit_picture’
Then the new field will be filled via PHP-code (i.e. in the event OnLoad):
3. Set the Content of the field
Add a usual HTML link (via a href) as contact of the field:
{edit_pictures} = '<a href="' . $string_link . '" class="scButton_small" title="Edit the picture" style="vertical-align: middle; display:inline-block;">' . {lang_contact_edit_pictures} . '</a>';
We’re using the string generated in 1. as link.
‘class’ defines that a small button is to be used. You could also use class="scButton_default" for a standard button. Hint: Some templates do not support small buttons.
‘title’ defines which text is be shown as popup if the cursor is over the button (PC-browser only).
{lang_contact_edit_pictures} defines which text is shown on the button. (Our sample: Bilder Bearbeiten)
Hint: Use plain text instead of {lang_contact_edit_pictures} of your’re not using the multilingual feature of Scriptcase.
Example:
If the lable field is placed below a picture, ot could be show like:
上面的例子,是連結到外部的Application。
如果是自己FORM/GRID本身的Button呢?
可以先使用SC內的BUTTON功能,建立一個 Button,然後跑跑結果看,用檢視原始碼看該Button的Source Code連結,複製出來。
比照上面的作法,建立一個 Label 欄位,將上段Button複製下來的Source Code貼到該 Label 的內容裡面,
安排該Field顯示在適當的位置。這樣就完成了。
缺點是:原本預設顯示在表頭/表尾的按鈕,必須重複出現。因為如果把該按鈕不顯示,該功能就不行執行了!
沒有留言:
張貼留言