顯示具有 Xataface 標籤的文章。 顯示所有文章
顯示具有 Xataface 標籤的文章。 顯示所有文章

星期五, 5月 14, 2010

升級Dataface到1.2.4

今天升級Dataface到1.2.4版,出乎意料的順利
解壓縮後將寫入權限設給 Dataface/templates_c/ 目錄
就一切正常,繁體中文的語系也不用自己新增,
看來使用Dataface的人也慢慢多了。

http://xataface.com/admin.php?-action=home

星期三, 1月 13, 2010

Xataface 利用 Cookies 減少重覆填寫基本資料

修改或新增 應用程式目錄/tables/table_name/table_name.php
class tables_survey_y100 {

function beforeSave(&$record){ //存檔前先寫入cookie
$cookie_arr = array('depart'=>'填表單位', 'section'=>'填表科別', 'user_name'=>'填表人', 'tel'=>'聯絡分機');
foreach ($cookie_arr as $id => $value) {
setcookie($id,$record->strval($value),time()+60*60*24*30);
}
}

function block__after_new_record_form(){ //新增資料時讀入cookie值
echo "<script language='javascript'><!--"
$cookie_arr = array('depart'=>'填表單位', 'section'=>'填表科別', 'user_name'=>'填表人', 'tel'=>'聯絡分機');
foreach ($cookie_arr as $id => $value) {
echo "document.new_survey_y100_record_form.$value.value='".$_COOKIE[$id]."';";
}
echo "//--></script>"


ps:大於、小於符號請換成半型

xatafave自訂欄位寬度

xataface目前(1.2.2版)為止不能用調整參數的方式自訂清單檢視的欄位寬度,比較方便的替代方案是增加widget:label的字元來增加欄位寬度,但是中文因為每個字元都可以斷行的關係,並不能利用增加欄名的中文字元來增加欄位寬度。

改善這個問題可以設定 white-space: nowrap; 這個css參數強迫不要斷行。
通常我會希望全網站都套用這個設定,所以直接修改 xataface/plone.css
增加

thead {
white-space: nowrap;
}

星期三, 12月 16, 2009

Xataface自訂列表清單

Xataface清單顯示滑鼠預設點選動作為"檢視"該筆記錄的詳細資料,如果要修改為"開啟某網頁"就必須使用自訂欄位顯示的方式。

作法如下:
1.修改或新增 應用系統目錄/tables/資料表名稱/資料表名稱.php
2.新增 class "class tables_資料表名稱 { } "
3.新增 function 欄位名稱__renderCell( &$record ) {
return '<a href="'.$record->strval('欄位名稱').'" target="_blank">'.$record->strval('欄位名稱').'</a>';
}

Xataface中文亂碼問題

Xataface 1.2 版開始已有簡體中文介面,如果資料庫正確儲存為utf8時Xataface也可以正常顯示,但是預設語系還是ISO-8859-1,所以輸入中文時都會被轉碼為&#999999格式存入資料庫。
解決方式為在conf.ini最上方設定
default_oe=UTf-8
default_ie=UTF-8
如果使用Xataface建置的應用系統很多,不想重復設定,可直接修改Xataface/Dataface/Application.php中,將
if ( !isset($this->_conf['default_ie']) ) $this->_conf['default_ie'] = 'ISO-8859-1';
if ( !isset($this->_conf['default_oe'])) $this->_conf['default_oe'] = 'ISO-8859-1';
ISO-8859-1改為UTF-8,所有應用系統都會以UTF-8為編碼方式。

星期二, 6月 30, 2009

Xataface-紀錄填表者ip

1.修改fields.ini
[ip]
widget:type=hidden
visibility:list=0

2.修改tablename.php -> class tables_tablename 加入
function beforeSave(&$record){
$record->setValue('ip', $_SERVER['REMOTE_ADDR']);
}

Xataface-製作動態選單

在Xataface中設定動態選單(雙層選單)並不困難,這裡示範的是單一資料表方式,也可將第一層和第二層選單分開存在兩個資料表(areas)。








province_idcity_idname
U01U0100province_1
U01U0101city_1
U01U0102city_2
U02U0200province_2
U02U0201city_3
U02U0202city_4

1.修改valuelists.ini
[cities]
__sql__ = "select city_id, name, province_id from areas order by city_id"
[provinces]
__sql__ = "select province_id,province_name from areas where SUBSTR(city_id,4,2)="00" order by province_id"


2.修改fields.ini
[province]
vocabulary=provinces
[city]
vocabulary=cities


3.修改應用程式目錄/tables/tablename.php
class tables_tablename {
http://xataface.com/wiki/index.php?-table=wiki&-action=browse&page_id=%3D90
} //End of class

星期五, 4月 25, 2008

Xataface-參數(_prefs)設定

Xataface的參數定義在 Dataface/Application.php 的 $prefs array 包含
'show_jump_menu'=>1, // The drop-down menu that allows you to "jump" to any record in the found set.
'show_result_controller'=>1, // Next, previous, page number .. links...
'show_table_tabs'=>1, // Details, List, Find, etc...
'show_actions_menu'=>1, // New record, Show all, delete, etc...
'show_logo'=>1, // Show logo at top right of app
'show_tables_menu'=>1, // The tabs to select a table.
'show_search'=>1, // Show search field in upper right.
'show_record_actions'=>1, // Show actions related to particular record
'show_recent_records_menu'=>1
'show_bread_crumbs' => 1, // Bread crumbs at top of page to show where you are
'show_record_tabs' => 1, // View, Edit, Translate, History, etc...
'show_record_tree' => 1, // Tree to navigate the relationships of this record.
'list_view_scroll_horizontal'=>1, // Whether to scroll list horizontal if it exceeds page width
'list_view_scroll_vertical'=>1

自訂的方式
一、在conf.ini中使用
[_prefs]
show_search = 1
二、在delegate中使用 function getPreferences()

Xataface-依使用者不同限制紀錄權限

目的:利用setSecurityFilter讓使用者只能改自己的紀錄,不能改別人的紀錄
一、在ApplicationDelegate.php新增函數如下

function getPreferences(){
$mytable =& Dataface_Table::loadTable('Users') ; // load the table named 'my_table'
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
$app =& Dataface_Application::getInstance();
$tables =& $app->conf['_tables'];
if ( $user && $user->val('Role') != 'ADMIN' ){
unset($tables['Users']);
$mytable->setSecurityFilter(array('UserID'=>$user->val('UserID')));
}
return array(); // Mandatory!! getPreferences() must return array.
}

Xataface-依使用者不同限制欄位權限

如果想讓xataface建置的網頁程式,依使用者的不同隱藏網頁部份元素,可以透過xataface提供的自訂css功能。
例如:管理者可以變更使用者的角色,而使用者不能改變角色,可以將表單中的角色欄位隱藏
注意:這個隱藏法只能防一般使用者,進階使用者有可能繞過這個限制,必須再依步驟四設定欄位權限
一、在Users table的 Users.php 新增函數
function block__custom_stylesheets(){
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
$role = $user->val('Role');
if ( $role!='ADMIN' ){
echo '<link rel="stylesheet" type="text/css" href="tables/Users/custom.css">';
}
二、建立custom.css
#Users-UserName-label-wrapper, #Users-UserName-wrapper, #UserName, #Users-Role-label-wrapper,#Users- Role-wrapper, #table_tabs, #contentActionsWrapper, #record-tabs-history {
visibility: hidden;
}
四、設定欄位權限-在Users table的 Users.php 新增函數
function UserName__permissions(&$record) {
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
$role = $user->val('Role');
if ( $role!='ADMIN') { return Dataface_PermissionsTool::READ_ONLY(); }
return Dataface_PermissionsTool::getRolePermissions($role);
}
function Role__permissions(&$record) {
if ( $role!='ADMIN') { return Dataface_PermissionsTool::READ_ONLY(); }
return Dataface_PermissionsTool::getRolePermissions($role);
}