1+
2+ const commentInput = document . getElementById ( "comments" )
3+ const allowAllUsersStatusUpdate = document . getElementById ( "statusUpdateAllUsers" )
4+ const allowNoUsersStatusUpdate = document . getElementById ( "statusUpdateNoUsers" )
5+ const allowUsersWithStatusUpdate = document . getElementById ( "statusUpdateUsersWith" )
6+
7+ const itemPushNotificationAllUsers = document . getElementById ( "pushNotificationAllUsers" )
8+ const itemPushNotificationNoUsers = document . getElementById ( "pushNotificationNoUsers" )
9+ const itemPushNotificationUsersWith = document . getElementById ( "pushNotificationUsersWith" )
10+ const userTagsContainer = document . getElementById ( "userTagsContainer" )
11+ const itemPushNotificationTagsContainer = document . getElementById ( "itemPushNotificationTagsContainer" )
12+
13+
14+ const statusUpdatetagsInputContainer = new buildfire . components . control . tagsInput ( "#statusUpdatetagsInputContainer" , {
15+ languageSettings :{
16+ placeholder : "Select Tags" ,
17+ } ,
18+ settings :{
19+ sourceType : 'custom' ,
20+ source : ( options , callback ) => {
21+ buildfire . auth . showTagsSearchDialog ( null , ( err , result ) => {
22+ if ( err ) return console . log ( err ) ;
23+
24+ if ( result && result . length ) {
25+ let allTags = result . map ( tag => ( { value : tag . tagName } ) ) ;
26+ settings . statusUpdateTags = result ;
27+ save ( ) ;
28+ callback ( allTags ) ;
29+ }
30+ } ) ;
31+ } ,
32+ allowAutoComplete : true ,
33+ allowUserInput : true ,
34+ }
35+ } ) ;
36+ const pushNotificationtagsInputContainer = new buildfire . components . control . tagsInput ( "#pushNotificationtagsInputContainer" , {
37+ languageSettings :{
38+ placeholder : "Select Tags" ,
39+ } ,
40+ settings :{
41+ sourceType : 'custom' ,
42+ source : ( options , callback ) => {
43+ buildfire . auth . showTagsSearchDialog ( null , ( err , result ) => {
44+ if ( err ) return console . log ( err ) ;
45+
46+ if ( result && result . length ) {
47+ let allTags = result . map ( tag => ( { value : tag . tagName } ) ) ;
48+ settings . pushNotificationTags = result ;
49+ save ( ) ;
50+ callback ( allTags ) ;
51+ }
52+ } ) ;
53+ } ,
54+ allowAutoComplete : true ,
55+ allowUserInput : true ,
56+ }
57+ } ) ;
58+
59+ statusUpdatetagsInputContainer . onUpdate = ( data ) => {
60+ settings . statusUpdateTags = data . tags ;
61+
62+ save ( ) ;
63+ }
64+
65+ pushNotificationtagsInputContainer . onUpdate = ( data ) => {
66+ settings . pushNotificationTags = data . tags ;
67+ save ( ) ;
68+ }
69+
70+ var settings = { }
71+
72+
73+ const init = ( ) => {
74+ Settings . get ( ( err , result ) => {
75+ settings = result ;
76+ if ( result . enableComments ) {
77+ commentInput . checked = true ;
78+ }
79+ setCheckedInputAllowUsersStatus ( result . statusUpdateUsersSegment )
80+ setCheckedInputItemPushNotification ( result . pushNotificationUsersSegment )
81+
82+ if ( settings . statusUpdateTags && settings . statusUpdateTags . length ) {
83+ statusUpdatetagsInputContainer . set ( settings . statusUpdateTags ) ;
84+ }
85+ if ( settings . pushNotificationTags && settings . pushNotificationTags . length ) {
86+ pushNotificationtagsInputContainer . set ( settings . pushNotificationTags ) ;
87+ }
88+ showUsersTagsContainer ( ) ;
89+ showItemPushNotificationTagsContainer ( ) ;
90+ } )
91+ }
92+
93+ const showUsersTagsContainer = ( ) => {
94+ userTagsContainer . style . display = allowUsersWithStatusUpdate . checked ? "block" : "none"
95+ }
96+ const showItemPushNotificationTagsContainer = ( ) => {
97+ itemPushNotificationTagsContainer . style . display = itemPushNotificationUsersWith . checked ? "block" : "none"
98+ }
99+
100+ const setCheckedInputAllowUsersStatus = ( status ) => {
101+ switch ( status ) {
102+ case STATUS_UPDATE_SEGMENT . ALL_USERS :
103+ allowAllUsersStatusUpdate . checked = true ;
104+ break ;
105+ case STATUS_UPDATE_SEGMENT . NO_USERS :
106+ allowNoUsersStatusUpdate . checked = true ;
107+ break ;
108+ case STATUS_UPDATE_SEGMENT . TAGS :
109+ allowUsersWithStatusUpdate . checked = true ;
110+ break ;
111+ default :
112+ allowNoUsersStatusUpdate . checked = true ;
113+ break ;
114+ }
115+
116+ showUsersTagsContainer ( ) ;
117+ }
118+
119+ const setCheckedInputItemPushNotification = ( status ) => {
120+ switch ( status ) {
121+ case PUSH_NOTIFICATIONS_SEGMENT . ALL_USERS :
122+ itemPushNotificationAllUsers . checked = true ;
123+ break ;
124+ case PUSH_NOTIFICATIONS_SEGMENT . NO_USERS :
125+ itemPushNotificationNoUsers . checked = true ;
126+ break ;
127+ case PUSH_NOTIFICATIONS_SEGMENT . TAGS :
128+ itemPushNotificationUsersWith . checked = true ;
129+ break ;
130+ default :
131+ itemPushNotificationNoUsers . checked = true ;
132+ break ;
133+ }
134+
135+ showItemPushNotificationTagsContainer ( ) ;
136+ }
137+
138+ const updateCommentsProperty = ( ) => {
139+ settings . enableComments = commentInput . checked ;
140+ save ( ) ;
141+ }
142+
143+ const changeStatusUpdate = ( status ) => {
144+ setCheckedInputAllowUsersStatus ( status )
145+ settings . statusUpdateUsersSegment = status ;
146+ save ( ) ;
147+ }
148+
149+ const changeItemPushNotification = ( status ) => {
150+ setCheckedInputItemPushNotification ( status )
151+ settings . pushNotificationUsersSegment = status ;
152+ save ( ) ;
153+ }
154+
155+ const save = ( ) => {
156+ Settings . save ( settings , ( ) => { } )
157+
158+ buildfire . messaging . sendMessageToWidget ( {
159+ type : 'UpdateSettings' ,
160+ data : settings
161+ } ) ;
162+ }
163+
164+ init ( ) ;
0 commit comments