Use {{aceEditor}} helper to display the ace editor

This commit is contained in:
Robin Ward 2013-05-29 14:08:00 -04:00
parent 0601bb6d74
commit fe3ac50aae
11 changed files with 50 additions and 74 deletions

View file

@ -0,0 +1,14 @@
/**
Inserts a rich code editor
@method aceEditor
@for Handlebars
**/
Ember.Handlebars.registerHelper('aceEditor', function(options) {
var hash = options.hash,
types = options.hashTypes;
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, Discourse.AceEditorView, options);
});

View file

@ -26,10 +26,10 @@
{{#with selectedItem}}
{{textField class="style-name" value=name}}
{{#if view.headerActive}}
{{view Discourse.AceEditorView contentBinding="header" mode="html"}}
{{aceEditor content=header mode="html"}}
{{/if}}
{{#if view.stylesheetActive}}
{{view Discourse.AceEditorView contentBinding="stylesheet" mode="css"}}
{{aceEditor content=stylesheet mode="css"}}
{{/if}}
{{/with}}
<br>

View file

@ -91,7 +91,7 @@
</tr>
</thead>
{{#unless loading}}
{{ render 'admin_report_trust_levels' users_by_trust_level }}
{{ render 'admin/templates/reports/trust_levels_report' users_by_trust_level tagName="tbody" }}
{{/unless}}
</table>
</div>
@ -162,14 +162,14 @@
</tr>
</thead>
{{#unless loading}}
{{ render 'admin_report_visits' visits }}
{{ render 'admin/templates/reports/per_day_counts_report' visits tagName="tbody"}}
{{/unless}}
</table>
</div>
</div>
<div class="dashboard-right">
{{ render admin_github_commits githubCommits }}
{{ render 'admin/templates/commits' githubCommits }}
<div class="dashboard-stats">
<table class="table table-condensed table-hover">

View file

@ -11,11 +11,11 @@
{{/if}}
{{#if html}}
{{view Discourse.AceEditorView contentBinding="model.content" mode="html"}}
{{aceEditor content=model.content mode="html"}}
{{/if}}
{{#if css}}
{{view Discourse.AceEditorView contentBinding="model.content" mode="css"}}
{{aceEditor content=model.content mode="css"}}
{{/if}}

View file

@ -34,31 +34,25 @@ Discourse.AceEditorView = Discourse.View.extend({
},
didInsertElement: function() {
var initAce,
_this = this;
initAce = function() {
_this.editor = ace.edit(_this.$('.ace')[0]);
_this.editor.setTheme("ace/theme/chrome");
_this.editor.setShowPrintMargin(false);
_this.editor.getSession().setMode("ace/mode/" + (_this.get('mode')));
return _this.editor.on("change", function(e) {
/* amending stuff as you type seems a bit out of scope for now - can revisit after launch
changes = @get('changes')
unless changes
changes = []
@set('changes', changes)
changes.push e.data
*/
_this.skipContentChangeEvent = true;
_this.set('content', _this.editor.getSession().getValue());
_this.skipContentChangeEvent = false;
var aceEditorView = this;
var initAce = function() {
aceEditorView.editor = ace.edit(aceEditorView.$('.ace')[0]);
aceEditorView.editor.setTheme("ace/theme/chrome");
aceEditorView.editor.setShowPrintMargin(false);
aceEditorView.editor.getSession().setMode("ace/mode/" + (aceEditorView.get('mode')));
aceEditorView.editor.on("change", function(e) {
aceEditorView.skipContentChangeEvent = true;
aceEditorView.set('content', aceEditorView.editor.getSession().getValue());
aceEditorView.skipContentChangeEvent = false;
});
};
if (window.ace) {
return initAce();
initAce();
} else {
return $LAB.script('http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js').wait(initAce);
$LAB.script('http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js').wait(initAce);
}
}
});

View file

@ -1,11 +0,0 @@
/**
A view for showing commits to the discourse repo.
@class AdminGithubCommitsView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.AdminGithubCommitsView = Discourse.View.extend({
templateName: 'admin/templates/commits'
});

View file

@ -1,4 +0,0 @@
Discourse.AdminGroupsView = Discourse.View.extend({
});

View file

@ -1,13 +0,0 @@
/**
The view that displays the number of users at each trust level
on the admin dashboard.
@class AdminReportTrustLevelsView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
Discourse.AdminReportTrustLevelsView = Discourse.View.extend({
templateName: 'admin/templates/reports/trust_levels_report',
tagName: 'tbody'
});

View file

@ -1,4 +0,0 @@
Discourse.AdminReportVisitsView = Discourse.View.extend({
templateName: 'admin/templates/reports/per_day_counts_report',
tagName: 'tbody'
});

View file

@ -17,6 +17,18 @@ Discourse.Utilities = {
return size;
},
/**
Allows us to supply bindings without "binding" to a helper.
**/
normalizeHash: function(hash, hashTypes) {
for (var prop in hash) {
if (hashTypes[prop] === 'ID') {
hash[prop + 'Binding'] = hash[prop];
delete hash[prop];
}
}
},
categoryUrlId: function(category) {
if (!category) return "";
var id = Em.get(category, 'id');

View file

@ -1,15 +1,3 @@
/**
Allows us to supply bindings without "binding" to a helper.
**/
function normalizeHash(hash, hashTypes) {
for (var prop in hash) {
if (hashTypes[prop] === 'ID') {
hash[prop + 'Binding'] = hash[prop];
delete hash[prop];
}
}
}
/**
Breaks up a long string
@ -78,7 +66,7 @@ Ember.Handlebars.registerHelper('textField', function(options) {
var hash = options.hash,
types = options.hashTypes;
normalizeHash(hash, types);
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, Discourse.TextField, options);
});
@ -93,7 +81,7 @@ Ember.Handlebars.registerHelper('inputTip', function(options) {
var hash = options.hash,
types = options.hashTypes;
normalizeHash(hash, types);
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, Discourse.InputTipView, options);
});
@ -108,7 +96,7 @@ Ember.Handlebars.registerHelper('popupInputTip', function(options) {
var hash = options.hash,
types = options.hashTypes;
normalizeHash(hash, types);
Discourse.Utilities.normalizeHash(hash, types);
return Ember.Handlebars.helpers.view.call(this, Discourse.PopupInputTipView, options);
});