diff --git a/data/web/promote.telegram.org/js/promote.js b/data/web/promote.telegram.org/js/promote.js index 84bc474f83..4fc4c9028d 100644 --- a/data/web/promote.telegram.org/js/promote.js +++ b/data/web/promote.telegram.org/js/promote.js @@ -401,6 +401,7 @@ var Ads = { } }, onBlur: function(value) { + options.onBlur && options.onBlur(field, options.getDataOpts); options.onEnter && options.onEnter(field, value); }, onEnter: function(value) { @@ -496,6 +497,7 @@ var NewAd = { field: selectData.field, c_field: selectData.c_field, }, + onBlur: NewAd.onLocationSelectBlur, onUpdate: NewAd.onSelectUpdate, onChange: NewAd.onLocationSelectChange }); @@ -527,10 +529,14 @@ var NewAd = { state.targetTypeField.fieldEl().on('change.curPage', NewAd.onTargetTypeChange); state.pictureCheckbox = state.$form.field('picture'); state.pictureCheckbox.on('change.curPage', NewAd.onPictureChange); + state.intersectTopicsCheckbox = state.$form.field('intersect_topics'); + state.intersectTopicsCheckbox.on('change.curPage', NewAd.onIntersectTopicsChange); state.excludePoliticCheckbox = state.$form.field('exclude_politic'); state.excludePoliticCheckbox.on('change.curPage', NewAd.onExcludePoliticChange); state.onlyPoliticCheckbox = state.$form.field('only_politic'); state.onlyPoliticCheckbox.on('change.curPage', NewAd.onOnlyPoliticChange); + state.deviceField = state.$form.field('device'); + state.deviceField.on('ddchange.curPage', NewAd.onDeviceChange); state.confirmedCheckbox = state.$form.field('confirmed'); state.confirmedCheckbox.on('change.curPage', NewAd.onConfirmedChange); NewAd.updateAdPreview(state.$form, state.previewData); @@ -567,8 +573,10 @@ var NewAd = { state.targetTypeField.fieldEl().off('.curPage'); state.confirmedCheckbox.off('.curPage'); state.pictureCheckbox.off('.curPage'); + state.intersectTopicsCheckbox.off('.curPage'); state.excludePoliticCheckbox.off('.curPage'); state.onlyPoliticCheckbox.off('.curPage'); + state.deviceField.off('.curPage'); for (var i = 0; i < state.selectList.length; i++) { var selectData = state.selectList[i]; if (selectData.location_search) { @@ -597,6 +605,10 @@ var NewAd = { var $form = $(this.form); NewAd.adPostCheck($form); }, + onIntersectTopicsChange: function() { + NewAd.updateAdTargetOverview(); + NewAd.saveDraftAuto(true); + }, onExcludePoliticChange: function() { if ($(this).prop('checked')) { Aj.state.onlyPoliticCheckbox.prop('checked', false); @@ -660,6 +672,13 @@ var NewAd = { Ads.hideFieldError(buttonField); NewAd.adPostCheck($form); }, + onDeviceChange: function() { + var $form = $(this).parents('form'); + var devideField = $form.field('devide'); + Ads.hideFieldError(devideField); + NewAd.updateAdTargetOverview(); + NewAd.saveDraftAuto(true); + }, adPostCheck: function($form, try_index) { var textField = $form.field('text'); var promoteUrlField = $form.field('promote_url'); @@ -667,6 +686,7 @@ var NewAd = { var websiteNameField = $form.field('website_name'); var websitePhotoField = $form.field('website_photo'); var cpmField = $form.field('cpm'); + var deviceField = $form.field('device'); var text = textField.value(); var promote_url = promoteUrlField.value(); var button = buttonField.data('value'); @@ -674,6 +694,7 @@ var NewAd = { var website_photo = websitePhotoField.value(); var $formGroup = promoteUrlField.fieldEl().parents('.form-group'); var $cpmFormGroup = cpmField.fieldEl().parents('.form-group'); + var device = deviceField.data('value'); if (!text && !promote_url) { return false; } @@ -683,7 +704,8 @@ var NewAd = { promote_url: promote_url, button: button, website_name: website_name, - website_photo: website_photo + website_photo: website_photo, + device: device }; if (Aj.state.adId) { params.ad_id = Aj.state.adId; @@ -912,6 +934,17 @@ var NewAd = { }); return false; }, + onLocationSelectBlur: function(field, opts) { + var $form = Aj.state.$form; + var $cFieldEl = $form.field(opts.c_field); + var c_value = $cFieldEl.data('value'); + if (c_value.join) { + if (c_value.length > 1) { + Ads.hideFieldError($cFieldEl); + return false; + } + } + }, onLocationSelectChange: function(field, value, valueFull) { var $fieldEl = Aj.state.$form.field(field); Ads.hideFieldError($fieldEl); @@ -919,11 +952,12 @@ var NewAd = { onSelectUpdate: function(field, value, valueFull) { var $fieldEl = Aj.state.$form.field(field); if (field == 'user_topics') { - var has_user_topics = $fieldEl.data('value').length > 0; - if (has_user_topics) { - Aj.state.onlyPoliticCheckbox.prop('checked', false); + var user_topics_cnt = $fieldEl.data('value').length; + if (user_topics_cnt > 1) { + $('.js-intersect-topics-wrap', Aj.state.$form).slideShow(); + } else { + $('.js-intersect-topics-wrap', Aj.state.$form).slideHide(); } - Aj.state.onlyPoliticCheckbox.prop('disabled', has_user_topics); } var selOpts = $fieldEl.data('selOpts'); var paired_field = selOpts.pairedField; @@ -1192,6 +1226,18 @@ var NewAd = { updateAdTargetOverview: function() { var len = {}, lang_params = {}, need_outside_cb = false; var target_type = Aj.state.$form.field('target_type').value(); + var joinTargets = function(list, or, repeat) { + var lk = or ? 'WEB_AD_TARGET_OR' : 'WEB_AD_TARGET_AND'; + if (repeat && list.length > 2) { + var last_item = list.pop(); + return l(lk, {item1: joinTargets(list, or, repeat), item2: last_item}); + } + if (list.length > 1) { + var last_item = list.pop(); + list[list.length - 1] = l(lk, {item1: list[list.length - 1], item2: last_item}); + } + return list.join(', '); + }; for (var i = 0; i < Aj.state.selectList.length; i++) { var selectData = Aj.state.selectList[i]; var field = selectData.field; @@ -1208,16 +1254,16 @@ var NewAd = { need_outside_cb = true; } } - if (list.length > 1) { - var last_item = list.pop(); - list[list.length - 1] = l('WEB_AD_TARGET_AND', {item1: list[list.length - 1], item2: last_item}); - } - lang_params[field] = list.join(', '); + var list_or = (field == 'langs' || field == 'topics' || field == 'countries' || field == 'locations' || field == 'user_langs' || field == 'user_topics' && !Aj.state.intersectTopicsCheckbox.prop('checked') || field == 'user_channels' || field == 'audiences') + lang_params[field] = joinTargets(list, list_or); } else { lang_params[field] = ''; } Ads.hideFieldError($field); } + len.device = Aj.state.$form.field('device').data('value'); + lang_params.device = '' + Aj.state.$form.field('device').html() + ''; + var overview = ''; if (target_type == 'channels') { if ((len.langs || len.topics) && len.channels) { @@ -1270,27 +1316,33 @@ var NewAd = { if (len.user_topics > 0) { user_targets.push(l('WEB_AD_TARGET_USER_TOPICS', lang_params)); } + if (len.user_channels > 0) { + user_targets.push(l('WEB_AD_TARGET_USER_CHANNELS', lang_params)); + } if (len.audiences > 0) { user_targets.push(l('WEB_AD_TARGET_AUDIENCES', lang_params)); } - if (user_targets.length > 1) { - var last_user_target = user_targets.pop(); - user_targets[user_targets.length - 1] = l('WEB_AD_TARGET_AND', {item1: user_targets[user_targets.length - 1], item2: last_user_target}); + if (len.device) { + user_targets.push(l('WEB_AD_TARGET_DEVICE', lang_params)); } + user_targets = joinTargets(user_targets, false, true); if (Aj.state.onlyPoliticCheckbox.prop('checked')) { - overview += '