如何将用户会话变量设置为ckeditor lite用户名以进行跟踪更改

时间:2015-03-12 05:24:52

标签: javascript asp.net-mvc ckeditor

如何动态分配 lite.userName 变量。当用户登录到应用程序时,我需要将用户会话变量分配给lite.username,以便在CKEDITOR中跟踪更改将显示相应的用户。

默认情况下,我可以在config.js文件中设置 lite.userName ='作者&#39 ;; 。但我没有办法用会话分配该用户名。

以下是我的CKEDITOR config.js 文件。我正在使用MVC5& VS 2013

CKEDITOR.editorConfig = function( config ) {
config.extraPlugins = 'button,floatpanel,panel,panelbutton,quicktable,eqneditor';
config.skin = 'office2013';
config.width = 950;
config.height = 647;
// Remove unwanted buttons
config.removeButtons = 'Source,Save,NewPage,Preview,Templates,' +
'Simple Image Browser,ImageButton,Print,CreateDiv,' +
'Textarea,' +
'Form,Checkbox,Radio,TextField,Textarea,Select,Button,HiddenField,'+
//'BidiLtr,BidiRtl,Language,' +
'Format,Anchor,' +
'Flash,HorizontalRule,Smiley,PageBreak,Iframe,' +
'Font,FontSize,' +
'About';    
config.floatingtools = 'Basic';
config.floatingtools_Basic =
[
['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link']
];
var lite = config.lite = config.lite || {};
lite.isTracking = false;    
lite.userName = 'Author';
lite.userId = 'A';     
lite.userStyles = {
"21": 3,
"15": 1,
"18": 2
};
lite.tooltipTemplate = "%a by %u";
};

Body.cshtml

@model System.Data.DataSet
@{
ViewBag.Title = "Body";
Layout = "~/Views/Shared/_ArticleLayout.cshtml";
}
@section scripts
{
@Scripts.Render("~/Scripts/ckeditor/ckeditor.js")
}
<div class="col-lg-12">
<div class="col-lg-12">
<div class="table-responsive">
<table id="table1" class="table table-bordered table-hover table-striped">
<tr>
<th>@Html.DisplayName("Body")
<fieldset>
<input id="ViewID" type="hidden" value="Body" name="ViewName">
</fieldset>
</th>
</tr>
<tr>
<td>
<textarea id="qMaxEditorSource" class="ckeditor">
@Html.Raw(HttpUtility.HtmlDecode(Model.Tables["General"].Rows[0][0].ToString()))
</textarea>
</td>
</tr>
</table>
</div>
</div>
</div>

4 个答案:

答案 0 :(得分:1)

我不知道任何MS代码,但在纯JavaScript中我做了类似这样的事情,我正在挂钩'configLoaded'事件。我还设置了我想要使用的工具栏(我的配置文件中有一对)和语言环境。

var ckEditor = CKEDITOR.replace(node, { language: locale, toolbar: 'Extended'});
ckEditor.on('configLoaded', extendConfig);


function extendConfig() {
    ckEditor.config.lite.userName = appConfig.getUserName();
    ckEditor.config.lite.userId = appConfig.getUserId();
    ckEditor.config.lite.isTracking = false;
}

appConfig是我的应用程序的模块。你可以用任何东西代替。

有关配置的更多信息,请参阅http://docs.ckeditor.com/#!/guide/dev_configuration

答案 1 :(得分:1)

        CKEDITOR.on('instanceCreated', function (event) {
            var editor = event.editor,
				element = editor.element;
                editor.on('configLoaded', function () {
                    var conf = CKEDITOR.config;
                    var lt = conf.lite = conf.lite || {};
                    lt.isTracking = true;
                    lt.userName = "sohel rana";
                    lt.userId = 2;
                    lt.tooltipTemplate = "%a by- %u  ,Time:  %d-%m-%yy: (%t)";
                });
        });

它为我做了诀窍。你可以在session

中设置userId和name

答案 2 :(得分:0)

config.js

var lite = config.lite = config.lite || {};
    lite.isTracking = true;   
    lite.userName = author_user_name();
    lite.userId = author_user_id();
    lite.tooltipTemplate = "%a by %u  , %d-%m-%yy: (%t)";


aspx page
function author_user_name() {
var author_user_name = '@Session["author_user_name"]';
}

function author_user_id() {
var author_user_id = '@Session["author_user_id"]';
}

答案 3 :(得分:0)

&#13;
&#13;
aspx page
function author_user_name() {
var author_user_name = '@Session["author_user_name"]';
return author_user_name;
}

function author_user_id() {
var author_user_id = '@Session["author_user_id"]';
return author_user_id;
}
&#13;
&#13;
&#13;