-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #694 from tf/widget-configuration
Widget configuration
- Loading branch information
Showing
40 changed files
with
856 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pageflow.WidgetType = pageflow.Object.extend({ | ||
initialize: function(serverSideConfig, clientSideConfig) { | ||
this.name = serverSideConfig.name; | ||
this.translationKey = serverSideConfig.translationKey; | ||
this.configurationEditorView = clientSideConfig.configurationEditorView; | ||
this.isOptional = clientSideConfig.isOptional; | ||
}, | ||
|
||
hasConfiguration: function() { | ||
return !!this.configurationEditorView; | ||
}, | ||
|
||
createConfigurationEditorView: function(options) { | ||
var constructor = this.configurationEditorView; | ||
|
||
return new constructor(_.extend({ | ||
attributeTranslationKeyPrefixes: [ | ||
'pageflow.editor.widgets.attributes.' + this.name, | ||
'pageflow.editor.widgets.common_attributes' | ||
] | ||
}, options)); | ||
} | ||
}); |
53 changes: 53 additions & 0 deletions
53
app/assets/javascripts/pageflow/editor/api/widget_types.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
pageflow.WidgetTypes = pageflow.Object.extend({ | ||
initialize: function() { | ||
this._clientSideConfigs = {}; | ||
this._optionalRoles = {}; | ||
}, | ||
|
||
register: function(name, config) { | ||
if (this._setup) { | ||
throw 'Widget types already set up. Register widget types before initializers run.'; | ||
} | ||
|
||
this._clientSideConfigs[name] = config; | ||
}, | ||
|
||
setup: function(serverSideConfigsByRole) { | ||
this._setup = true; | ||
this._widgetTypesByName = {}; | ||
|
||
var roles = _.keys(serverSideConfigsByRole); | ||
|
||
this._widgetTypesByRole = roles.reduce(_.bind(function(result, role) { | ||
result[role] = serverSideConfigsByRole[role].map(_.bind(function(serverSideConfig) { | ||
var clientSideConfig = this._clientSideConfigs[serverSideConfig.name] || {}; | ||
var widgetType = new pageflow.WidgetType(serverSideConfig, clientSideConfig); | ||
|
||
this._widgetTypesByName[serverSideConfig.name] = widgetType; | ||
return widgetType; | ||
}, this)); | ||
|
||
return result; | ||
}, this), {}); | ||
}, | ||
|
||
findAllByRole: function(role) { | ||
return this._widgetTypesByRole[role] || []; | ||
}, | ||
|
||
findByName: function(name) { | ||
if (!this._widgetTypesByName[name]) { | ||
throw('Could not find widget type with name "' + name +'"'); | ||
} | ||
|
||
return this._widgetTypesByName[name]; | ||
}, | ||
|
||
registerRole: function(role, options) { | ||
this._optionalRoles[role] = options.isOptional; | ||
}, | ||
|
||
isOptional: function(role) { | ||
return !!this._optionalRoles[role]; | ||
} | ||
}); |
31 changes: 23 additions & 8 deletions
31
app/assets/javascripts/pageflow/editor/collections/widgets_collection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
pageflow.WidgetsCollection = Backbone.Collection.extend({ | ||
model: pageflow.Widget, | ||
|
||
initialize: function(models, options) { | ||
options = options || {}; | ||
this.subject = options.subject; | ||
initialize: function() { | ||
this.listenTo(this, 'change:type_name change:configuration', function() { | ||
this.batchSave(); | ||
}); | ||
}, | ||
|
||
url: function() { | ||
return this.subject.widgetsUrlRoot() + '/widgets'; | ||
return '/editor/subjects/entries/' + this.subject.id + '/widgets'; | ||
}, | ||
}); | ||
|
||
pageflow.WidgetsCollection.createForSubject = function(subject) { | ||
return new pageflow.WidgetsCollection([], {subject: subject}); | ||
}; | ||
batchSave: function(options) { | ||
var subject = this.subject; | ||
|
||
return Backbone.sync('patch', subject, _.extend(options || {}, { | ||
url: this.url() + '/batch', | ||
|
||
attrs: { | ||
widgets: this.map(function(widget) { | ||
return widget.toJSON(); | ||
}) | ||
}, | ||
|
||
success: function(response) { | ||
subject.trigger('sync:widgets', subject, response, {}); | ||
} | ||
})); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
app/assets/javascripts/pageflow/editor/initializers/setup_widget_types.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
pageflow.app.addInitializer(function(options) { | ||
pageflow.editor.widgetTypes = options.widget_types; | ||
pageflow.editor.widgetTypes.registerRole('navigation', { | ||
isOptional: true | ||
}); | ||
|
||
pageflow.editor.widgetTypes.setup(options.widget_types); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
app/assets/javascripts/pageflow/editor/models/mixins/widget_subject.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
pageflow.Theming = Backbone.Model.extend({ | ||
modelName: 'theming', | ||
i18nKey: 'pageflow/theming', | ||
collectionName: 'themings', | ||
|
||
mixins: [pageflow.widgetSubject] | ||
collectionName: 'themings' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/assets/javascripts/pageflow/editor/models/widget_configuration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pageflow.WidgetConfiguration = pageflow.Configuration.extend({ | ||
i18nKey: 'pageflow/widget', | ||
|
||
defaults: {} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
app/assets/javascripts/pageflow/editor/templates/edit_widget.jst.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
<div class="widget_type"> | ||
</div> | ||
<a class="back"><%= I18n.t('pageflow.editor.templates.edit_widget.back') %></a> |
3 changes: 3 additions & 0 deletions
3
app/assets/javascripts/pageflow/editor/templates/widget_item.jst.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="widget_type"> | ||
</div> | ||
<a class="settings" title="<%= I18n.t('pageflow.editor.templates.widget_item.settings') %>"></a> |
32 changes: 11 additions & 21 deletions
32
app/assets/javascripts/pageflow/editor/views/edit_widget_view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
pageflow.EditWidgetView = Backbone.Marionette.Layout.extend({ | ||
pageflow.EditWidgetView = Backbone.Marionette.ItemView.extend({ | ||
template: 'templates/edit_widget', | ||
tagName: 'li', | ||
className: 'edit_widget', | ||
|
||
regions: { | ||
widgetTypeContainer: '.widget_type' | ||
}, | ||
|
||
ui: { | ||
role: 'h2' | ||
events: { | ||
'click a.back': function() { | ||
editor.navigate('/meta_data/widgets', {trigger: true}); | ||
} | ||
}, | ||
|
||
onRender: function() { | ||
var widgetTypes = this.options.widgetTypes[this.model.role()] || []; | ||
|
||
this.widgetTypeContainer.show(new pageflow.SelectInputView({ | ||
model: this.model, | ||
propertyName: 'type_name', | ||
label: I18n.t('pageflow.widgets.roles.' + this.model.role()), | ||
collection: widgetTypes, | ||
valueProperty: 'name', | ||
translationKeyProperty: 'translationKey', | ||
includeBlank: true | ||
})); | ||
var configurationEditor = this.model.widgetType().createConfigurationEditorView({ | ||
model: this.model.configuration, | ||
tab: this.options.tab | ||
}); | ||
|
||
this.$el.toggle(widgetTypes.length > 1); | ||
this.appendSubview(configurationEditor); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.