Skip to content

Commit

Permalink
Fix contropanel
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Aug 1, 2017
1 parent be7b016 commit 4634ba5
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 29 deletions.
47 changes: 47 additions & 0 deletions sc/social/like/browser/scripts/social_like.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,53 @@
(function(a){(jQuery.browser=jQuery.browser||{}).mobile=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);

$(function(){
// Update control panel options
if ($('.template-sociallike-settings').length > 0) {
var updateControlPanel = function() {
var enabledPlugins = $.map(
$('#form-widgets-plugins_enabled-to option'),
function(option) {
return option.value;
}
);
if (enabledPlugins.indexOf('Facebook') >= 0) {
$('#fieldsetlegend-facebook').parent().show();
} else {
$('#fieldsetlegend-facebook').parent().hide();
}
if (enabledPlugins.indexOf('Twitter') >= 0) {
$('#fieldsetlegend-twitter').parent().show();
} else {
$('#fieldsetlegend-twitter').parent().hide();
}
if ($('#form-widgets-do_not_track-0').is(':checked')) {
$('#formfield-form-widgets-facebook_app_id').show();
} else {
$('#formfield-form-widgets-facebook_app_id').hide();
}
var enabledButtons = $.map(
$('#form-widgets-fbbuttons-to option'),
function(option) {
return option.value;
}
);
if (enabledButtons.indexOf('Share') >= 0) {
$('[id^=formfield-form-widgets-fbshare]').show();
} else {
$('[id^=formfield-form-widgets-fbshare]').hide();
}
if (enabledButtons.indexOf('Like') >= 0) {
$('[id^=formfield-form-widgets-fblike]').show();
} else {
$('[id^=formfield-form-widgets-fblike]').hide();
}
};
$('#form-widgets-plugins_enabled button').on('click', updateControlPanel);
$('#form-widgets-do_not_track-0').on('change', updateControlPanel);
$('#form-widgets-fbbuttons button').on('click', updateControlPanel);
updateControlPanel();
}

$("div#viewlet-social-like").each(function(){
$(this).fadeIn(3000);
$(this).removeAttr("style");
Expand Down
206 changes: 184 additions & 22 deletions sc/social/like/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
from sc.social.like.config import DEFAULT_ENABLED_CONTENT_TYPES
from sc.social.like.config import DEFAULT_PLUGINS_ENABLED
from sc.social.like.utils import validate_canonical_domain
from sc.social.like.utils import validate_like_ref
from sc.social.like.vocabularies import FacebookButtonsVocabulary
from sc.social.like.vocabularies import FacebookVerbsVocabulary
from sc.social.like.vocabularies import FacebookLikeActionVocabulary
from sc.social.like.vocabularies import FacebookLikeColorschemeVocabulary
from sc.social.like.vocabularies import FacebookLikeLayoutVocabulary
from sc.social.like.vocabularies import FacebookShareLayoutVocabulary
from sc.social.like.vocabularies import FacebookSizeVocabulary
from sc.social.like.vocabularies import TypeButtonVocabulary
from zope import schema
from zope.interface import Interface
from zope.interface import Invalid
from zope.interface import invariant

# BBB: for compatibility with installations made before 2.5.0
import sys
Expand Down Expand Up @@ -113,11 +120,21 @@ class ISocialLikeSettings(model.Schema):
label=u'Facebook',
fields=[
'canonical_domain',
'fbaction',
'facebook_username',
'facebook_app_id',
'fbbuttons',
'fbshowlikes',
'fbshare_layout',
'fbshare_mobile_iframe',
'fbshare_size',
'fblike_action',
'fblike_colorscheme',
'fblike_kid_directed_site',
'fblike_layout',
'fblike_ref',
'fblike_share',
'fblike_show_faces',
'fblike_size',
'fblike_width',
],
)

Expand All @@ -134,19 +151,7 @@ class ISocialLikeSettings(model.Schema):
constraint=validate_canonical_domain,
)

fbaction = schema.Choice(
title=_(u'Verb to display'),
description=_(
u'help_verb_display',
default=u'The verb to display in the Facebook button. '
u'Currently only "like" and "recommend" are '
u'supported.',
),
required=True,
default=u'like',
vocabulary=FacebookVerbsVocabulary,
)

# variable name is the same as Plone 5
facebook_username = schema.ASCIILine(
title=_(u'Admins'),
description=_(
Expand All @@ -158,6 +163,7 @@ class ISocialLikeSettings(model.Schema):
default='',
)

# variable name is the same as Plone 5
facebook_app_id = schema.ASCIILine(
title=_(u'Application ID'),
description=_(
Expand All @@ -177,22 +183,178 @@ class ISocialLikeSettings(model.Schema):
),
value_type=schema.Choice(vocabulary=FacebookButtonsVocabulary),
required=True,
default=(u'Like', ),
default=(u'Share', ),
)

fbshare_layout = schema.Choice(
title=_(u'Share Layout'),
description=_(
u'help_share_layout',
default=u'Selects one of the different layouts that '
u'are available for the plugin. Can be one of '
u'"box_count", "button_count", "button".',
),
required=False,
default=u'box_count',
vocabulary=FacebookShareLayoutVocabulary,
)

fbshare_mobile_iframe = schema.Bool(
title=_(u'Share Mobile iframe'),
description=_(
u'help_share_mobile_iframe',
default=u'If set to true, the share button will open the '
u'share dialog in an iframe (instead of a popup) '
u'on top of your website on mobile. This option '
u'is only available for mobile, not desktop. For '
u'more information see Mobile Web Share Dialog.',
),
required=False,
default=True,
)

fbshowlikes = schema.Bool(
title=_(u'Show number of likes'),
fbshare_size = schema.Choice(
title=_(u'Share Size'),
description=_(
u'help_show_likes',
default=u'If enabled, the Facebook button will show the number of '
u'Facebook users who have already liked this page.'
u'help_share_size',
default=u'The button is offered in 2 sizes i.e. "large" '
u'and "small".',
),
default=u'small',
required=False,
vocabulary=FacebookSizeVocabulary,
)

fblike_action = schema.Choice(
title=_(u'Like Action'),
description=_(
u'help_like_action',
default=u'The verb to display on the button. Can be '
u'either "like" or "recommend".',
),
default=u'like',
required=False,
vocabulary=FacebookLikeActionVocabulary,
)

fblike_colorscheme = schema.Choice(
title=_(u'Like Color Scheme'),
description=_(
u'help_like_colorscheme',
default=u'The color scheme used by the plugin for '
u'any text outside of the button itself. '
u'Can be "light" or "dark".',
),
default=u'light',
required=False,
vocabulary=FacebookLikeColorschemeVocabulary,
)

fblike_kid_directed_site = schema.Bool(
title=_(u'Like Kid Directed Site'),
description=_(
u'help_like_kid_directed_site',
default=u'If your web site or online service, or a '
u'portion of your service, is directed to '
u'children under 13 you must enable this.',
),
required=False,
default=True,
)

fblike_layout = schema.Choice(
title=_(u'Like Layout'),
description=_(
u'help_like_layout',
default=u'Selects one of the different layouts that '
u'are available for the plugin. Can be one of '
u'"standard", "button_count", "button" or '
u'"box_count".',
),
default=u'button_count',
required=False,
vocabulary=FacebookLikeLayoutVocabulary,
)

fblike_ref = schema.ASCIILine(
title=_(u'Like Tracking Referrals'),
description=_(
u'help_like_ref',
default=u'A label for tracking referrals which must '
u'be less than 50 characters and can contain '
u'alphanumeric characters and some '
u'punctuation (currently "+/=-.:_").',
),
constraint=validate_like_ref,
required=False,
default='',
)

fblike_share = schema.Bool(
title=_(u'Like Share'),
description=_(
u'help_like_share',
default=u'Specifies whether to include a share '
u'button beside the Like button.',
),
required=False,
default=False,
)

fblike_show_faces = schema.Bool(
title=_(u'Like Show Faces'),
description=_(
u'help_like_show_faces',
default=u'Specifies whether to display profile photos '
u'below the button (standard layout only). You '
u'must not enable this on child-directed sites.'
),
required=False,
default=False,
)

fblike_size = schema.Choice(
title=_(u'Like Size'),
description=_(
u'help_like_size',
default=u'The button is offered in 2 sizes i.e. "large" '
u'and "small".',
),
required=False,
default=u'small',
vocabulary=FacebookSizeVocabulary,
)

fblike_width = schema.Int(
title=_(u'Like Width'),
description=_(
u'help_like_width',
default=u'The width of the plugin (standard layout only), '
u'which is subject to the minimum and default width.'
),
required=False,
default=90,
)

@invariant
def validate_like_width(data):
if u'Like' not in data.fbbuttons:
return
layout_min_width = {
u'standard': 225,
u'box_count': 55,
u'button_count': 90,
u'button': 47
}
min_width = layout_min_width[data.fblike_layout]
if data.fblike_width < min_width:
raise Invalid(_(u'For layout "{layout}" the min width is "{width}"'.format(
layout=data.fblike_layout, width=min_width)))

model.fieldset(
'twitter', label=u'Twitter', fields=['twitter_username'])

# variable name is the same as Plone 5
twitter_username = schema.ASCIILine(
title=_(u'Twitter nick'),
description=_(
Expand Down
28 changes: 27 additions & 1 deletion sc/social/like/tests/test_upgrades.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from plone import api
from plone.registry import field
from plone.registry.interfaces import IRegistry
from plone.registry.record import Record
from sc.social.like.config import IS_PLONE_5
from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.testing import HAS_DEXTERITY
Expand Down Expand Up @@ -297,7 +300,7 @@ def setUp(self):
def test_upgrade_to_3046_registrations(self):
version = self.setup.getLastVersionForProfile(self.profile_id)[0]
self.assertGreaterEqual(int(version), int(self.to_version))
self.assertEqual(self.total_steps, 1)
self.assertEqual(self.total_steps, 2)

@unittest.skipUnless(HAS_DEXTERITY, 'plone.app.contenttypes must be installed')
def test_reindex_catalog(self):
Expand All @@ -324,3 +327,26 @@ def test_reindex_catalog(self):
self.execute_upgrade_step(step)
results = api.content.find(object_provides=ISocialMedia.__identifier__)
self.assertEqual(len(results), 9) # no failure and catalog updated

def test_update_facebook_options(self):
# check if the upgrade step is registered
title = u'Update facebook options'
step = self.get_upgrade_step(title)
self.assertIsNotNone(step)

# simulate state on previous version
from sc.social.like.upgrades.v3046 import OPTIONS_TO_REMOVE
registry = getUtility(IRegistry)
for option in OPTIONS_TO_REMOVE:
record = ISocialLikeSettings.__identifier__ + option
registry.records[record] = Record(
field.TextLine(title=u'Some record'))
self.assertIn(record, registry.records)

# run the upgrade step to validate the update
self.execute_upgrade_step(step)

# Test if our setting is there and set
for option in OPTIONS_TO_REMOVE:
record = ISocialLikeSettings.__identifier__ + option
self.assertNotIn(record, registry.records)
Loading

0 comments on commit 4634ba5

Please sign in to comment.