Skip to content

Commit

Permalink
#170 done
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil committed Oct 25, 2024
1 parent da30bdb commit f1d0592
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
44 changes: 30 additions & 14 deletions js/pages/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class cDetailTags {
}

//###############################################################
//# cDetailImage
//# cDetailSolButtons
//###############################################################
class cDetailSolButtons {
static SOL_CHILD_ID = 's'
Expand Down Expand Up @@ -451,7 +451,7 @@ class cDetailImage {
}

//###############################################################
//# cDetailImage
//# cDetailHighlight
//###############################################################
class cDetailHighlight {
static onLoad() {
Expand Down Expand Up @@ -513,6 +513,32 @@ class cDetailHighlight {
}
}

//###############################################################
//# cDetailComments
//###############################################################
class cDetailComments {
//***************************************************************************
static killWidget() {
var oComment = cJquery.element(cDetailPageConstants.COMMENTS_CONTAINER_ID)
const oWidget = oComment.data('ckCommentbox') // capitalise the first letter of the widget
if (oWidget) oWidget.destroy()
}

//***************************************************************************
static init_widget() {
this.killWidget()

var oComment = cJquery.element(cDetailPageConstants.COMMENTS_CONTAINER_ID)
oComment.commentbox({
mission: cMission,
sol: cDetail.sol,
product: cDetail.product,
instrument: cDetail.instrument,
read_only: false
})
}
}

//###############################################################
//# cImageButtons
//###############################################################
Expand Down Expand Up @@ -748,18 +774,8 @@ class cDetail {
// get the tags
cDetailTags.get_tags()

// render comments
var oComment = cJquery.element('commentContainer')
const oWidget = oComment.data('ckCommentbox') // capitalise the first letter of the widget
if (oWidget) oWidget.destroy()

oComment.commentbox({
mission: cMission,
sol: this.sol,
product: this.product,
instrument: this.instrument,
read_only: false
})
//init the comments widget
cDetailComments.init_widget()
}

//***************************************************************
Expand Down
18 changes: 11 additions & 7 deletions js/widgets/comment-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ class cCommentBox {
const oThis = this

//----------- hook onto facebook user - if readonly skip
if (!this.options.read_only) bean.on(cFacebook, cFacebook.STATUS_EVENT, () => oThis.onFacebookUser())

this.get_comments()
}

Expand All @@ -92,17 +90,18 @@ class cCommentBox {
var sProduct = this.options.product
var sInstr = this.options.instrument
cDebug.write('getting comments for s:' + sSOl + ' p:' + sProduct + ' i:' + sInstr)
cComments.get(sSOl, sInstr, sProduct, d => oThis.onGotComments(d))
cComments.get(sSOl, sInstr, sProduct, d => oThis.onCommentsResponse(d))
}

//*************************************************************
//* Events
//*************************************************************
onFacebookUser() {
enableEditor() {
var oElement = this.element

//-----------if readonly dont enable anything
if (this.options.read_only) return
if (cAuth.user == null) return

//-----------enable the button
var sBUT_ID = cJquery.child_ID(oElement, this.COMMENTS_BUTTON_ID)
Expand Down Expand Up @@ -138,20 +137,25 @@ class cCommentBox {
}

//*************************************************************
onGotComments(poHttp) {
onCommentsResponse(poHttp) {
var oElement = this.element
var sCommentsID = cJquery.child_ID(oElement, this.COMMENTS_DISPLAY_ID)
var oData = poHttp.response

// enable the editor
this.enableEditor()

// display the comments
var oDiv = cJquery.element(sCommentsID)
oDiv.empty()

if (!oData) {
oDiv.append('No Comments - be the first !')
} else {
for (var i = 0; i < oData.length; i++) {
var sText = decodeURIComponent(oData[i].c)
var sUser = oData[i].u
var oItem = oData[i]
var sText = decodeURIComponent(oItem.c)
var sUser = oItem.u
if (sUser === '') sUser = 'anonymous'

var oCommentDiv = $('<DIV>', {
Expand Down

0 comments on commit f1d0592

Please sign in to comment.