create table display on event "table not found"

This commit is contained in:
lutranf
2014-08-27 16:46:27 +02:00
parent a9d54bcc4a
commit 27df89b0aa
4 changed files with 42 additions and 18 deletions

View File

@@ -59,9 +59,13 @@ class Databap extends PhpObject
const NAME_PASS_SEP = '-'; const NAME_PASS_SEP = '-';
//HTTP Requests response //HTTP Requests response
const DISCONNECTED = '__DISCONNECTED__';
const ERROR = '__ERROR__'; const ERROR = '__ERROR__';
const SUCCESS = '__SUCCESS__'; const SUCCESS = '__SUCCESS__';
const DISCONNECTED = '__DISCONNECTED__';
const NOT_FOUND = '__NOT_FOUND__';
const FAIL_INSERT = '__FAIL_INSERT__';
const FAIL_UPDATE = '__FAIL_UPDATE__';
const FAIL_DELETE = '__FAIL_DELETE__';
//Chat Constants //Chat Constants
//TODO Transfer these constants to chat page //TODO Transfer these constants to chat page
@@ -366,7 +370,7 @@ class Databap extends PhpObject
'version_date'=>self::VERSION_DATE, 'version_date'=>self::VERSION_DATE,
'default_page'=>$sPage, 'default_page'=>$sPage,
'default_id'=>$oItemId, 'default_id'=>$oItemId,
'disconnected'=>self::DISCONNECTED, 'errors'=>array('disconnected'=>self::DISCONNECTED, 'not_found'=>self::NOT_FOUND, 'insert'=>self::FAIL_INSERT, 'update'=>self::FAIL_UPDATE, 'delete'=>self::FAIL_DELETE),
'success'=>self::SUCCESS, 'success'=>self::SUCCESS,
'error'=>self::ERROR, 'error'=>self::ERROR,
'keep_alive'=>self::KEEP_ALIVE, 'keep_alive'=>self::KEEP_ALIVE,
@@ -982,7 +986,7 @@ class Databap extends PhpObject
$sRightTableLink = '<a href="'.$this->getInternalLink('table', $asTable['title']).'" target="_blank">table '.self::getTableFormat($asTable['title']).'</a>'; $sRightTableLink = '<a href="'.$this->getInternalLink('table', $asTable['title']).'" target="_blank">table '.self::getTableFormat($asTable['title']).'</a>';
$asTable['warning'] = ($bReadById && $iTableId!=$this->getUpToDateId(self::TABL_TABLE, $iTableId))?'Il existe une documentation plus à jour pour la '.$sRightTableLink:''; $asTable['warning'] = ($bReadById && $iTableId!=$this->getUpToDateId(self::TABL_TABLE, $iTableId))?'Il existe une documentation plus à jour pour la '.$sRightTableLink:'';
} }
else $sDesc = 'Table '.$oTableId.' introuvable'; else $sDesc = self::NOT_FOUND;
return $this->getJsonPostResult($bSuccess, $sDesc, $asTable); return $this->getJsonPostResult($bSuccess, $sDesc, $asTable);
} }
@@ -1132,6 +1136,7 @@ class Databap extends PhpObject
$asTable['title'] = self::getTableFormat($asTable['title']); $asTable['title'] = self::getTableFormat($asTable['title']);
$asTable['description'] = self::getDescriptionFormat($asTable['description']); $asTable['description'] = self::getDescriptionFormat($asTable['description']);
$asTable['led'] = self::getDateFormat($asTable['led']); $asTable['led'] = self::getDateFormat($asTable['led']);
//$asTable['keywords'] = ToolBox::findReplaceLinks($asTable['description']);
} }
return $asTable; return $asTable;
} }

18
jquery/databap.js vendored
View File

