From 904793269b7e886a9a172acd26dbff2d8d97728c Mon Sep 17 00:00:00 2001 From: diminator Date: Mon, 21 Sep 2015 18:04:15 +0200 Subject: [PATCH] refactored detail page for wallets --- .../ascribe_detail/wallet_action_panel.js | 70 ++++++++++++ .../ascribe_detail/wallet_piece_container.js | 85 ++++++++++++++ .../cyland_accordion_list_item.js | 1 - .../ascribe_detail/cyland_piece_container.js | 77 +++---------- .../ascribe_detail/ikonotv_piece_container.js | 106 ++---------------- 5 files changed, 181 insertions(+), 158 deletions(-) create mode 100644 js/components/whitelabel/wallet/components/ascribe_detail/wallet_action_panel.js create mode 100644 js/components/whitelabel/wallet/components/ascribe_detail/wallet_piece_container.js diff --git a/js/components/whitelabel/wallet/components/ascribe_detail/wallet_action_panel.js b/js/components/whitelabel/wallet/components/ascribe_detail/wallet_action_panel.js new file mode 100644 index 00000000..2a4ba61a --- /dev/null +++ b/js/components/whitelabel/wallet/components/ascribe_detail/wallet_action_panel.js @@ -0,0 +1,70 @@ +'use strict'; + +import React from 'react'; + + +import ListRequestActions from '../../../../ascribe_forms/list_form_request_actions'; +import AclButtonList from '../../../../ascribe_buttons/acl_button_list'; +import DeleteButton from '../../../../ascribe_buttons/delete_button'; + +import AclProxy from '../../../../acl_proxy'; + + +import { mergeOptions } from '../../../../../utils/general_utils'; + + +let WalletActionPanel = React.createClass({ + propTypes: { + piece: React.PropTypes.object.isRequired, + currentUser: React.PropTypes.object.isRequired, + loadPiece: React.PropTypes.func.isRequired, + submitButtonType: React.PropTypes.func.isRequired + }, + + render(){ + if (this.props.piece && + this.props.piece.notifications && + this.props.piece.notifications.length > 0) { + return ( + ); + } + else { + + //We need to disable the normal acl_loan because we're inserting a custom acl_loan button + let availableAcls; + + if (this.props.piece && this.props.piece.acl && typeof this.props.piece.acl.acl_loan !== 'undefined') { + // make a copy to not have side effects + availableAcls = mergeOptions({}, this.props.piece.acl); + availableAcls.acl_loan = false; + } + let SubmitButtonType = this.props.submitButtonType; + + return ( + + + + + + + ); + } + } +}); + +export default WalletActionPanel; \ No newline at end of file diff --git a/js/components/whitelabel/wallet/components/ascribe_detail/wallet_piece_container.js b/js/components/whitelabel/wallet/components/ascribe_detail/wallet_piece_container.js new file mode 100644 index 00000000..adbd3e95 --- /dev/null +++ b/js/components/whitelabel/wallet/components/ascribe_detail/wallet_piece_container.js @@ -0,0 +1,85 @@ +'use strict'; + +import React from 'react'; + + +import Piece from '../../../../../components/ascribe_detail/piece'; + +import WalletActionPanel from './wallet_action_panel'; +import CollapsibleParagraph from '../../../../../components/ascribe_collapsible/collapsible_paragraph'; + +import HistoryIterator from '../../../../ascribe_detail/history_iterator'; +import Note from '../../../../ascribe_detail/note'; + +import DetailProperty from '../../../../ascribe_detail/detail_property'; + +import ApiUrls from '../../../../../constants/api_urls'; + +import { getLangText } from '../../../../../utils/lang_utils'; +import { mergeOptions } from '../../../../../utils/general_utils'; + + +let WalletPieceContainer = React.createClass({ + + propTypes: { + piece: React.PropTypes.object.isRequired, + currentUser: React.PropTypes.object.isRequired, + loadPiece: React.PropTypes.func.isRequired, + submitButtonType: React.PropTypes.func.isRequired + }, + + + render() { + return ( + +
+

{this.props.piece.title}

+ + +
+ + } + subheader={ +
+ + +
+
+ }> + + 0}> + + + + {return {'id': this.props.piece.id}; }} + label={getLangText('Personal note (private)')} + defaultValue={this.props.piece.private_note || null} + placeholder={getLangText('Enter your comments ...')} + editable={true} + successMessage={getLangText('Private note saved')} + url={ApiUrls.note_private_piece} + currentUser={this.props.currentUser}/> + + + {this.props.children} +
+ ); + + } +}); + +export default WalletPieceContainer; diff --git a/js/components/whitelabel/wallet/components/cyland/ascribe_accordion_list/cyland_accordion_list_item.js b/js/components/whitelabel/wallet/components/cyland/ascribe_accordion_list/cyland_accordion_list_item.js index 9535e832..72357f48 100644 --- a/js/components/whitelabel/wallet/components/cyland/ascribe_accordion_list/cyland_accordion_list_item.js +++ b/js/components/whitelabel/wallet/components/cyland/ascribe_accordion_list/cyland_accordion_list_item.js @@ -1,7 +1,6 @@ 'use strict'; import React from 'react'; -import Router from 'react-router'; import AccordionListItemPiece from '../../../../../ascribe_accordion_list/accordion_list_item_piece'; diff --git a/js/components/whitelabel/wallet/components/cyland/ascribe_detail/cyland_piece_container.js b/js/components/whitelabel/wallet/components/cyland/ascribe_detail/cyland_piece_container.js index 51e65386..81c7a0cf 100644 --- a/js/components/whitelabel/wallet/components/cyland/ascribe_detail/cyland_piece_container.js +++ b/js/components/whitelabel/wallet/components/cyland/ascribe_detail/cyland_piece_container.js @@ -7,29 +7,19 @@ import PieceStore from '../../../../../../stores/piece_store'; import UserStore from '../../../../../../stores/user_store'; -import Piece from '../../../../../../components/ascribe_detail/piece'; +import CylandSubmitButton from '../ascribe_buttons/cyland_submit_button'; + +import CollapsibleParagraph from '../../../../../../components/ascribe_collapsible/collapsible_paragraph'; + +import CylandAdditionalDataForm from '../ascribe_forms/cyland_additional_data_form'; + +import WalletPieceContainer from '../../ascribe_detail/wallet_piece_container'; import AppConstants from '../../../../../../constants/application_constants'; -import Form from '../../../../../../components/ascribe_forms/form'; -import Property from '../../../../../../components/ascribe_forms/property'; -import InputTextAreaToggable from '../../../../../../components/ascribe_forms/input_textarea_toggable'; -import CollapsibleParagraph from '../../../../../../components/ascribe_collapsible/collapsible_paragraph'; - -import HistoryIterator from '../../../../../ascribe_detail/history_iterator'; -import Note from '../../../../../ascribe_detail/note'; - -import CylandAdditionalDataForm from '../../cyland/ascribe_forms/cyland_additional_data_form'; - -import FurtherDetailsFileuploader from '../../../../../ascribe_detail/further_details_fileuploader'; -import DetailProperty from '../../../../../ascribe_detail/detail_property'; - -import ApiUrls from '../../../../../../constants/api_urls'; - import { getLangText } from '../../../../../../utils/lang_utils'; import { mergeOptions } from '../../../../../../utils/general_utils'; - let CylandPieceContainer = React.createClass({ getInitialState() { return mergeOptions( @@ -40,16 +30,18 @@ let CylandPieceContainer = React.createClass({ componentDidMount() { PieceStore.listen(this.onChange); - PieceActions.fetchOne(this.props.params.pieceId); UserStore.listen(this.onChange); - }, - componentWillUnmount() { // Every time we're leaving the piece detail page, // just reset the piece that is saved in the piece store // as it will otherwise display wrong/old data once the user loads // the piece detail a second time PieceActions.updatePiece({}); + + this.loadPiece(); + }, + + componentWillUnmount() { PieceStore.unlisten(this.onChange); UserStore.unlisten(this.onChange); }, @@ -65,45 +57,11 @@ let CylandPieceContainer = React.createClass({ render() { if(this.state.piece && this.state.piece.title) { return ( - -
-

{this.state.piece.title}

- - -
- - } - subheader={ -
- - -
-
- }> - - 0}> - - - - {return {'id': this.state.piece.id}; }} - label={getLangText('Personal note (private)')} - defaultValue={this.state.piece.private_note || null} - placeholder={getLangText('Enter your comments ...')} - editable={true} - successMessage={getLangText('Private note saved')} - url={ApiUrls.note_private_piece} - currentUser={this.state.currentUser}/> - + submitButtonType={CylandSubmitButton}> -
+ ); - } else { + } + else { return (
diff --git a/js/components/whitelabel/wallet/components/ikonotv/ascribe_detail/ikonotv_piece_container.js b/js/components/whitelabel/wallet/components/ikonotv/ascribe_detail/ikonotv_piece_container.js index bd0cd104..3c2a3e4b 100644 --- a/js/components/whitelabel/wallet/components/ikonotv/ascribe_detail/ikonotv_piece_container.js +++ b/js/components/whitelabel/wallet/components/ikonotv/ascribe_detail/ikonotv_piece_container.js @@ -7,13 +7,7 @@ import PieceStore from '../../../../../../stores/piece_store'; import UserStore from '../../../../../../stores/user_store'; -import Piece from '../../../../../../components/ascribe_detail/piece'; -import AppConstants from '../../../../../../constants/application_constants'; - -import ListRequestActions from '../../../../../ascribe_forms/list_form_request_actions'; -import AclButtonList from '../../../../../ascribe_buttons/acl_button_list'; -import DeleteButton from '../../../../../ascribe_buttons/delete_button'; import IkonotvSubmitButton from '../ascribe_buttons/ikonotv_submit_button'; import CollapsibleParagraph from '../../../../../../components/ascribe_collapsible/collapsible_paragraph'; @@ -21,19 +15,13 @@ import CollapsibleParagraph from '../../../../../../components/ascribe_collapsib import IkonotvArtistDetailsForm from '../ascribe_forms/ikonotv_artist_details_form'; import IkonotvArtworkDetailsForm from '../ascribe_forms/ikonotv_artwork_details_form'; -import HistoryIterator from '../../../../../ascribe_detail/history_iterator'; -import Note from '../../../../../ascribe_detail/note'; +import WalletPieceContainer from '../../ascribe_detail/wallet_piece_container'; -import DetailProperty from '../../../../../ascribe_detail/detail_property'; - -import AclProxy from '../../../../../acl_proxy'; - -import ApiUrls from '../../../../../../constants/api_urls'; +import AppConstants from '../../../../../../constants/application_constants'; import { getLangText } from '../../../../../../utils/lang_utils'; import { mergeOptions } from '../../../../../../utils/general_utils'; - let IkonotvPieceContainer = React.createClass({ getInitialState() { return mergeOptions( @@ -68,93 +56,14 @@ let IkonotvPieceContainer = React.createClass({ PieceActions.fetchOne(this.props.params.pieceId); }, - getActions(){ - if (this.state.piece && - this.state.piece.notifications && - this.state.piece.notifications.length > 0) { - return ( - ); - } - else { - - //We need to disable the normal acl_loan because we're inserting a custom acl_loan button - let availableAcls; - - if(this.state.piece && this.state.piece.acl && typeof this.state.piece.acl.acl_loan !== 'undefined') { - // make a copy to not have side effects - availableAcls = mergeOptions({}, this.state.piece.acl); - availableAcls.acl_loan = false; - } - - return ( - - - - - - - ); - } - }, - render() { if(this.state.piece && this.state.piece.title) { return ( - -
-

{this.state.piece.title}

- - -
-
- } - subheader={ -
- - -
-
- }> - {this.getActions()} - 0}> - - - - {return {'id': this.state.piece.id}; }} - label={getLangText('Personal note (private)')} - defaultValue={this.state.piece.private_note || null} - placeholder={getLangText('Enter your comments ...')} - editable={true} - successMessage={getLangText('Private note saved')} - url={ApiUrls.note_private_piece} - currentUser={this.state.currentUser}/> - - + submitButtonType={IkonotvSubmitButton}> - + ); - } else { + } + else { return (