From 27df89b0aa1d9a5933d8bfb2dc9dbbd01af1502b Mon Sep 17 00:00:00 2001 From: lutranf Date: Wed, 27 Aug 2014 16:46:27 +0200 Subject: [PATCH] create table display on event "table not found" --- inc/databap.php | 11 ++++++++--- jquery/databap.js | 18 +++++++++++------- masks/table.html | 30 ++++++++++++++++++++++-------- todo | 1 + 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/inc/databap.php b/inc/databap.php index 2bd630d..5c3fef0 100644 --- a/inc/databap.php +++ b/inc/databap.php @@ -59,9 +59,13 @@ class Databap extends PhpObject const NAME_PASS_SEP = '-'; //HTTP Requests response - const DISCONNECTED = '__DISCONNECTED__'; const ERROR = '__ERROR__'; 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 //TODO Transfer these constants to chat page @@ -366,7 +370,7 @@ class Databap extends PhpObject 'version_date'=>self::VERSION_DATE, 'default_page'=>$sPage, '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, 'error'=>self::ERROR, 'keep_alive'=>self::KEEP_ALIVE, @@ -982,7 +986,7 @@ class Databap extends PhpObject $sRightTableLink = 'table '.self::getTableFormat($asTable['title']).''; $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); } @@ -1132,6 +1136,7 @@ class Databap extends PhpObject $asTable['title'] = self::getTableFormat($asTable['title']); $asTable['description'] = self::getDescriptionFormat($asTable['description']); $asTable['led'] = self::getDateFormat($asTable['led']); + //$asTable['keywords'] = ToolBox::findReplaceLinks($asTable['description']); } return $asTable; } diff --git a/jquery/databap.js b/jquery/databap.js index 7daeb2d..fa3263a 100644 --- a/jquery/databap.js +++ b/jquery/databap.js @@ -476,7 +476,7 @@ function Databap() data: vars, 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 { @@ -488,7 +488,7 @@ function Databap() }, 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.disconnected = true; @@ -817,22 +817,26 @@ function Databap() 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) { - msg = msg+'.'; - self.addMsgBefore(msg, 'error', elem); + self.addMsgBefore(this.addPunctuation(msg), 'error', elem); }; this.addWarningBefore = function(msg, elem) { - msg = 'Attention : '+msg+'.'; + msg = 'Attention : '+this.addPunctuation(msg); self.addMsgBefore(msg, 'warning', elem); }; this.addSuccessBefore = function(msg, elem) { - msg = msg+'.'; - self.addMsgBefore(msg, 'success', elem); + self.addMsgBefore(this.addPunctuation(msg), 'success', elem); }; this.addMsgBefore = function(msg, msgClass, elem) diff --git a/masks/table.html b/masks/table.html index b5e3a27..f5b018b 100644 --- a/masks/table.html +++ b/masks/table.html @@ -43,7 +43,7 @@ databap.onResize = function() //self.maximizeElem($('#keywords'), false, $('#table')); }; -function Table(iTableId) +function Table(oTable) { this.DISPLAY_EDIT = 'edit'; @@ -54,8 +54,9 @@ function Table(iTableId) this.ERROR_CLASS = 'form_error'; this.sDisplay = ''; - this.iTableId = iTableId || 0; - this.sTableName = ''; + this.oTable = oTable; + this.iTableId = ($.type(oTable)=='number')?oTable:0; + this.sTableName = ($.type(oTable)=='string')?oTable:''; this.sFeedBackBoxId = '#validation'; tableself = this; @@ -64,7 +65,7 @@ function Table(iTableId) $('#validation').addButton('dummy', '', function(){}, this.ACTION_BTN_ID, '', 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(); } @@ -80,8 +81,21 @@ Table.prototype.applyTableInfo = function() { if(asData.result == databap.consts.error) { - tableself.setDisplay(tableself.DISPLAY_ERROR); - databap.addErrorBefore(asData.desc, tableself.sFeedBackBoxId); + if(asData.desc == databap.consts.errors.not_found) + { + 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 { @@ -97,7 +111,7 @@ Table.prototype.applyTableInfo = function() databap.updateScrollBar(); } }, - {id:this.iTableId}, + {id:this.oTable}, 'json', function(){debug('Error: Unknown error thrown');}, true @@ -146,7 +160,7 @@ Table.prototype.save = function() { if(asData.result == databap.consts.success) { - databap.goToInternalLink('table', asData.name.toLowerCase()); + databap.goToInternalLink('table', asData.name.toUpperCase()); //tableself.iTableId = asData.name; //tableself.applyTableInfo(); } diff --git a/todo b/todo index 81a727a..98384e7 100644 --- a/todo +++ b/todo @@ -5,6 +5,7 @@ Internal: - independant code/procedure/article/table/document php classes ? - Admin param page - Independant Option Class +- put feedback box in title Bug fix: - [1.0.0] Tab dans chat