@@ -476,7 +476,7 @@ function Databap()
data: vars, data: vars,
success: function(result) success: function(result)
{ {
if(result==self.consts.disconnected) databap.refresh(); if(result==self.consts.errors.disconnected) databap.refresh();
else if((result==self.consts.error || typeof result.success != 'undefined' && result.success==self.consts.error) && typeof fOnError !== 'undefined') fOnError(); else if((result==self.consts.error || typeof result.success != 'undefined' && result.success==self.consts.error) && typeof fOnError !== 'undefined') fOnError();
else else
{ {
@@ -488,7 +488,7 @@ function Databap()
}, },
error: function(jqXHR, textStatus, errorThrown) error: function(jqXHR, textStatus, errorThrown)
{ {
if(jqXHR.responseText==self.consts.disconnected) databap.refresh(); if(jqXHR.responseText==self.consts.errors.disconnected) databap.refresh();
self.vars.loading = false; self.vars.loading = false;
self.vars.disconnected = true; self.vars.disconnected = true;
@@ -817,22 +817,26 @@ function Databap()
return self.consts.mask_folder+sPageName+'.html?'+self.consts.time; return self.consts.mask_folder+sPageName+'.html?'+self.consts.time;
}; };
this.addPunctuation = function(sMsg)
{
var asPunctuations = ['?', '!', '.', ',', ':', ';', '-', '/'];
return sMsg+($.inArray(sMsg.slice(-1), asPunctuations)==-1?'.':'');
};
this.addErrorBefore = function(msg, elem) this.addErrorBefore = function(msg, elem)
{ {
msg = msg+'.'; self.addMsgBefore(this.addPunctuation(msg), 'error', elem);
self.addMsgBefore(msg, 'error', elem);
}; };
this.addWarningBefore = function(msg, elem) this.addWarningBefore = function(msg, elem)
{ {
msg = 'Attention : '+msg+'.'; msg = 'Attention : '+this.addPunctuation(msg);
self.addMsgBefore(msg, 'warning', elem); self.addMsgBefore(msg, 'warning', elem);
}; };
this.addSuccessBefore = function(msg, elem) this.addSuccessBefore = function(msg, elem)
{ {
msg = msg+'.'; self.addMsgBefore(this.addPunctuation(msg), 'success', elem);
self.addMsgBefore(msg, 'success', elem);
}; };
this.addMsgBefore = function(msg, msgClass, elem) this.addMsgBefore = function(msg, msgClass, elem)

View File

@@ -43,7 +43,7 @@ databap.onResize = function()
//self.maximizeElem($('#keywords'), false, $('#table')); //self.maximizeElem($('#keywords'), false, $('#table'));
}; };
function Table(iTableId) function Table(oTable)
{ {
this.DISPLAY_EDIT = 'edit'; this.DISPLAY_EDIT = 'edit';
@@ -54,8 +54,9 @@ function Table(iTableId)
this.ERROR_CLASS = 'form_error'; this.ERROR_CLASS = 'form_error';
this.sDisplay = ''; this.sDisplay = '';
this.iTableId = iTableId || 0; this.oTable = oTable;
this.sTableName = ''; this.iTableId = ($.type(oTable)=='number')?oTable:0;
this.sTableName = ($.type(oTable)=='string')?oTable:'';
this.sFeedBackBoxId = '#validation'; this.sFeedBackBoxId = '#validation';
tableself = this; tableself = this;
@@ -64,7 +65,7 @@ function Table(iTableId)
$('#validation').addButton('dummy', '', function(){}, this.ACTION_BTN_ID, '', this.ACTION_BTN_ID); $('#validation').addButton('dummy', '', function(){}, this.ACTION_BTN_ID, '', this.ACTION_BTN_ID);
this.$Button = databap.tmp(this.ACTION_BTN_ID); this.$Button = databap.tmp(this.ACTION_BTN_ID);
if(this.iTableId>0 || this.iTableId!='') if(this.iTableId>0 || this.sTableName!='')
{ {
this.applyTableInfo(); this.applyTableInfo();
} }
@@ -80,8 +81,21 @@ Table.prototype.applyTableInfo = function()
{ {
if(asData.result == databap.consts.error) if(asData.result == databap.consts.error)
{ {
tableself.setDisplay(tableself.DISPLAY_ERROR); if(asData.desc == databap.consts.errors.not_found)
databap.addErrorBefore(asData.desc, tableself.sFeedBackBoxId); {
databap.addErrorBefore('Table '+tableself.oTable+' introuvable', tableself.sFeedBackBoxId);
if(tableself.sTableName!='')
{
tableself.setDisplay(tableself.DISPLAY_EDIT);
$('#title').val(tableself.sTableName).focus();
databap.addSuccessBefore('Mais vous pouvez la créer !', tableself.sFeedBackBoxId);
}
}
else
{
tableself.setDisplay(tableself.DISPLAY_ERROR);
databap.addErrorBefore(asData.desc, tableself.sFeedBackBoxId);
}
} }
else else
{ {
@@ -97,7 +111,7 @@ Table.prototype.applyTableInfo = function()
databap.updateScrollBar(); databap.updateScrollBar();
} }
}, },
{id:this.iTableId}, {id:this.oTable},
'json', 'json',
function(){debug('Error: Unknown error thrown');}, function(){debug('Error: Unknown error thrown');},
true true
@@ -146,7 +160,7 @@ Table.prototype.save = function()
{ {
if(asData.result == databap.consts.success) if(asData.result == databap.consts.success)
{ {
databap.goToInternalLink('table', asData.name.toLowerCase()); databap.goToInternalLink('table', asData.name.toUpperCase());
//tableself.iTableId = asData.name; //tableself.iTableId = asData.name;
//tableself.applyTableInfo(); //tableself.applyTableInfo();
} }

1
todo
View File

@@ -5,6 +5,7 @@ Internal:
- independant code/procedure/article/table/document php classes ? - independant code/procedure/article/table/document php classes ?
- Admin param page - Admin param page
- Independant Option Class - Independant Option Class
- put feedback box in title
Bug fix: Bug fix:
- [1.0.0] Tab dans chat - [1.0.0] Tab dans chat