Files
web-doc-editor/js/ui/task/SaveFileTask.js
Peter Kokot f06fee3640 Sync final newlines
This patch adds some missing newlines and trims multiple final newlines
into a single newline.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-02 03:44:40 +02:00

137 lines
5.7 KiB
JavaScript

Ext.namespace('ui', 'ui.task');
// config - {prefix, ftype, fid, fpath, fname, lang, storeRecord}
ui.task.SaveFileTask = function(config)
{
Ext.apply(this, config);
var id_prefix = this.prefix + '-' + this.ftype,
msg = Ext.MessageBox.wait(_('Saving data...')),
codeContent = Ext.getCmp(this.prefix + '-' + this.ftype + '-FILE-' + this.fid).getValue();
XHR({
scope : this,
params : {
task : 'saveFile',
filePath : this.fpath,
fileName : this.fname,
fileLang : this.lang,
fileContent : codeContent
},
success : function(r)
{
var o = Ext.util.JSON.decode(r.responseText);
if (this.prefix === 'FNU') {
// Update our store
if( this.ftype === 'EN' ) {
this.storeRecord.set('en_revision', o.revision);
this.storeRecord.set('fileModified', '{"user":"' + PhDOE.user.login + '", "anonymousIdent":"' + PhDOE.user.anonymousIdent + '"}');
} else {
this.storeRecord.set('revision', o.en_revision);
this.storeRecord.set('fileModified', '{"user":"' + PhDOE.user.login + '", "anonymousIdent":"' + PhDOE.user.anonymousIdent + '"}');
this.storeRecord.set('maintainer', o.maintainer);
}
this.storeRecord.commit();
}
if (this.prefix === 'FE') {
// Update our store
if( this.ftype === 'EN' ) {
this.storeRecord.set('fileModified', '{"user":"' + PhDOE.user.login + '", "anonymousIdent":"' + PhDOE.user.anonymousIdent + '"}');
this.storeRecord.commit();
} else {
this.storeRecord.set('maintainer', o.maintainer);
this.storeRecord.set('fileModified', '{"user":"' + PhDOE.user.login + '", "anonymousIdent":"' + PhDOE.user.anonymousIdent + '"}');
this.storeRecord.commit();
}
}
if (this.prefix === 'FNR') {
// Update our store
if( this.ftype === 'EN' ) {
this.storeRecord.set('reviewed', o.reviewed);
this.storeRecord.set('fileModified', '{"user":"' + PhDOE.user.login + '", "anonymousIdent":"' + PhDOE.user.anonymousIdent + '"}');
this.storeRecord.commit();
} else {
this.storeRecord.set('reviewed', o.reviewed);
this.storeRecord.set('maintainer', o.reviewed_maintainer);
this.storeRecord.set('fileModified', '{"user":"' + PhDOE.user.login + '", "anonymousIdent":"' + PhDOE.user.anonymousIdent + '"}');
this.storeRecord.commit();
}
}
if (this.prefix === 'AF') {
this.storeRecord.getUI().addClass('fileModifiedByMe'); // tree node
}
// As the content have been modified, we need to change the originalContent to handle the "codemodified" action
Ext.getCmp(this.prefix + '-' + this.ftype + '-FILE-' + this.fid).setOriginalContent(codeContent);
// Add this files into WorkTreeGrid. Before, we delete it from WorkTreeGrid if this file have been same by anothers users.
ui.cmp.WorkTreeGrid.getInstance().delRecord(o.id);
ui.cmp.PatchesTreeGrid.getInstance().delRecord(o.id);
ui.cmp.WorkTreeGrid.getInstance().addRecord(
o.id, this.lang + this.fpath, this.fname, 'update'
);
// reset file
Ext.getCmp(id_prefix + '-FILE-' + this.fid + '-btn-save').disable();
Ext.getCmp(id_prefix + '-FILE-' + this.fid).isModified = false;
Ext.getCmp(this.prefix + '-' + this.fid).isModified = false;
Ext.getCmp(id_prefix + '-PANEL-' + this.fid).setTitle(
Ext.getCmp(id_prefix + '-PANEL-' + this.fid).permlink +
Ext.getCmp(id_prefix + '-PANEL-' + this.fid).originTitle
);
var cmp;
if( this.lang === 'en' ) {
cmp = Ext.getCmp(this.prefix + '-LANG-FILE-' + this.fid);
} else {
cmp = Ext.getCmp(this.prefix + '-EN-FILE-' + this.fid);
}
if (this.ftype === 'ALL' || !cmp.isModified) {
// reset tab-panel
Ext.getCmp(this.prefix + '-' + this.fid).setTitle(
Ext.getCmp(this.prefix + '-' + this.fid).originTitle
);
}
// Remove wait msg
msg.hide();
// Notify
PhDOE.notify('info', _('Document saved'), String.format(_('Document <br><br><b>{0}</b><br><br> was saved successfully !'), this.lang + this.fpath + this.fname));
},
failure : function(r)
{
var o = Ext.util.JSON.decode(r.responseText);
// Remove wait msg
msg.hide();
// If there is some Xml error, we display the Xml window
if( o.XmlError && o.XmlError != 'no_error' )
{
// Display a message to inform that a file cann't be saved with some XML errors
Ext.MessageBox.alert(_('XML Errors'), _('There is somes XML\'s errors.<br /><br />You must fix it before saving this file.<br /><br />Valid this window to show this errors.'), function() {
new ui.cmp.CheckXmlWin({
errors : o.XmlError
});
});
}
if( o.type ) {
PhDOE.winForbidden(o.type);
}
}
});
};