Просмотр исходного кода

disabled button and modal for deleting attament when the user is guest

Yuki Takei 8 лет назад
Родитель
Сommit
48474cb472

+ 30 - 16
resource/js/components/PageAttachment.js

@@ -79,24 +79,23 @@ export default class PageAttachment extends React.Component {
     });
   }
 
-  render() {
-    const attachmentToDelete = this.state.attachmentToDelete;
-    let deleteModalClose = () => this.setState({ attachmentToDelete: null });
-    let showModal = attachmentToDelete !== null;
+  isUserLoggedIn() {
+    return this.props.crowi.me !== '';
+  }
 
-    let deleteInUse = null;
-    if (attachmentToDelete !== null) {
-      deleteInUse = this.state.inUse[attachmentToDelete._id] || false;
-    }
+  render() {
+    let deleteAttachmentModal = '';
+    if (this.isUserLoggedIn()) {
+      const attachmentToDelete = this.state.attachmentToDelete;
+      let deleteModalClose = () => this.setState({ attachmentToDelete: null });
+      let showModal = attachmentToDelete !== null;
+
+      let deleteInUse = null;
+      if (attachmentToDelete !== null) {
+        deleteInUse = this.state.inUse[attachmentToDelete._id] || false;
+      }
 
-    return (
-      <div>
-        <p>Attachments</p>
-        <PageAttachmentList
-          attachments={this.state.attachments}
-          inUse={this.state.inUse}
-          onAttachmentDeleteClicked={this.onAttachmentDeleteClicked}
-        />
+      deleteAttachmentModal = (
         <DeleteAttachmentModal
           show={showModal}
           animation={false}
@@ -108,6 +107,21 @@ export default class PageAttachment extends React.Component {
           deleteError={this.state.deleteError}
           onAttachmentDeleteClickedConfirm={this.onAttachmentDeleteClickedConfirm}
         />
+      );
+    }
+
+
+    return (
+      <div>
+        <p>Attachments</p>
+        <PageAttachmentList
+          attachments={this.state.attachments}
+          inUse={this.state.inUse}
+          onAttachmentDeleteClicked={this.onAttachmentDeleteClicked}
+          isUserLoggedIn={this.isUserLoggedIn()}
+        />
+
+        {deleteAttachmentModal}
       </div>
     );
   }

+ 6 - 1
resource/js/components/PageAttachment/Attachment.js

@@ -35,6 +35,10 @@ export default class Attachment extends React.Component {
 
     const fileType = <span className="attachment-filetype label label-default">{attachment.fileFormat}</span>;
 
+    const btnTrash = (this.props.isUserLoggedIn)
+        ? <a className="text-danger attachment-delete" onClick={this._onAttachmentDeleteClicked}><Icon name="trash-o" /></a>
+        : '';
+
     return (
       <li>
           <User user={attachment.creator} />
@@ -46,7 +50,7 @@ export default class Attachment extends React.Component {
 
           {fileInUse}
 
-          <a className="text-danger attachment-delete" onClick={this._onAttachmentDeleteClicked}><Icon name="trash-o" /></a>
+          {btnTrash}
       </li>
     );
   }
@@ -56,6 +60,7 @@ Attachment.propTypes = {
   attachment: PropTypes.object.isRequired,
   inUse: PropTypes.bool.isRequired,
   onAttachmentDeleteClicked: PropTypes.func.isRequired,
+  isUserLoggedIn: PropTypes.bool.isRequired,
 };
 
 Attachment.defaultProps = {

+ 1 - 0
resource/js/components/PageAttachment/PageAttachmentList.js

@@ -16,6 +16,7 @@ export default class PageAttachmentList extends React.Component {
           attachment={attachment}
           inUse={this.props.inUse[attachment._id] || false}
           onAttachmentDeleteClicked={this.props.onAttachmentDeleteClicked}
+          isUserLoggedIn={this.props.isUserLoggedIn}
          />
       );
     });