Add delete button on docs
This commit is contained in:
11
inc/catc.php
11
inc/catc.php
@@ -150,12 +150,19 @@ class CATC extends Main
|
||||
return self::getJsonResult(!empty($asDocList), '', $asDocList);
|
||||
}
|
||||
|
||||
public function uploadDoc($iCourseId)
|
||||
{
|
||||
public function uploadDoc($iCourseId) {
|
||||
$this->oClassManagement->incClass('uploader', true);
|
||||
$oDoc = new Doc($this->oDb, $this->oAuth->getUserId(), $iCourseId);
|
||||
$oUploader = new Uploader($oDoc);
|
||||
|
||||
return $oUploader->sBody;
|
||||
}
|
||||
|
||||
public function deleteDoc($iDocId) {
|
||||
$oDoc = new Doc($this->oDb);
|
||||
$oDoc->setDocId($iDocId);
|
||||
$bResult = $oDoc->delete();
|
||||
|
||||
return self::getJsonResult($bResult, '');
|
||||
}
|
||||
}
|
||||
21
inc/doc.php
21
inc/doc.php
@@ -14,7 +14,7 @@ class Doc extends PhpObject {
|
||||
private $iUserId;
|
||||
private $iCourseId;
|
||||
|
||||
public function __construct(Db &$oDb, $iUserId, $iCourseId)
|
||||
public function __construct(Db &$oDb, $iUserId=0, $iCourseId=0)
|
||||
{
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
@@ -53,13 +53,24 @@ class Doc extends PhpObject {
|
||||
return $bResult?'':'error_db';
|
||||
}
|
||||
|
||||
public function delete($sFileName) {
|
||||
public function delete() {
|
||||
if($this->iDocId > 0) {
|
||||
$asDoc = $this->getDoc();
|
||||
$bResult = $this->oDb->deleteRow(self::DOC_TABLE, $this->iDocId);
|
||||
if($bResult) $bResult = unlink($asDoc['filepath']);
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
public function getList() {
|
||||
$this->oDb->setTrace(true);
|
||||
$asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$this->getDocKeys()));
|
||||
public function getDoc() {
|
||||
$asDocList = $this->getList(array(Db::getId(self::DOC_TABLE) => $this->iDocId));
|
||||
return array_shift($asDocList);
|
||||
}
|
||||
|
||||
public function getList($asConstraint=array()) {
|
||||
$asKeys = empty($asConstraint)?$this->getDocKeys():$asConstraint;
|
||||
$asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$asKeys));
|
||||
foreach($asDocs as &$asDoc) $asDoc['filepath'] = self::getFilePath($asDoc['filename']);
|
||||
|
||||
return $asDocs;
|
||||
|
||||
@@ -60,6 +60,9 @@ elseif($sAction!='' && $bLoggedIn)
|
||||
case 'upload_doc':
|
||||
$sResult = $oCATC->uploadDoc($iId);
|
||||
break;
|
||||
case 'delete_doc':
|
||||
$sResult = $oCATC->deleteDoc($iId);
|
||||
break;
|
||||
case 'get_docs':
|
||||
$sResult = $oCATC->getDocs($iId);
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
<div id="notes"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="template-items">
|
||||
<div class="doc-item btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-outline-primary btn-labeled shadow-sm" href="" target="_blank"><span class="btn-label"><i class="fal file"></i></span><span class="btn-desc"></span></a>
|
||||
<button type="button" class="delete btn btn-danger"><i class="fal fa-delete"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
oCATC.pageInit = function(asHash, bFirstPage) {
|
||||
self.tmp('id_course', asHash.items[0]);
|
||||
@@ -50,10 +56,10 @@ oCATC.pageInit = function(asHash, bFirstPage) {
|
||||
oCATC.feedback('notice', sMsg);
|
||||
});
|
||||
loadDocs();
|
||||
},
|
||||
}/*,
|
||||
progressall: function (e, asData) {
|
||||
$('#progress .bar').css('width', parseInt(asData.loaded / asData.total * 100, 10)+'%');
|
||||
}
|
||||
}*/
|
||||
});
|
||||
loadDocs();
|
||||
};
|
||||
@@ -66,10 +72,22 @@ function loadDocs() {
|
||||
Tools.ajax(
|
||||
'get_docs',
|
||||
(asData) => {
|
||||
var $DocList = $('#doc_list').empty();
|
||||
$.each(asData, function(iKey, asDoc){
|
||||
$('#doc_list').append($('<a>', {'class':'item', href:asDoc.filepath, target:'_blank'})
|
||||
.appendIcon('file-'+asDoc.type)
|
||||
.append(asDoc.filename));
|
||||
var $Item = oCATC.getTemplateItem('doc-item');
|
||||
$Item.find('.btn').addClass(asDoc.type).attr('href', asDoc.filepath);
|
||||
$Item.find('.file').addClass('fa-file-'+asDoc.type);
|
||||
$Item.find('.btn-desc').text(asDoc.filename);
|
||||
$Item.find('.delete').data('id', asDoc.id_doc).click(function(){
|
||||
Tools.ajax(
|
||||
'delete_doc',
|
||||
(asData) => {loadDocs();},
|
||||
{id: $(this).data('id')}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
$DocList.append($Item);
|
||||
});
|
||||
|
||||
},
|
||||
@@ -102,7 +120,7 @@ function save(bForce) {
|
||||
}
|
||||
else {
|
||||
var sContent = oEditor.getContent();
|
||||
if(oEditor.id != 0) {
|
||||
if(self.tmp('id_course') != 0) {
|
||||
self.tmp('saving', true);
|
||||
noteFeedback('info', 'Saving...');
|
||||
getInfo(
|
||||
|
||||
@@ -275,6 +275,10 @@ function CATC(asGlobals)
|
||||
asVarName.unshift('tmp');
|
||||
return self.vars(asVarName, oValue);
|
||||
};
|
||||
|
||||
this.getTemplateItem = function(sItemName) {
|
||||
return self.elem.$Main.find('.template-items').find('.'+sItemName).clone();
|
||||
}
|
||||
}
|
||||
|
||||
class Editor {
|
||||
|
||||
@@ -22,3 +22,17 @@ $font-family-base: $font_para;
|
||||
.alert-error {
|
||||
@extend .alert-danger;
|
||||
}
|
||||
|
||||
.btn.btn-labeled {
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
|
||||
.btn-label {
|
||||
position: relative;
|
||||
left: -12px;
|
||||
display: inline-block;
|
||||
padding: 6px 12px;
|
||||
background: rgba(0, 0, 0, 0.15);
|
||||
border-radius: 3px 0 0 3px;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,11 @@ $fa-css-prefix: fa;
|
||||
@import 'fa/rotated-flipped';
|
||||
@import 'fa/stacked';
|
||||
|
||||
//Common
|
||||
.#{$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); }
|
||||
|
||||
//Logon
|
||||
.#{$fa-css-prefix}-user:before { content: fa-content($fa-var-user); }
|
||||
.#{$fa-css-prefix}-password:before { content: fa-content($fa-var-key); }
|
||||
@@ -21,9 +26,6 @@ $fa-css-prefix: fa;
|
||||
.#{$fa-css-prefix}-settings:before { content: fa-content($fa-var-cog); }
|
||||
.#{$fa-css-prefix}-logoff:before { content: fa-content($fa-var-sign-out); }
|
||||
|
||||
//Workshops
|
||||
.#{$fa-css-prefix}-previous:before { content: fa-content($fa-var-chevron-left); }
|
||||
|
||||
//Course
|
||||
.#{$fa-css-prefix}-file-upload:before { content: fa-content($fa-var-file-upload); }
|
||||
.#{$fa-css-prefix}-file-image:before { content: fa-content($fa-var-file-image); }
|
||||
|
||||
@@ -12,24 +12,12 @@
|
||||
}
|
||||
|
||||
#doc_list {
|
||||
background: $gray-400;
|
||||
border-radius: 0.5em;
|
||||
height: calc(100% - 41.35px);
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
|
||||
a.item {
|
||||
display: block;
|
||||
padding: 0.5em 1em;
|
||||
width: 100%;
|
||||
|
||||
i.fal {
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
&:first-child {
|
||||
padding-top: 1em;
|
||||
}
|
||||
.btn {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,8 +47,8 @@
|
||||
#notes {
|
||||
width: 100%;
|
||||
height: calc(100% - 43.35px);
|
||||
background: $gray-400;
|
||||
border-radius: 0.5em;
|
||||
border: 2px solid $gray-400;
|
||||
@include catc-round(0.5em);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,10 @@ a:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@mixin catc-round($radius) {
|
||||
border-radius: 0 $radius $radius $radius;
|
||||
}
|
||||
|
||||
/* Common Classes - Containers */
|
||||
|
||||
#container {
|
||||
@@ -45,6 +49,10 @@ a:hover {
|
||||
bottom: 1em;
|
||||
}
|
||||
|
||||
.template-items {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Common Classes - Inputs */
|
||||
|
||||
a.button {
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
sass --style=compressed --watch catc.scss:catc.css
|
||||
sass --style=compressed --watch catc.scss:catc.css --poll
|
||||
Reference in New Issue
Block a user