Definitions v1
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@
|
||||
/settings.php
|
||||
/files/*
|
||||
!/files/.htaccess
|
||||
!/files/db/
|
||||
11
files/db/update_v1_to_v2.sql
Normal file
11
files/db/update_v1_to_v2.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE `definitions` (
|
||||
`id_definition` int(10) UNSIGNED auto_increment,
|
||||
`id_user` int(10) UNSIGNED,
|
||||
`title` VARCHAR(50),
|
||||
`description` VARCHAR(500),
|
||||
`led` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id_definition`),
|
||||
UNIQUE KEY `uni_def_title` (`title`));
|
||||
|
||||
ALTER TABLE definitions ADD INDEX(`id_user`);
|
||||
ALTER TABLE definitions ADD FOREIGN KEY (`id_user`) REFERENCES users(`id_user`);
|
||||
26
inc/catc.php
26
inc/catc.php
@@ -14,7 +14,8 @@ class CATC extends Main
|
||||
array('name'=>'auth', 'project'=>true),
|
||||
array('name'=>'course', 'project'=>true),
|
||||
array('name'=>'note', 'project'=>true),
|
||||
array('name'=>'doc', 'project'=>true)
|
||||
array('name'=>'doc', 'project'=>true),
|
||||
array('name'=>'definition', 'project'=>true)
|
||||
);
|
||||
parent::__construct($oClassManagement, $sProcessPage, $asClasses);
|
||||
|
||||
@@ -37,8 +38,9 @@ class CATC extends Main
|
||||
(
|
||||
Auth::USER_TABLE => array(Db::getText(Auth::USER_TABLE), 'nickname', 'pass', 'cookie'),
|
||||
Course::WS_TABLE => array('dates'),
|
||||
Course::COURSE_TABLE=> array(Db::getId('workshops'), 'description', 'timeslot'),
|
||||
'notes' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'),
|
||||
Course::COURSE_TABLE => array(Db::getId('workshops'), 'description', 'timeslot'),
|
||||
Note::NOTE_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'),
|
||||
Definition::DEF_TABLE => array(Db::getId(Auth::USER_TABLE), 'title', 'description'),
|
||||
Doc::DOC_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'filename'),
|
||||
'todos' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'description')
|
||||
),
|
||||
@@ -49,6 +51,7 @@ class CATC extends Main
|
||||
'pass' => "VARCHAR(256) NOT NULL",
|
||||
'cookie' => "VARCHAR(255)",
|
||||
'dates' => "VARCHAR(50)",
|
||||
'title' => "VARCHAR(50)",
|
||||
'description' => "VARCHAR(200)",
|
||||
'timeslot' => "ENUM('SAT-M', 'SAT-A', 'SUN-M', 'SUN-A')",
|
||||
'notes' => "LONGTEXT",
|
||||
@@ -57,7 +60,8 @@ class CATC extends Main
|
||||
),
|
||||
'constraints' => array
|
||||
(
|
||||
Doc::DOC_TABLE => "UNIQUE KEY `uni_file` (`filename`)"
|
||||
Doc::DOC_TABLE => "UNIQUE KEY `uni_file` (`filename`)",
|
||||
Definition::DEF_TABLE => "UNIQUE KEY `uni_def_title` (`title`)"
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -160,4 +164,18 @@ class CATC extends Main
|
||||
|
||||
return self::getJsonResult($bResult, '');
|
||||
}
|
||||
|
||||
/* Defs */
|
||||
|
||||
public function getDefs() {
|
||||
$oDef = new Definition($this->oDb, $this->oAuth->getUserId());
|
||||
return self::getJsonResult(true, '', $oDef->getDefinitions());
|
||||
}
|
||||
|
||||
public function setDef($iDefId, $sTitle, $sDesc) {
|
||||
$bNew = ($iDefId == 0);
|
||||
$oDef = new Definition($this->oDb, $this->oAuth->getUserId(), $iDefId);
|
||||
$bResult = $oDef->setDefinition($sTitle, $sDesc);
|
||||
return self::getJsonResult($bResult, '', array('new_def'=>$bNew, 'def'=>$oDef->getDefinition()));
|
||||
}
|
||||
}
|
||||
59
inc/definition.php
Normal file
59
inc/definition.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
class Definition extends PhpObject {
|
||||
|
||||
const DEF_TABLE = 'definitions';
|
||||
|
||||
/**
|
||||
* DB
|
||||
* @var Db
|
||||
*/
|
||||
private $oDb;
|
||||
private $iDefId;
|
||||
private $iUserId;
|
||||
|
||||
public function __construct(Db &$oDb, $iUserId=0, $iDefId=0)
|
||||
{
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
$this->setUserId($iUserId);
|
||||
$this->setDefId($iDefId);
|
||||
}
|
||||
|
||||
public function setUserId($iUserId) {
|
||||
$this->iUserId = $iUserId;
|
||||
}
|
||||
|
||||
public function setDefId($iDefId) {
|
||||
$this->iDefId = $iDefId;
|
||||
}
|
||||
|
||||
public function getDefinitions($iDefId=0) {
|
||||
$asConstraints = array(Db::getId(Auth::USER_TABLE)=>$this->iUserId);
|
||||
if($iDefId > 0) $asConstraints[Db::getId(self::DEF_TABLE)] = $iDefId;
|
||||
|
||||
$asDefs = $this->oDb->selectRows(array('from'=>self::DEF_TABLE, 'constraint'=>$asConstraints), Db::getId(self::DEF_TABLE));
|
||||
return $asDefs;
|
||||
}
|
||||
|
||||
public function getDefinition() {
|
||||
$asDef = array();
|
||||
if($this->iDefId > 0) {
|
||||
$asDef = $this->getDefinitions($this->iDefId);
|
||||
if(!empty($asDef)) $asDef = array_shift($asDef);
|
||||
}
|
||||
return $asDef;
|
||||
}
|
||||
|
||||
public function setDefinition($sTitle, $sDesc) {
|
||||
$asInfo = array(Db::getId(Auth::USER_TABLE)=>$this->iUserId, 'title'=>$sTitle, 'description'=>$sDesc);
|
||||
if($this->iDefId == 0) {
|
||||
$iDefId = $this->oDb->insertRow(self::DEF_TABLE, $asInfo);
|
||||
}
|
||||
else {
|
||||
$iDefId = $this->oDb->updateRow(self::DEF_TABLE, $this->iDefId, $asInfo);
|
||||
}
|
||||
$this->setDefId($iDefId);
|
||||
return ($iDefId > 0);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ $sNickName = isset($_REQUEST['nickname'])?$_REQUEST['nickname']:'';
|
||||
$iApiKey = isset($_GET['api'])?$_GET['api']:'';
|
||||
$sContent = isset($_POST['content'])?$_POST['content']:'';
|
||||
$iId = isset($_REQUEST['id'])?$_REQUEST['id']:0;
|
||||
$sTitle = isset($_REQUEST['title'])?$_REQUEST['title']:'';
|
||||
$sDesc = isset($_REQUEST['description'])?$_REQUEST['description']:'';
|
||||
|
||||
//Initiate class
|
||||
$oCATC = new CATC($oClassManagement, __FILE__);
|
||||
@@ -63,6 +65,12 @@ elseif($sAction!='' && $bLoggedIn)
|
||||
case 'get_docs':
|
||||
$sResult = $oCATC->getDocs($iId);
|
||||
break;
|
||||
case 'get_defs':
|
||||
$sResult = $oCATC->getDefs();
|
||||
break;
|
||||
case 'set_def':
|
||||
$sResult = $oCATC->setDef($iId, $sTitle, $sDesc);
|
||||
break;
|
||||
default:
|
||||
$sResult = CATC::getJsonResult(false, CATC::NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
<script type="text/javascript">
|
||||
oCATC.pageInit = function(asHash, bFirstPage)
|
||||
{
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
$(window).keyup(function(e) {
|
||||
if(e.which==13) {
|
||||
if($('#signin').is(':visible')) $('#signin').click();
|
||||
|
||||
@@ -4,9 +4,19 @@
|
||||
<div id="logo_box"><a href="#workshops"></a></div>
|
||||
</div>
|
||||
<div id="menu">
|
||||
<ul>
|
||||
<li><input type="text" id="dico" name="dico" /></li><li><a href="#workshops" class="button fal fa-home"></a></li><li><a href="#logoff" class="button fal fa-logoff"></a></li>
|
||||
</ul>
|
||||
<nav class="navbar navbar-expand p-0 justify-content-end">
|
||||
<form class="container-fluid">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend"><span class="input-group-text"><i class="fal fa-search"></i></span></div>
|
||||
<input id="search" class="form-control my-0" type="search" placeholder="Search" aria-label="Search" autocomplete="off" />
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-primary" type="button" id="add_def" data-toggle="modal" data-id="0" data-target="#add-def"><i class="fal fa-add"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<button class="home btn btn-outline-primary mr-2 ml-2 my-0" type="submit"><i class="fal fa-home"></i></button>
|
||||
<button class="logoff btn btn-outline-primary my-0" type="submit"><i class="fal fa-logoff"></i></button>
|
||||
</form>
|
||||
</nav>
|
||||
</div>
|
||||
<div id="main_title"><h1></h1></div>
|
||||
<div id="main"></div>
|
||||
@@ -16,3 +26,29 @@
|
||||
<footer>
|
||||
<span>Designed and powered by Franzz & Clarita - CATC Notes Project under <a href="http://www.gnu.org/licenses/gpl.html" target="_blank">GPLv3</a> License</span>
|
||||
</footer>
|
||||
<div id="add-def" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="add_def_title" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="add_def_title"></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"><i class="fal fa-close"></i></span></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="def_form">
|
||||
<input type="hidden" id="def_id" name="id" />
|
||||
<div class="form-group">
|
||||
<label for="def_title">Term to define</label>
|
||||
<input type="text" class="form-control" id="def_title" name="title" placeholder="Term">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="def_description">Definition</label>
|
||||
<textarea class="form-control" id="def_description" name="description" placeholder="Definition"></textarea>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="save" type="button" class="btn btn-primary" data-dismiss="modal">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -55,8 +55,50 @@ function CATC(asGlobals)
|
||||
|
||||
this.initMenu = function()
|
||||
{
|
||||
self.elem.$Menu.find('.fa-home').attr('href', '#'+self.consts.default_page);
|
||||
self.elem.$Menu.show('fast');
|
||||
//Search
|
||||
self.refreshDefs();
|
||||
self.elem.$Menu.find('#search').addSearch('defs');
|
||||
$('#add-def').on('show.bs.modal', function (event) {
|
||||
var $Button = $(event.relatedTarget);
|
||||
var iDefId = $Button.data('id');
|
||||
var $Modal = $(this);
|
||||
|
||||
var asDef = iDefId?self.vars(['lov-defs', iDefId]):{'title':'', 'description':''};
|
||||
$Modal.find('#add_def_title').text(iDefId?'Update a definition':'Add a new definition');
|
||||
$Modal.find('#def_id').val(iDefId);
|
||||
$Modal.find('#def_title').val(asDef.title);
|
||||
$Modal.find('#def_description').val(asDef.description);
|
||||
|
||||
var asParams = Tools.serialize('def_form');
|
||||
$Modal.find('#save').off('click').click(function(){
|
||||
Tools.ajax(
|
||||
'set_def',
|
||||
function(asData){
|
||||
self.onFeedback('success', 'Definition of "'+asData.def.title+'" '+(asData.new_def?'added':'updated'));
|
||||
self.refreshDefs();
|
||||
},
|
||||
'def_form'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
self.elem.$Menu.find('.home').click(function(){self.setHash(self.consts.default_page);});
|
||||
self.elem.$Menu.find('.logoff').click(function(){self.setHash('logoff');});
|
||||
self.elem.$Menu.slideDown('fast');
|
||||
};
|
||||
|
||||
this.refreshDefs = function() {
|
||||
Tools.ajax(
|
||||
'get_defs',
|
||||
(asData) => {
|
||||
self.vars('lov-defs', asData);
|
||||
$.each(self.vars('lov-defs'), function(iKey, asValues) {
|
||||
self.vars(['lov-defs', iKey, 'safe_title'], removeDiacritics(asValues['title']));
|
||||
self.vars(['lov-defs', iKey, 'label'], asValues['description']);
|
||||
self.vars(['lov-defs', iKey, 'safe_label'], removeDiacritics(asValues['description']));
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.setSideElemVisibility = function() {
|
||||
@@ -238,7 +280,10 @@ function CATC(asGlobals)
|
||||
$FadeInElem.html($Dom);
|
||||
|
||||
//Show main
|
||||
$FadeInElem.fadeTo('fast', 1, function(){self.pageInit(asHash, bFirstPage);});
|
||||
$FadeInElem.fadeTo('fast', 1, function(){
|
||||
self.pageInit(asHash, bFirstPage);
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
};
|
||||
|
||||
/* Variables Handling */
|
||||
@@ -277,7 +322,7 @@ function CATC(asGlobals)
|
||||
};
|
||||
|
||||
this.getTemplateItem = function(sItemName) {
|
||||
return self.elem.$Main.find('.template-items').find('.'+sItemName).clone();
|
||||
return $('.template-items').find('.'+sItemName).clone();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,85 @@ function copyArray(asArray)
|
||||
return asArray.slice(0); //trick to copy array
|
||||
}
|
||||
|
||||
$.prototype.addSearch = function(sSection)
|
||||
{
|
||||
$(this)
|
||||
.autocomplete({
|
||||
autoFocus: true,
|
||||
delay: 0,
|
||||
section:sSection,
|
||||
source: function(oRequest, fResponse) {
|
||||
var sTerm = removeDiacritics(oRequest.term);
|
||||
var rMatcher = new RegExp($.ui.autocomplete.escapeRegex(sTerm), 'i');
|
||||
var asResults = [];
|
||||
|
||||
var asData = self.vars('lov-'+this.options.section);
|
||||
$.each(asData, function(iDefId, oItem) {
|
||||
var oTitleMatch = oItem.safe_title.match(rMatcher);
|
||||
var oLabelMatch = oItem.safe_label.match(rMatcher);
|
||||
if(oTitleMatch) {
|
||||
oItem.index = parseInt(oTitleMatch.index, 10);
|
||||
oItem.size = oTitleMatch[0].length;
|
||||
oItem.field = 'title';
|
||||
asResults.push(oItem);
|
||||
}
|
||||
else if(oLabelMatch) {
|
||||
oItem.index = parseInt(oLabelMatch.index, 10);
|
||||
oItem.size = oLabelMatch[0].length;
|
||||
oItem.field = 'label';
|
||||
asResults.push(oItem);
|
||||
}
|
||||
oItem.id = iDefId;
|
||||
});
|
||||
|
||||
$('#add_def')
|
||||
.toggleClass('btn-outline-primary', (asResults.length > 0))
|
||||
.toggleClass('btn-primary', (asResults.length == 0));
|
||||
|
||||
fResponse(asResults);
|
||||
}
|
||||
}
|
||||
)
|
||||
.data("ui-autocomplete")._renderItem = function(ul, item) {
|
||||
|
||||
var fGetHighLightedContent = function(sContent, iIndex, iSize){
|
||||
return $('<span>')
|
||||
.append(sContent.substr(0, iIndex))
|
||||
.append($('<span>', {'class':'highlight text-secondary'}).text(sContent.substr(iIndex, iSize)))
|
||||
.append(sContent.substr(iIndex + iSize));
|
||||
};
|
||||
var $Title = $('<div>', {'class':'title text-break text-capitalize font-weight-bold text-primary'});
|
||||
var $Desc = $('<div>', {'class':'desc text-break'});
|
||||
|
||||
if(item.field=='title') {
|
||||
$Title.append(fGetHighLightedContent(item.title, item.index, item.size));
|
||||
$Desc.text(item.label);
|
||||
}
|
||||
else {
|
||||
$Title.text(item.title);
|
||||
$Desc.append(fGetHighLightedContent(item.label, item.index, item.size));
|
||||
}
|
||||
return $('<li>', {'class':'list-group-item shadow'})
|
||||
.css('width', $('#search').outerWidth())
|
||||
.data("item.autocomplete", item)
|
||||
.append($('<div>', {'class':'row'})
|
||||
.append($('<div>', {'class':'col'})
|
||||
.append($Title)
|
||||
.append($Desc)
|
||||
)
|
||||
.append($('<div>', {'class':'col-auto d-flex align-items-center'}).append($('<button>', {'class':'btn btn-outline-secondary'})
|
||||
.data('id', item.id)
|
||||
.attr('data-toggle', 'modal')
|
||||
.attr('data-target', '#add-def')
|
||||
.appendIcon('edit')
|
||||
))
|
||||
)
|
||||
.appendTo(ul);
|
||||
};
|
||||
|
||||
$($(this).data("ui-autocomplete").classesElementLookup['ui-front']).addClass('list-group');
|
||||
}
|
||||
|
||||
$.prototype.appendIcon = function(sIcon, bFull) {
|
||||
return $(this).append(Tools.getIcon(sIcon, bFull));
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -36,3 +36,7 @@ $font-family-base: $font_para;
|
||||
border-radius: 3px 0 0 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
box-shadow: none;
|
||||
}
|
||||
@@ -16,14 +16,16 @@ $fa-css-prefix: fa;
|
||||
.#{$fa-css-prefix}-previous:before { content: fa-content($fa-var-chevron-left); }
|
||||
.#{$fa-css-prefix}-next:before { content: fa-content($fa-var-chevron-right); }
|
||||
.#{$fa-css-prefix}-delete:before { content: fa-content($fa-var-trash-alt); }
|
||||
.#{$fa-css-prefix}-edit:before { content: fa-content($fa-var-pencil); }
|
||||
.#{$fa-css-prefix}-add:before { content: fa-content($fa-var-plus); }
|
||||
|
||||
//Logon
|
||||
.#{$fa-css-prefix}-user:before { content: fa-content($fa-var-user); }
|
||||
.#{$fa-css-prefix}-password:before { content: fa-content($fa-var-key); }
|
||||
|
||||
//Menu
|
||||
.#{$fa-css-prefix}-search:before { content: fa-content($fa-var-search); }
|
||||
.#{$fa-css-prefix}-home:before { content: fa-content($fa-var-home); }
|
||||
.#{$fa-css-prefix}-settings:before { content: fa-content($fa-var-cog); }
|
||||
.#{$fa-css-prefix}-logoff:before { content: fa-content($fa-var-sign-out); }
|
||||
|
||||
//Course
|
||||
|
||||
@@ -143,20 +143,17 @@ a.button:active {
|
||||
right: 0;
|
||||
width: 50%;
|
||||
height: 111px;
|
||||
text-align: right;
|
||||
|
||||
a.button {
|
||||
margin-top: calc( ( 110px - 40px ) /2 );
|
||||
.navbar {
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: none;
|
||||
/* Search bar */
|
||||
|
||||
li {
|
||||
display: inline;
|
||||
margin-left: 1em;
|
||||
}
|
||||
}
|
||||
.ui-helper-hidden-accessible {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Main */
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user