2018-08-23 06:52:20 +00:00
< template >
< div
class = "marketplace-page"
: data - page - name = "page_name"
>
2018-08-23 17:12:41 +00:00
< notification -message
v - if = "last_sync_message"
: message = "last_sync_message"
@ remove - message = "clear_last_sync_message"
> < / n o t i f i c a t i o n - m e s s a g e >
2018-08-27 15:07:06 +00:00
< div class = "flex justify-between align-flex-end margin-bottom" >
2018-08-23 15:55:53 +00:00
< h5 > { { page _title } } < / h5 >
< button class = "btn btn-primary btn-sm publish-items"
2018-08-24 11:08:34 +00:00
: disabled = "no_selected_items"
@ click = "publish_selected_items"
>
2018-08-23 15:55:53 +00:00
< span > { { publish _button _text } } < / span >
< / button >
< / div >
< item -cards -container
2018-08-25 16:24:49 +00:00
: container _name = "page_title"
2018-08-23 15:55:53 +00:00
: items = "selected_items"
2018-08-24 11:08:34 +00:00
: item _id _fieldname = "item_id_fieldname"
2018-08-25 07:48:30 +00:00
: is _local = "true"
2018-08-24 11:08:34 +00:00
: editable = "true"
@ remove - item = "remove_item_from_selection"
2018-08-23 15:55:53 +00:00
: empty _state _message = "empty_state_message"
: empty _state _bordered = "true"
: empty _state _height = "80"
>
< / i t e m - c a r d s - c o n t a i n e r >
< p class = "text-muted" > { { valid _products _instruction } } < / p >
2018-08-23 08:22:41 +00:00
< search -input
2018-08-23 15:55:53 +00:00
: placeholder = "search_placeholder"
2018-08-23 08:22:41 +00:00
: on _search = "get_valid_items"
v - model = "search_value"
>
< / s e a r c h - i n p u t >
2018-08-23 15:55:53 +00:00
2018-08-23 06:52:20 +00:00
< item -cards -container
: items = "valid_items"
2018-08-24 11:08:34 +00:00
: item _id _fieldname = "item_id_fieldname"
2018-08-25 07:48:30 +00:00
: is _local = "true"
2018-08-24 11:08:34 +00:00
: on _click = "show_publishing_dialog_for_item"
2018-08-23 06:52:20 +00:00
>
< / i t e m - c a r d s - c o n t a i n e r >
< / div >
< / template >
< script >
2018-08-25 08:39:01 +00:00
import NotificationMessage from '../components/NotificationMessage.vue' ;
import { ItemPublishDialog } from '../components/item_publish_dialog' ;
2018-08-23 06:52:20 +00:00
export default {
name : 'publish-page' ,
2018-08-27 04:42:45 +00:00
components : {
NotificationMessage
} ,
2018-08-23 06:52:20 +00:00
data ( ) {
return {
page _name : frappe . get _route ( ) [ 1 ] ,
valid _items : [ ] ,
2018-08-23 15:55:53 +00:00
selected _items : [ ] ,
2018-08-24 11:08:34 +00:00
items _data _to _publish : { } ,
2018-08-23 15:55:53 +00:00
search _value : '' ,
2018-08-24 11:08:34 +00:00
item _id _fieldname : 'item_code' ,
2018-08-23 15:55:53 +00:00
// Constants
2018-08-30 06:31:04 +00:00
// TODO: multiline translations don't work
2018-08-23 15:55:53 +00:00
page _title : _ _ ( 'Publish Products' ) ,
search _placeholder : _ _ ( 'Search Items ...' ) ,
2018-08-30 06:31:04 +00:00
empty _state _message : _ _ ( ` No Items selected yet. Browse and click on products below to publish. ` ) ,
valid _products _instruction : _ _ ( ` Only products with an image and description can be published. Please update them if an item in your inventory does not appear. ` ) ,
2018-08-23 17:12:41 +00:00
last _sync _message : ( hub . settings . last _sync _datetime )
? _ _ ( ` Last sync was
< a href = "#marketplace/profile" >
$ { comment _when ( hub . settings . last _sync _datetime ) } < / a > .
< a href = "#marketplace/my-products" >
See your Published Products < / a > . ` )
: ''
2018-08-23 06:52:20 +00:00
} ;
} ,
2018-08-23 15:55:53 +00:00
computed : {
no _selected _items ( ) {
return this . selected _items . length === 0 ;
} ,
publish _button _text ( ) {
const number = this . selected _items . length ;
let text = 'Publish' ;
if ( number === 1 ) {
text = 'Publish 1 Product' ;
}
if ( number > 1 ) {
text = ` Publish ${ number } Products ` ;
}
return _ _ ( text ) ;
2018-08-24 11:08:34 +00:00
} ,
items _dict ( ) {
let items _dict = { } ;
this . valid _items . map ( item => {
items _dict [ item [ this . item _id _fieldname ] ] = item
} )
return items _dict ;
} ,
2018-08-23 15:55:53 +00:00
} ,
2018-08-23 06:52:20 +00:00
created ( ) {
this . get _valid _items ( ) ;
2018-08-24 11:08:34 +00:00
this . make _publishing _dialog ( ) ;
2018-08-23 06:52:20 +00:00
} ,
methods : {
get _valid _items ( ) {
frappe . call (
'erpnext.hub_node.api.get_valid_items' ,
{
search _value : this . search _value
}
)
2018-08-23 08:22:41 +00:00
. then ( ( r ) => {
this . valid _items = r . message ;
2018-08-23 06:52:20 +00:00
} )
2018-08-23 17:12:41 +00:00
} ,
2018-08-24 11:08:34 +00:00
publish _selected _items ( ) {
frappe . call (
'erpnext.hub_node.api.publish_selected_items' ,
{
items _to _publish : this . selected _items
}
)
. then ( ( r ) => {
this . selected _items = [ ] ;
return frappe . db . get _doc ( 'Hub Settings' ) ;
} )
. then ( doc => {
hub . settings = doc ;
this . add _last _sync _message ( ) ;
} ) ;
} ,
add _last _sync _message ( ) {
this . last _sync _message = _ _ ( ` Last sync was
< a href = "#marketplace/profile" >
$ { comment _when ( hub . settings . last _sync _datetime ) } < / a > .
< a href = "#marketplace/my-products" >
See your Published Products < / a > . ` );
} ,
2018-08-23 17:12:41 +00:00
clear _last _sync _message ( ) {
this . last _sync _message = '' ;
2018-08-24 11:08:34 +00:00
} ,
remove _item _from _selection ( item _code ) {
this . selected _items = this . selected _items
. filter ( item => item . item _code !== item _code ) ;
} ,
make _publishing _dialog ( ) {
this . item _publish _dialog = ItemPublishDialog (
{
fn : ( values ) => {
this . add _item _to _publish ( values ) ;
this . item _publish _dialog . hide ( ) ;
}
} ,
{
fn : ( ) => {
const values = this . item _publish _dialog . get _values ( true ) ;
this . update _items _data _to _publish ( values ) ;
}
}
) ;
} ,
add _item _to _publish ( values ) {
this . update _items _data _to _publish ( values ) ;
const item _code = values . item _code ;
let item _doc = this . items _dict [ item _code ] ;
const item _to _publish = Object . assign ( { } , item _doc , values ) ;
this . selected _items . push ( item _to _publish ) ;
} ,
update _items _data _to _publish ( values ) {
this . items _data _to _publish [ values . item _code ] = values ;
} ,
show _publishing _dialog _for _item ( item _code ) {
let item _data = this . items _data _to _publish [ item _code ] ;
if ( ! item _data ) { item _data = { item _code } ; } ;
this . item _publish _dialog . clear ( ) ;
const item _doc = this . items _dict [ item _code ] ;
if ( item _doc ) {
this . item _publish _dialog . fields _dict . image _list . set _data (
item _doc . attachments . map ( attachment => attachment . file _url )
) ;
}
this . item _publish _dialog . set _values ( item _data ) ;
this . item _publish _dialog . show ( ) ;
2018-08-23 06:52:20 +00:00
}
}
}
< / script >
< style scoped > < / style >