BUG 6212 Way to Export Skins 2.0

Implemented a way to export Skins in 2.0
This commit is contained in:
Hugo Loza
2011-07-20 17:15:47 -04:00
parent 4bfd4dde2b
commit 8386ad6514
3 changed files with 365 additions and 136 deletions

View File

@@ -1247,6 +1247,8 @@ $output = $outputHeader.$output;
return;
}
break;
case 'tar':
G::sendHeaders ( $filename , 'application/x-tar', $download, $downloadFileName ); break;
default :
//throw new Exception ( "Unknown type of file '$file'. " );
G::sendHeaders ( $filename , 'application/octet-stream', $download, $downloadFileName ); break;

View File

@@ -26,9 +26,10 @@ function updatePageSize(){
$config = Array();
$config[] = $arr;
$c->aConfig = $config;
$c->saveConfig('calendarList', 'pageSize','',$_SESSION['USER_LOGGED']);
$c->saveConfig('skinsList', 'pageSize', '', $_SESSION['USER_LOGGED']);
echo '{success: true}';
}
function skinList() {
//Get Skin Config files
$skinListArray = array();
@@ -38,11 +39,16 @@ function skinList(){
//Read and parse each Configuration File
foreach ($customSkins as $key => $configInformation) {
$folderId = str_replace(G::ExpandPath("skinEngine") . 'base', "", str_replace(PATH_CUSTOM_SKINS, "", str_replace("/config.xml", "", $configInformation)));
if ($folderId == "")
$folderId = "classic";
$xmlConfiguration = file_get_contents($configInformation);
$xmlConfigurationObj = G::xmlParser($xmlConfiguration);
$skinInformationArray = $skinFilesArray = $xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['information']['__CONTENT__'];
$res = array();
$res['SKIN_FOLDER_ID'] = strtolower($folderId);
foreach ($skinInformationArray as $keyInfo => $infoValue) {
$res['SKIN_' . strtoupper($keyInfo)] = $infoValue['__VALUE__'];
}
@@ -50,3 +56,89 @@ function skinList(){
}
print_r(G::json_encode($skinListArray));
}
function createSkin($baseSkin='classic') {
}
function exportSkin($skinToExport) {
try {
if (!isset($_REQUEST['SKIN_FOLDER_ID'])) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_NAME_REUIRED')) );
}
$skinName = $_REQUEST['SKIN_FOLDER_ID'];
$customSkins = glob(PATH_CUSTOM_SKINS . "*/config.xml");
$skinFolderBase = PATH_CUSTOM_SKINS . $skinName;
$skinFolder = $skinFolderBase . PATH_SEP;
$skinTar = PATH_CUSTOM_SKINS . $skinName . '.tar';
if (!is_dir($skinFolder)) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_DOESNT_EXIST')) );
}
if (!file_exists($skinFolder . "config.xml")) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_CONFIGFILE_DOESNT_EXIST')) );
}
if (file_exists($skinTar)) {
//try to delete
if (!unlink($skinTar)) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FOLDER_PERMISSIONS')) );
}
}
//Try to generate tar file
G::LoadThirdParty('pear/Archive', 'Tar');
$tar = new Archive_Tar($skinTar);
$tar->_compress = false;
addTarFolder($tar, $skinFolder, PATH_CUSTOM_SKINS);
// $aFiles = $tar->listContent();
/*
*/
$response['success'] = true;
$response['message'] = $skinTar;
print_r(G::json_encode($response));
} catch (Exception $e) {
$response['success'] = false;
$response['message'] = $e->getMessage();
print_r(G::json_encode($response));
}
}
function streamSkin() {
$skinTar = $_REQUEST['file'];
$bDownload = true;
G::streamFile($skinTar, $bDownload, basename($skinTar));
@unlink($fileTar);
}
function addTarFolder($tar, $pathBase, $pluginHome) {
$aux = explode(PATH_SEP, $pathBase);
if ($aux[count($aux) - 2] == '.svn')
return;
if ($handle = opendir($pathBase)) {
while (false !== ($file = readdir($handle))) {
if (is_file($pathBase . $file)) {
//print "file $file \n";
$tar->addModify($pathBase . $file, '', $pluginHome);
}
if (is_dir($pathBase . $file) && $file != '..' && $file != '.') {
//print "dir $pathBase$file \n";
addTarFolder($tar, $pathBase . $file . PATH_SEP, $pluginHome);
}
}
closedir($handle);
}
}

