1
0
mirror of https://github.com/flarum/core.git synced 2025-10-18 10:16:09 +02:00
Files
php-flarum/ember/forum/app/views/discussion.js
Toby Zerner 40a6d77e74 Big front-end asset/filestructure refactor
- Extract shared Ember components into a “flarum-common” ember-cli
addon. This can be used by both the forum + admin Ember apps, keeping
things DRY
- Move LESS styles into their own top-level directory and do a similar
thing (extract common styles)
- Add LESS/JS compilation and versioning to PHP (AssetManager)
- Set up admin entry point

(Theoretical) upgrade instructions:
- Delete everything in [app_root]/public
- Set up tooling in forum/admin Ember apps (npm install/update, bower
install/update) and then build them (ember build)
- php artisan vendor:publish
- Upgrade flarum/flarum repo (slight change in a config file)
- If you need to trigger a LESS/JS recompile, delete the .css/.js files
in [app_root]/public/flarum. I set up LiveReload to do this for me when
I change files in less/ or ember/

Todo:
- Start writing admin app!
- Remove bootstrap/font-awesome from repo and instead depend on their
composer packages? Maybe? (Bower is not an option here)
2015-03-29 22:13:26 +10:30

92 lines
3.2 KiB
JavaScript

import Ember from 'ember';
import HasItemLists from 'flarum-forum/mixins/has-item-lists';
import DropdownSplit from 'flarum-forum/components/ui/dropdown-split';
import StreamScrubber from 'flarum-forum/components/discussion/stream-scrubber';
var $ = Ember.$;
export default Ember.View.extend(HasItemLists, {
itemLists: ['sidebar'],
discussion: Ember.computed.alias('controller.model'),
didInsertElement: function() {
this.get('controller').on('loaded', this, this.loaded);
this.get('controller').on('startWasChanged', this, this.startWasChanged);
},
willDestroyElement: function() {
this.get('controller').off('loaded', this, this.loaded);
this.get('controller').off('startWasChanged', this, this.startWasChanged);
},
// When the controller has finished loading, we want to scroll down to the
// appropriate post instantly (without animation).
loaded: function() {
this.get('streamContent').send('goToNumber', this.get('controller.start'), true);
},
// When the start position of the discussion changes, we want to scroll
// down to the appropriate post.
startWasChanged: function(start) {
this.get('streamContent').send('goToNumber', start);
},
// ------------------------------------------------------------------------
// OBSERVERS
// ------------------------------------------------------------------------
// Whenever the model's title changes, we want to update that document's
// title the reflect the new title.
updateTitle: Ember.observer('controller.model.title', function() {
this.set('controller.controllers.application.pageTitle', this.get('controller.model.title'));
}),
// ------------------------------------------------------------------------
// LISTENERS
// ------------------------------------------------------------------------
populateSidebar: function(items) {
items.pushObjectWithTag(DropdownSplit.extend({
items: this.populateItemList('controls'),
icon: 'reply',
buttonClass: 'btn-primary',
listItemClass: 'primary-control',
}), 'controls');
},
addStreamScrubber: Ember.on('didInsertElement', function() {
this.get('sidebar').pushObjectWithTag(StreamScrubber.extend({
streamContent: this.get('streamContent'),
listItemClass: 'title-control'
}), 'scrubber');
}),
populateControls: function(items) {
var view = this;
this.addActionItem(items, 'reply', 'Reply', 'reply', null, function() {
view.get('streamContent').send('goToLast');
view.get('controller').send('reply');
});
this.addSeparatorItem(items);
this.addActionItem(items, 'rename', 'Rename', 'pencil', 'discussion.canEdit', function() {
var discussion = view.get('controller.model');
var currentTitle = discussion.get('title');
var title = prompt('Enter a new title for this discussion:', currentTitle);
if (title && title !== currentTitle) {
view.get('controller').send('rename', title);
}
});
this.addActionItem(items, 'delete', 'Delete', 'times', 'discussion.canDelete', function() {
if (confirm('Are you sure you want to delete this discussion?')) {
view.get('controller').send('delete');
}
});
}
});