add-source.js
3 weeks ago
builder.js
3 weeks ago
confirm-dialog.js
3 weeks ago
date_i18n.js
3 weeks ago
install-plugin-popup.js
3 weeks ago
jquery.tooltipster.min.js
3 weeks ago
oembed.js
3 weeks ago
owl.autoheight.js
3 weeks ago
ressources.js
3 weeks ago
tooltip-wizard.js
3 weeks ago
vue-color.min.js
3 weeks ago
add-source.js
337 lines
| 1 | var cffStorage = window.localStorage; |
| 2 | /** |
| 3 | * Add Source Popup |
| 4 | * |
| 5 | * @since 4.0 |
| 6 | */ |
| 7 | Vue.component('sb-add-source-component', { |
| 8 | name: 'sb-add-source-component', |
| 9 | template: '#sb-add-source-component', |
| 10 | props: [ |
| 11 | 'genericText', |
| 12 | 'links', |
| 13 | 'svgIcons', |
| 14 | 'viewsActive', |
| 15 | 'selectSourceScreen', |
| 16 | 'selectedFeed', |
| 17 | 'parent' |
| 18 | ], |
| 19 | data: function() { |
| 20 | return{ |
| 21 | sourcesList : cff_source.sources, |
| 22 | //Add New Source |
| 23 | newSourceData : cff_source.newSourceData ? cff_source.newSourceData : null, |
| 24 | sourceConnectionURLs : cff_source.sourceConnectionURLs, |
| 25 | returnedApiSourcesList : [], |
| 26 | addNewSource : { |
| 27 | typeSelected : 'page', |
| 28 | manualSourceID : null, |
| 29 | manualSourceToken : null |
| 30 | }, |
| 31 | selectedSourcesToConnect : [], |
| 32 | loadingAjax : false |
| 33 | } |
| 34 | }, |
| 35 | computed : { |
| 36 | |
| 37 | }, |
| 38 | mounted : function(){ |
| 39 | var self = this; |
| 40 | if(self.newSourceData != null){ |
| 41 | self.initAddSourceData(); |
| 42 | } |
| 43 | self.processFBConnectSuccess(); |
| 44 | }, |
| 45 | methods : { |
| 46 | /** |
| 47 | * Return Page/Group Avatar |
| 48 | * |
| 49 | * @since 4.0 |
| 50 | * |
| 51 | * @return string |
| 52 | */ |
| 53 | returnGroupPageAvatar : function(source){ |
| 54 | var info = this.$parent.jsonParse(source.info); |
| 55 | return (source.account_type == 'page') ? 'https://graph.facebook.com/'+source.account_id+'/picture' : (info.picture.data.url ? info.picture.data.url : ''); |
| 56 | }, |
| 57 | |
| 58 | |
| 59 | /** |
| 60 | * Add Feed Source Manually |
| 61 | * |
| 62 | * @since 4.0 |
| 63 | */ |
| 64 | addSourceManually: function(isEventSource = false){ |
| 65 | var self = this, |
| 66 | manualSourceData = { |
| 67 | 'action' : 'cff_source_builder_update', |
| 68 | 'type' : self.addNewSource.typeSelected, |
| 69 | 'id' : self.addNewSource.manualSourceID, |
| 70 | 'access_token' : self.addNewSource.manualSourceToken, |
| 71 | }; |
| 72 | if(isEventSource){ |
| 73 | manualSourceData.privilege = 'events'; |
| 74 | } |
| 75 | var alerts = document.querySelectorAll(".sb-alerts-wrap"); |
| 76 | if (alerts.length) { |
| 77 | alerts[0].parentNode.removeChild(alerts[0]); |
| 78 | } |
| 79 | |
| 80 | if(self.$parent.checkNotEmpty(self.addNewSource.manualSourceID) && self.$parent.checkNotEmpty(self.addNewSource.manualSourceToken) ){ |
| 81 | self.loadingAjax = true; |
| 82 | self.$parent.ajaxPost(manualSourceData, function(_ref){ |
| 83 | var data = _ref.data; |
| 84 | if (typeof data.success !== 'undefined' && data.success === false) { |
| 85 | //cff-fb-source-inputs cff-fb-fs |
| 86 | var inputs = document.querySelectorAll(".cff-fb-source-inputs")[0]; |
| 87 | |
| 88 | var div = document.createElement('div'); |
| 89 | div.innerHTML = data.message; |
| 90 | while (div.children.length > 0) { |
| 91 | inputs.appendChild(div.children[0]); |
| 92 | } |
| 93 | |
| 94 | } else { |
| 95 | self.addNewSource = {typeSelected : 'page', manualSourceID : null,manualSourceToken : null}; |
| 96 | self.sourcesList = data; |
| 97 | self.$parent.sourcesList = data; |
| 98 | self.$parent.viewsActive.sourcePopup = false; |
| 99 | if(self.$parent.customizerFeedData){ |
| 100 | self.$parent.activateView('sourcePopup', 'customizer'); |
| 101 | } |
| 102 | } |
| 103 | self.loadingAjax = false; |
| 104 | |
| 105 | }); |
| 106 | }else{ |
| 107 | alert("Token or ID Empty") |
| 108 | } |
| 109 | }, |
| 110 | |
| 111 | /** |
| 112 | * Make sure something entered for manual connections |
| 113 | * |
| 114 | * @since 4.0 |
| 115 | */ |
| 116 | checkManualEmpty : function() { |
| 117 | var self = this; |
| 118 | return self.$parent.checkNotEmpty(self.addNewSource.manualSourceID) && self.$parent.checkNotEmpty(self.addNewSource.manualSourceToken); |
| 119 | }, |
| 120 | |
| 121 | /** |
| 122 | * Init Add Source Action |
| 123 | * Triggered when the connect button is returned |
| 124 | * |
| 125 | * @since 4.0 |
| 126 | */ |
| 127 | initAddSourceData : function(){ |
| 128 | var self = this; |
| 129 | self.$parent.viewsActive.sourcePopup = true; |
| 130 | self.$parent.viewsActive.sourcePopupScreen = 'step_2'; |
| 131 | if(self.newSourceData && !self.newSourceData.error){ |
| 132 | if(self.newSourceData.admin || self.newSourceData.member){ |
| 133 | self.addNewSource.typeSelected = 'group'; |
| 134 | self.newSourceData.admin.forEach(function(singleSource){ |
| 135 | singleSource.admin = true; |
| 136 | self.returnedApiSourcesList.push(self.createSourceObject('group',singleSource)); |
| 137 | }); |
| 138 | self.newSourceData.member.forEach(function(singleSource){ |
| 139 | //if(!self.checkObjectArrayElement(self.returnedApiSourcesList, self.newSourceData.admin, 'id')){ |
| 140 | singleSource.admin = false; |
| 141 | self.returnedApiSourcesList.push(self.createSourceObject('group',singleSource)); |
| 142 | //} |
| 143 | }); |
| 144 | }else{ |
| 145 | self.newSourceData.pages.forEach(function(singleSource){ |
| 146 | self.returnedApiSourcesList.push(self.createSourceObject('page',singleSource)); |
| 147 | }); |
| 148 | } |
| 149 | } |
| 150 | }, |
| 151 | |
| 152 | /** |
| 153 | * Create Single Source Object |
| 154 | * |
| 155 | * @since 4.0 |
| 156 | * |
| 157 | * @return Object |
| 158 | */ |
| 159 | createSourceObject : function(type,object){ |
| 160 | return { |
| 161 | account_id : object.id, |
| 162 | access_token : object.access_token, |
| 163 | account_type : type, |
| 164 | info : (type == 'group' ? JSON.stringify(object) : '{}'), |
| 165 | admin : (type == 'group' ? object.admin : ''), |
| 166 | username : object.name |
| 167 | } |
| 168 | }, |
| 169 | |
| 170 | /** |
| 171 | * Select Page/Group to Connect |
| 172 | * |
| 173 | * @since 4.0 |
| 174 | */ |
| 175 | selectSourcesToConnect : function(source){ |
| 176 | var self = this; |
| 177 | |
| 178 | if (typeof window.cffSelected === 'undefined') { |
| 179 | window.cffSelected = []; |
| 180 | } |
| 181 | if(self.selectedSourcesToConnect.includes(source.account_id)){ |
| 182 | self.selectedSourcesToConnect.splice(self.selectedSourcesToConnect.indexOf(source.account_id), 1); |
| 183 | window.cffSelected.splice(self.selectedSourcesToConnect.indexOf(source.admin), 1); |
| 184 | }else{ |
| 185 | self.selectedSourcesToConnect.push(source.account_id); |
| 186 | window.cffSelected.push(source.admin); |
| 187 | } |
| 188 | }, |
| 189 | |
| 190 | /** |
| 191 | * Select Page/Group to Connect |
| 192 | * |
| 193 | * @since 4.0 |
| 194 | */ |
| 195 | addSourcesOnConnect : function(){ |
| 196 | var self = this; |
| 197 | if(self.selectedSourcesToConnect.length > 0){ |
| 198 | var sourcesListToAdd = []; |
| 199 | self.selectedSourcesToConnect.forEach(function(accountID, index){ |
| 200 | self.returnedApiSourcesList.forEach(function(source){ |
| 201 | if(source.account_id === accountID) |
| 202 | sourcesListToAdd.push(source); |
| 203 | }); |
| 204 | }); |
| 205 | var connectSourceData = { |
| 206 | 'action' : 'cff_source_builder_update_multiple', |
| 207 | 'type' : self.addNewSource.typeSelected, |
| 208 | 'sourcesList' : sourcesListToAdd |
| 209 | }; |
| 210 | self.$parent.ajaxPost(connectSourceData, function(_ref){ |
| 211 | var data = _ref.data, |
| 212 | sourcesList = data.sourcesList; |
| 213 | if( data?.hasError ){ |
| 214 | self.$parent.processNotification("addSourceError"); |
| 215 | } |
| 216 | self.sourcesList = sourcesList; |
| 217 | self.$parent.sourcesList = sourcesList; |
| 218 | self.$parent.viewsActive.sourcePopup = false; |
| 219 | if(self.$parent.customizerFeedData){ |
| 220 | self.$parent.activateView('sourcePopup', 'customizer'); |
| 221 | } |
| 222 | }); |
| 223 | } |
| 224 | }, |
| 225 | |
| 226 | /** |
| 227 | * Process Connect FB Button |
| 228 | * |
| 229 | * @since 4.0 |
| 230 | */ |
| 231 | processFBConnect : function(){ |
| 232 | var self = this, |
| 233 | accountType = self.addNewSource.typeSelected, |
| 234 | params = accountType === 'page' ? self.sourceConnectionURLs.page : self.sourceConnectionURLs.group, |
| 235 | ifConnectURL = params.connect, |
| 236 | screenType = (self.$parent.customizerFeedData != undefined) ? 'customizer' : 'creationProcess', |
| 237 | appendURL = ( screenType == 'customizer' ) ? self.sourceConnectionURLs.stateURL + ',feed_id='+ self.$parent.customizerFeedData.feed_info.id : self.sourceConnectionURLs.stateURL; |
| 238 | if(screenType != 'customizer'){ |
| 239 | self.createLocalStorage(screenType); |
| 240 | } |
| 241 | |
| 242 | if( self.$parent.isSetupPage === 'true'){ |
| 243 | appendURL = appendURL+ ',is_setup_page=yes'; |
| 244 | } |
| 245 | |
| 246 | const urlParams = { |
| 247 | 'wordpress_user' : params.wordpress_user, |
| 248 | 'v' : params.v, |
| 249 | 'vn' : params.vn, |
| 250 | 'cff_con' : params.cff_con, |
| 251 | 'has_group' : params.has_group, |
| 252 | 'state' : "{'{url=" + appendURL + "}'}" |
| 253 | }; |
| 254 | |
| 255 | if(params.sw_feed) { |
| 256 | urlParams['sw-feed'] = 'true'; |
| 257 | } |
| 258 | |
| 259 | var form = document.createElement('form'); |
| 260 | form.method = 'POST'; |
| 261 | form.action = ifConnectURL; |
| 262 | form.action = ifConnectURL + (params.has_group === true ? '?has_group=true' : ''); |
| 263 | |
| 264 | for (const param in urlParams) { |
| 265 | if (urlParams.hasOwnProperty(param)) { |
| 266 | var input = document.createElement('input'); |
| 267 | input.type = 'hidden'; |
| 268 | input.name = param; |
| 269 | input.value = urlParams[param]; |
| 270 | form.appendChild(input); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | document.body.appendChild(form); |
| 275 | form.submit(); |
| 276 | }, |
| 277 | |
| 278 | /** |
| 279 | * Browser Local Storage for FB Connect |
| 280 | * |
| 281 | * @since 4.0 |
| 282 | */ |
| 283 | createLocalStorage : function(screenType){ |
| 284 | var self = this; |
| 285 | switch (screenType) { |
| 286 | case 'creationProcess': |
| 287 | cffStorage.setItem('selectedFeed', self.$parent.selectedFeed); |
| 288 | if( self.$parent.isSetupPage === 'true'){ |
| 289 | cffStorage.setItem('isSetupPage', 'true'); |
| 290 | } |
| 291 | break; |
| 292 | case 'customizer': |
| 293 | cffStorage.setItem( 'feed_id', self.$parent.customizerFeedData.feed_info.id ); |
| 294 | break; |
| 295 | } |
| 296 | cffStorage.setItem( 'FBConnect', 'true' ); |
| 297 | cffStorage.setItem( 'screenType', screenType ); |
| 298 | }, |
| 299 | |
| 300 | |
| 301 | /** |
| 302 | * Process FB Connect Success |
| 303 | * |
| 304 | * @since 4.0 |
| 305 | */ |
| 306 | processFBConnectSuccess : function(){ |
| 307 | var self = this; |
| 308 | if( cffStorage.FBConnect === 'true' && cffStorage.screenType ){ |
| 309 | if( cffStorage?.isSetupPage === 'true' && cffStorage?.isSetupPage ){ |
| 310 | cffStorage.removeItem("isSetupPage"); |
| 311 | cffStorage.setItem('setCurrentStep',1); |
| 312 | window.location = window.location.href.replace('cff-feed-builder', 'cff-setup') ; |
| 313 | } |
| 314 | |
| 315 | if( cffStorage.screenType == 'creationProcess' && cffStorage.selectedFeed ){ |
| 316 | self.$parent.selectedFeed = cffStorage.selectedFeed; |
| 317 | self.$parent.viewsActive.pageScreen = 'selectFeed'; |
| 318 | self.$parent.viewsActive.selectedFeedSection = 'selectSource'; |
| 319 | } |
| 320 | if( cffStorage.screenType == 'customizer' && cffStorage.feed_id){ |
| 321 | var urlParams = new URLSearchParams(window.location.search); |
| 322 | urlParams.set('feed_id', cffStorage.feed_id); |
| 323 | window.location.search = urlParams; |
| 324 | } |
| 325 | } |
| 326 | cffStorage.removeItem("FBConnect"); |
| 327 | cffStorage.removeItem("screenType"); |
| 328 | cffStorage.removeItem("selectedFeed"); |
| 329 | cffStorage.removeItem("feed_id"); |
| 330 | }, |
| 331 | |
| 332 | groupNext : function() { |
| 333 | console.log('next'); |
| 334 | } |
| 335 | } |
| 336 | }); |
| 337 |