View File

@@ -107,7 +107,7 @@ Ext.onReady(function(){
exportButton = new Ext.Action({
text: _('ID_EXPORT'),
iconCls: 'button_menu_ext ss_sprite ss_basket_go',
//handler: CopyButtonAction,
handler: exportSkin,
disabled: true
});
searchButton = new Ext.Action({
@@ -149,9 +149,12 @@ Ext.onReady(function(){
singleSelect: true,
listeners:{
rowselect: function(sm){
//exportButton.enable();
exportButton.disable();
rowSelected = infoGrid.getSelectionModel().getSelected();
if((rowSelected.data.SKIN_FOLDER_ID)&&((rowSelected.data.SKIN_FOLDER_ID!="classic"))){
exportButton.enable();
}else{
exportButton.disable();
}
},
rowdeselect: function(sm){
exportButton.disable();
@@ -167,13 +170,37 @@ Ext.onReady(function(){
root: 'skins',
totalProperty: 'total_skins',
fields : [
{name : 'SKIN_ID'},
{name : 'SKIN_NAME'},
{name : 'SKIN_DESCRIPTION'},
{name : 'SKIN_AUTHOR'},
{name : 'SKIN_CREATEDATE'},
{name : 'SKIN_MODIFIEDDATE'},
{name : 'SKIN_STATUS'}
{
name : 'SKIN_ID'
},
{
name : 'SKIN_FOLDER_ID'
},
{
name : 'SKIN_NAME'
},
{
name : 'SKIN_DESCRIPTION'
},
{
name : 'SKIN_AUTHOR'
},
{
name : 'SKIN_CREATEDATE'
},
{
name : 'SKIN_MODIFIEDDATE'
},
{
name : 'SKIN_STATUS'
}
]
})
});
@@ -184,12 +211,49 @@ Ext.onReady(function(){
sortable: true
},
columns: [
{id:'SKIN_UID', dataIndex: 'SKIN_UID', hidden:true, hideable:false},
{header: _('ID_NAME'), dataIndex: 'SKIN_NAME', width: 100, align:'left'},
{header: _('ID_DESCRIPTION'), dataIndex: 'SKIN_DESCRIPTION', width: 200, align:'left'},
{header: _('ID_OWNER'), dataIndex: 'SKIN_AUTHOR', width: 69, align:'center'},
{header: _('ID_CREATE'), dataIndex: 'SKIN_CREATEDATE', width: 69, align:'center', renderer: showdate},
{header: _('ID_UPDATE_DATE'), dataIndex: 'SKIN_MODIFIEDDATE', width: 69, align:'center', renderer: showdate}
{
id:'SKIN_UID',
dataIndex: 'SKIN_UID',
hidden:true,
hideable:false
},
{
header: _('ID_NAME'),
dataIndex: 'SKIN_NAME',
width: 100,
align:'left'
},
{
header: _('ID_DESCRIPTION'),
dataIndex: 'SKIN_DESCRIPTION',
width: 200,
align:'left'
},
{
header: _('ID_OWNER'),
dataIndex: 'SKIN_AUTHOR',
width: 69,
align:'center'
},
{
header: _('ID_CREATE'),
dataIndex: 'SKIN_CREATEDATE',
width: 69,
align:'center',
renderer: showdate
},
{
header: _('ID_UPDATE_DATE'),
dataIndex: 'SKIN_MODIFIEDDATE',
width: 69,
align:'center',
renderer: showdate
}
//{header: _('ID_STATUS'), dataIndex: 'SKIN_STATUS', width: 130, align:'center', renderer: render_status},
]
});
@@ -250,7 +314,9 @@ Ext.onReady(function(){
store: store,
cm: cmodel,
sm: smodel,
tbar: [newButton, '-', importButton,exportButton, {xtype: 'tbfill'}, searchText,clearTextButton,searchButton],
tbar: [newButton, '-', importButton,exportButton, {
xtype: 'tbfill'
}, searchText,clearTextButton,searchButton],
bbar: bbarpaging,
listeners: {
rowdblclick: DoNothing
@@ -269,7 +335,9 @@ Ext.onReady(function(){
this
);
infoGrid.on('contextmenu', function(evt){evt.preventDefault();}, this);
infoGrid.on('contextmenu', function(evt){
evt.preventDefault();
}, this);
infoGrid.addListener('rowcontextmenu',onMessageContextMenu, this);
infoGrid.store.load();
@@ -282,6 +350,7 @@ Ext.onReady(function(){
});
});
//Function format dates
showdate = function (value){
return _DF(value);
@@ -297,6 +366,51 @@ onMessageContextMenu = function (grid, rowIndex, e) {
//Do Nothing Function
DoNothing = function(){};
exportSkin = function(){
viewport.getEl().mask(_('ID_SKIN_EXPORTING'));
rowSelected = infoGrid.getSelectionModel().getSelected();
if((rowSelected.data.SKIN_FOLDER_ID)&&((rowSelected.data.SKIN_FOLDER_ID!="classic"))){
Ext.Ajax.request({
url: 'skin_Ajax',
params: {
action: 'exportSkin',
SKIN_FOLDER_ID: rowSelected.data.SKIN_FOLDER_ID
},
success: function(r,o){
viewport.getEl().unmask();
var resp = Ext.util.JSON.decode(r.responseText);
if (resp.success){
try {
Ext.destroy(Ext.get('downloadIframe'));
}
catch(e) {}
Ext.DomHelper.append(document.body, {
tag: 'iframe',
id:'downloadIframe',
frameBorder: 0,
width: 0,
height: 0,
css: 'display:none;visibility:hidden;height:0px;',
src: 'skin_Ajax?action=streamSkin&file='+resp.message
});
viewport.getEl().unmask();
}else{
viewport.getEl().unmask();
Ext.Msg.alert('Alert', resp.message);
//PMExt.error(_('ID_SKINS'),_('ID_MSG_CANNOT_EXPORT_SKIN'));
}
},
failure: function(r,o){
viewport.getEl().unmask();
PMExt.error(_('ID_SKINS'),_('ID_MSG_CANNOT_EXPORT_SKIN'));
}
});
}else{
PMExt.error(_('ID_SKINS'),_('ID_MSG_CANNOT_EXPORT_DEFAULT_SKIN'));
}
}
//Open New Calendar
NewCalendarAction = function(){
location.href = 'calendarEdit';
@@ -310,7 +424,11 @@ GridByDefault = function(){
//Do Search Function
DoSearch = function(){
infoGrid.store.load({params: {textFilter: searchText.getValue()}});
infoGrid.store.load({
params: {
textFilter: searchText.getValue()
}
});
};
//Edit Calendar Action
@@ -327,7 +445,10 @@ DeleteButtonAction = function(){
viewport.getEl().mask(_('ID_PROCESSING'));
Ext.Ajax.request({
url: 'calendar_Ajax',
params: {action: 'canDeleteCalendar', CAL_UID: rowSelected.data.CALENDAR_UID},
params: {
action: 'canDeleteCalendar',
CAL_UID: rowSelected.data.CALENDAR_UID
},
success: function(r,o){
viewport.getEl().unmask();
var resp = Ext.util.JSON.decode(r.responseText);
@@ -338,7 +459,10 @@ DeleteButtonAction = function(){
viewport.getEl().mask(_('ID_PROCESSING'));
Ext.Ajax.request({
url: 'calendar_Ajax',
params: {action: 'deleteCalendar', CAL_UID: rowSelected.data.CALENDAR_UID},
params: {
action: 'deleteCalendar',
CAL_UID: rowSelected.data.CALENDAR_UID
},
success: function(r,o){
viewport.getEl().unmask();
editButton.disable();
@@ -367,9 +491,17 @@ DeleteButtonAction = function(){
//Render Status
render_status = function(v){
switch(v){
case 'ACTIVE': return '<font color="green">' + _('ID_ACTIVE') + '</font>'; break;
case 'INACTIVE': return '<font color="red">' + _('ID_INACTIVE') + '</font>';; break;
case 'VACATION': return '<font color="blue">' + _('ID_VACATION') + '</font>';; break;
case 'ACTIVE':
return '<font color="green">' + _('ID_ACTIVE') + '</font>';
break;
case 'INACTIVE':
return '<font color="red">' + _('ID_INACTIVE') + '</font>';
;
break;
case 'VACATION':
return '<font color="blue">' + _('ID_VACATION') + '</font>';
;
break;
}
};
@@ -385,6 +517,9 @@ CopyButtonAction = function(){
UpdatePageConfig = function(pageSize){
Ext.Ajax.request({
url: 'calendar_Ajax',
params: {action:'updatePageSize', size: pageSize}
params: {
action:'updatePageSize',
size: pageSize
}
});
};