Merge branch 'version143' into develop

This commit is contained in:
trendschau 2020-12-15 20:52:20 +01:00
commit a9b5432927
16 changed files with 539 additions and 656 deletions

View file

@ -490,7 +490,7 @@ class BlockApiController extends ContentController
# minimum permission is that user is allowed to update his own content
if(!$this->c->acl->isAllowed($_SESSION['role'], 'mycontent', 'update'))
{
return $response->withJson(array('data' => false, 'errors' => ['message' => 'You are not allowed to publish content.']), 403);
return $response->withJson(array('data' => false, 'errors' => ['message' => 'You are not allowed to delete this content.']), 403);
}
# set structure
@ -507,7 +507,7 @@ class BlockApiController extends ContentController
# check ownership. This code should nearly never run, because there is no button/interface to trigger it.
if(!$this->checkContentOwnership())
{
return $response->withJson(array('data' => false, 'errors' => ['message' => 'You are not allowed to delete content.']), 403);
return $response->withJson(array('data' => false, 'errors' => ['message' => 'You are not allowed to delete this content.']), 403);
}
}

View file

@ -19,7 +19,6 @@ class SettingsController extends Controller
{
$user = new User();
$settings = $this->c->get('settings');
# $users = $user->getUsers();
$route = $request->getAttribute('route');
$navigation = $this->getNavigation();
@ -30,7 +29,6 @@ class SettingsController extends Controller
'acl' => $this->c->acl,
'navigation' => $navigation,
'content' => $content,
# 'users' => $users,
'route' => $route->getName()
));
}
@ -587,52 +585,46 @@ class SettingsController extends Controller
return $response->withRedirect($this->c->router->pathFor('user.show', ['username' => $_SESSION['user']] ));
}
$validate = new Validation();
if($validate->username($args['username']))
# get settings
$settings = $this->c->get('settings');
# get user with userdata
$user = new User();
$userdata = $user->getSecureUser($args['username']);
if(!$userdata)
{
# get settings
$settings = $this->c->get('settings');
# get user with userdata
$user = new User();
$userdata = $user->getSecureUser($args['username']);
$username = $userdata['username'];
# instantiate field-builder
$fieldsModel = new Fields();
# get the field-definitions
$fieldDefinitions = $this->getUserFields($userdata['userrole']);
# prepare userdata for field-builder
$userSettings['users']['user'] = $userdata;
# generate the input form
$userform = $fieldsModel->getFields($userSettings, 'users', 'user', $fieldDefinitions);
$route = $request->getAttribute('route');
$navigation = $this->getNavigation();
# set navigation active
$navigation['Users']['active'] = true;
return $this->render($response, 'settings/user.twig', array(
'settings' => $settings,
'acl' => $this->c->acl,
'navigation' => $navigation,
'usersettings' => $userSettings, // needed for image url in form, will overwrite settings for field-template
'userform' => $userform, // field model, needed to generate frontend-field
'userdata' => $userdata, // needed to fill form with data
# 'userrole' => false, // not needed ?
# 'username' => $args['username'], // not needed ?
'route' => $route->getName() // needed to set link active
));
$this->c->flash->addMessage('error', 'User does not exists');
return $response->withRedirect($this->c->router->pathFor('user.account'));
}
$this->c->flash->addMessage('error', 'User does not exists');
return $response->withRedirect($this->c->router->pathFor('user.account'));
# instantiate field-builder
$fieldsModel = new Fields();
# get the field-definitions
$fieldDefinitions = $this->getUserFields($userdata['userrole']);
# prepare userdata for field-builder
$userSettings['users']['user'] = $userdata;
# generate the input form
$userform = $fieldsModel->getFields($userSettings, 'users', 'user', $fieldDefinitions);
$route = $request->getAttribute('route');
$navigation = $this->getNavigation();
# set navigation active
$navigation['Users']['active'] = true;
return $this->render($response, 'settings/user.twig', array(
'settings' => $settings,
'acl' => $this->c->acl,
'navigation' => $navigation,
'usersettings' => $userSettings, // needed for image url in form, will overwrite settings for field-template
'userform' => $userform, // field model, needed to generate frontend-field
'userdata' => $userdata, // needed to fill form with data
'route' => $route->getName() // needed to set link active
));
}
public function listUser($request, $response)
@ -796,7 +788,12 @@ class SettingsController extends Controller
return $response->withRedirect($redirectRoute);
}
}
# change error-array for formbuilder
$errors = $_SESSION['errors'];
unset($_SESSION['errors']);
$_SESSION['errors']['user'] = $errors;#
$this->c->flash->addMessage('error', 'Please correct your input');
return $response->withRedirect($redirectRoute);
}

View file

@ -8,10 +8,10 @@ class User extends WriteYaml
{
$userDir = __DIR__ . '/../../settings/users';
/* check if plugins directory exists */
/* check if users directory exists */
if(!is_dir($userDir)){ return array(); }
/* get all plugins folder */
/* get all user files */
$users = array_diff(scandir($userDir), array('..', '.'));
$cleanUser = array();
@ -23,6 +23,43 @@ class User extends WriteYaml
return $cleanUser;
}
# returns array of emails of all users
public function getUserMails()
{
$userDir = __DIR__ . '/../../settings/users';
/* check if users directory exists */
if(!is_dir($userDir)){ return array(); }
/* get all user files */
$users = array_diff(scandir($userDir), array('..', '.'));
$usermails = array();
foreach($users as $key => $user)
{
if($user == '.logins'){ continue; }
$contents = file_get_contents($userDir . DIRECTORY_SEPARATOR . $user);
if($contents === false){ continue; }
$searchfor = 'email:';
# escape special characters in the query
$pattern = preg_quote($searchfor, '/');
# finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
# search, and store first occurence in $matches
if(preg_match($pattern, $contents, $match)){
$usermails[] = trim(str_replace("email:", "", $match[0]));
}
}
return $usermails;
}
public function getUser($username)
{

View file

@ -36,6 +36,26 @@ class Validation
return false;
}, 'only jpg, jpeg, png, webp, allowed');
# checks if email is available if user is created
Validator::addRule('emailAvailable', function($field, $value, array $params, array $fields) use ($user)
{
$usermails = $user->getUserMails();
if(in_array(trim($value), $usermails)){ return false; }
return true;
}, 'taken');
# checks if email is available if userdata is updated
Validator::addRule('emailChanged', function($field, $value, array $params, array $fields) use ($user)
{
$userdata = $user->getSecureUser($fields['username']);
if($userdata['email'] == $value){ return true; } # user has not updated his email
$usermails = $user->getUserMails();
if(in_array(trim($value), $usermails)){ return false; }
return true;
}, 'taken');
# checks if username is free when create new user
Validator::addRule('userAvailable', function($field, $value, array $params, array $fields) use ($user)
{
$userdata = $user->getUser($value);
@ -43,6 +63,7 @@ class Validation
return true;
}, 'taken');
# checks if user exists when userdata is updated
Validator::addRule('userExists', function($field, $value, array $params, array $fields) use ($user)
{
$userdata = $user->getUser($value);
@ -189,6 +210,7 @@ class Validation
$v->rule('noHTML', 'lastname')->message(" contains HTML");
$v->rule('lengthBetween', 'lastname', 2, 40);
$v->rule('email', 'email')->message("e-mail is invalid");
$v->rule('emailAvailable', 'email')->message("Email already taken");
$v->rule('in', 'userrole', $userroles);
return $this->validationResult($v);
@ -206,6 +228,7 @@ class Validation
$v->rule('noHTML', 'lastname')->message(" contains HTML");
$v->rule('lengthBetween', 'lastname', 2, 40);
$v->rule('email', 'email')->message("e-mail is invalid");
$v->rule('emailChanged', 'email')->message("Email already taken");
$v->rule('in', 'userrole', $userroles);
return $this->validationResult($v);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -31,7 +31,6 @@ const contentComponent = Vue.component('content-block', {
compmarkdown: '',
componentType: '',
disabled: false,
//fix load: false,
newblock: false,
}
},
@ -312,6 +311,7 @@ const contentComponent = Vue.component('content-block', {
var method = 'PUT';
}
sendJson(function(response, httpStatus)
{
if(httpStatus == 400)
@ -415,56 +415,41 @@ const contentComponent = Vue.component('content-block', {
var bloxid = bloxeditor.getElementsByClassName('blox')[0].dataset.id;
var self = this;
var url = self.$root.$data.root + '/api/v1/block';
var params = {
'url': document.getElementById("path").value,
'block_id': bloxid,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
};
var method = 'DELETE';
sendJson(function(response, httpStatus)
{
if(httpStatus == 400)
{
self.$root.$data.unsafed = false;
self.activatePage();
publishController.errors.message = "Looks like you are logged out. Please login and try again.";
}
if(response)
{
self.$root.$data.unsafed = false;
self.activatePage();
var result = JSON.parse(response);
if(result.errors)
{
publishController.errors.message = result.errors.message;
}
else
{
self.switchToPreviewMode();
self.$root.$data.html.splice(bloxid,1);
self.$root.$data.markdown.splice(bloxid,1);
self.$root.$data.blockMarkdown = '';
self.$root.$data.blockType = '';
/* update the table of content if in result */
if(result.toc)
{
self.$root.$data.html.splice(result.toc.id, 1, result.toc);
}
/* update the navigation and mark navigation item as modified */
navi.getNavi();
}
myaxios.delete('/api/v1/block',{
data: {
'url': document.getElementById("path").value,
'block_id': bloxid,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
}
})
.then(function (response)
{
self.$root.$data.unsafed = false;
self.activatePage();
self.switchToPreviewMode();
self.$root.$data.html.splice(bloxid,1);
self.$root.$data.markdown.splice(bloxid,1);
self.$root.$data.blockMarkdown = '';
self.$root.$data.blockType = '';
/* update the table of content if in result */
if(response.data.toc)
{
self.$root.$data.html.splice(response.data.toc.id, 1, response.data.toc);
}
}, method, url, params);
/* update the navigation and mark navigation item as modified */
navi.getNavi();
})
.catch(function (error)
{
if(error.response)
{
publishController.errors.message = error.response.data.errors.message;
}
});
},
},
})
@ -1612,45 +1597,36 @@ const imageComponent = Vue.component('image-component', {
self.imgpreview = e.target.result;
/* load image to server */
var url = self.$root.$data.root + '/api/v1/image';
var params = {
myaxios.post('/api/v1/image',{
'url': document.getElementById("path").value,
'image': e.target.result,
'name': imageFile.name,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
};
})
.then(function (response) {
self.load = false;
self.$parent.activatePage();
var method = 'POST';
sendJson(function(response, httpStatus)
{
self.imgmeta = true;
self.imgfile = response.data.name;
self.$emit('updatedMarkdown', '![]('+ response.data.name +')');
})
.catch(function (error)
{
/*
if(httpStatus == 400)
{
self.activatePage();
publishController.errors.message = "Looks like you are logged out. Please login and try again.";
}
if(response)
{
self.load = false;
self.$parent.activatePage();
var result = JSON.parse(response);
if(result.errors)
{
publishController.errors.message = result.errors;
}
else
{
self.imgmeta = true;
self.imgfile = result.name;
self.$emit('updatedMarkdown', '![]('+ result.name +')');
}
}
}, method, url, params);
*/
if(error.response.data.errors.message)
{
publishController.errors.message = error.response.data.errors.message;
}
});
}
}
}
@ -1803,47 +1779,30 @@ const fileComponent = Vue.component('file-component', {
reader.readAsDataURL(uploadedFile);
reader.onload = function(e) {
/* load file to server */
var url = self.$root.$data.root + '/api/v1/file';
var params = {
myaxios.post('/api/v1/file',{
'url': document.getElementById("path").value,
'file': e.target.result,
'name': uploadedFile.name,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
};
var method = 'POST';
sendJson(function(response, httpStatus)
{
if(httpStatus == 400)
{
self.activatePage();
publishController.errors.message = "Looks like you are logged out. Please login and try again.";
}
if(response)
{
self.load = false;
self.$parent.activatePage();
})
.then(function (response) {
self.load = false;
self.$parent.activatePage();
var result = JSON.parse(response);
if(result.errors)
{
publishController.errors.message = result.errors;
}
else
{
self.filemeta = true;
self.filetitle = result.info.title;
self.fileextension = result.info.extension;
self.fileurl = result.info.url;
self.createmarkdown();
}
}
}, method, url, params);
self.filemeta = true;
self.filetitle = response.data.info.title;
self.fileextension = response.data.info.extension;
self.fileurl = response.data.info.url;
self.createmarkdown();
})
.catch(function (error)
{
if(error.response.data.errors.message)
{
publishController.errors.message = error.response.data.errors.message;
}
});
}
}
}
@ -1890,82 +1849,63 @@ let editor = new Vue({
publishController.visual = true;
var self = this;
var url = this.root + '/api/v1/article/html';
var params = {
var self = this;
myaxios.post('/api/v1/article/html',{
'url': document.getElementById("path").value,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
};
var method = 'POST';
})
.then(function (response) {
var contenthtml = response.data.data;
self.title = contenthtml[0];
self.html = contenthtml;
var initialcontent = document.getElementById("initial-content");
initialcontent.parentNode.removeChild(initialcontent);
})
.catch(function (error)
{
if(error.response)
{
self.errors.title = error.response.errors;
}
});
sendJson(function(response, httpStatus)
{
if(httpStatus == 400)
{
}
if(response)
{
var result = JSON.parse(response);
if(result.errors)
{
self.errors.title = result.errors;
}
else
{
var contenthtml = result.data;
self.title = contenthtml[0];
self.html = contenthtml;
var initialcontent = document.getElementById("initial-content");
initialcontent.parentNode.removeChild(initialcontent);
}
}
}, method, url, params);
var url = this.root + '/api/v1/article/markdown';
sendJson(function(response, httpStatus)
{
if(httpStatus == 400)
{
}
if(response)
{
var result = JSON.parse(response);
if(result.errors)
{
self.errors.title = result.errors;
}
else
{
self.markdown = result.data;
myaxios.post('/api/v1/article/markdown',{
'url': document.getElementById("path").value,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
})
.then(function (response) {
self.markdown = response.data.data;
/* activate math plugin */
if (typeof renderMathInElement === "function") {
self.$nextTick(function () {
renderMathInElement(document.getElementById("blox"));
});
}
/* activate math plugin */
if (typeof renderMathInElement === "function") {
self.$nextTick(function () {
renderMathInElement(document.getElementById("blox"));
});
}
/* check for youtube videos */
if (typeof typemillUtilities !== "undefined")
{
setTimeout(function(){
self.$nextTick(function ()
{
typemillUtilities.start();
});
}, 200);
}
}
/* check for youtube videos */
if (typeof typemillUtilities !== "undefined") {
setTimeout(function(){
self.$nextTick(function () {
typemillUtilities.start();
});
}, 200);
}
}, method, url, params);
})
.catch(function (error)
{
if(error.response)
{
self.errors.title = error.response.errors;
}
});
},
methods: {
onStart: function()
@ -1974,60 +1914,51 @@ let editor = new Vue({
},
moveBlock: function(evt)
{
publishController.errors.message = false;
var params = {
var self = this;
myaxios.put('/api/v1/moveblock',{
'url': document.getElementById("path").value,
'old_index': evt.oldIndex,
'new_index': evt.newIndex,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
};
publishController.errors.message = false;
var url = this.root + '/api/v1/moveblock';
var self = this;
var method = 'PUT';
sendJson(function(response, httpStatus)
{
if(httpStatus == 400)
{
}
if(response)
{
})
.then(function (response) {
var result = JSON.parse(response);
self.freeze = false;
self.markdown = response.data.markdown;
self.blockMarkdown = '';
self.blockType = '';
if(result.errors)
{
publishController.errors.message = result.errors;
publishController.publishDisabled = false;
}
else
{
self.freeze = false;
self.markdown = result.markdown;
self.blockMarkdown = '';
self.blockType = '';
if(result.toc)
{
self.html.splice(result.toc.id, 1, result.toc);
}
publishController.publishDisabled = false;
publishController.publishResult = "";
/* update the navigation and mark navigation item as modified */
navi.getNavi();
/* update the math if plugin is there */
self.checkMath(params.new_index+1);
}
if(response.data.toc)
{
self.html.splice(response.data.toc.id, 1, response.data.toc);
}
}, method, url, params);
publishController.publishDisabled = false;
publishController.publishResult = "";
/* update the navigation and mark navigation item as modified */
navi.getNavi();
/* update the math if plugin is there */
self.checkMath(params.new_index+1);
})
.catch(function (error)
{
publishController.publishDisabled = false;
if(error.response.data.message)
{
publishController.errors.message = error.response.data.message;
}
if(error.response.data.errors.message)
{
publishController.errors.message = error.response.data.errors.message;
}
});
},
setData: function(event, blocktype, body)
{

View file

@ -28,7 +28,19 @@ const navcomponent = Vue.component('navigation', {
},
onEnd : function(evt)
{
var locator = {
if(evt.from.parentNode.id == evt.to.parentNode.id && evt.oldIndex == evt.newIndex)
{
return
}
evt.item.classList.add("load");
var self = this;
self.$root.$data.freeze = true;
self.errors = {title: false, content: false, message: false};
myaxios.post('/api/v1/article/sort',{
'item_id': evt.item.id,
'parent_id_from': evt.from.parentNode.id,
'parent_id_to': evt.to.parentNode.id,
@ -38,49 +50,32 @@ const navcomponent = Vue.component('navigation', {
'url': document.getElementById("path").value,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
};
})
.then(function (response) {
if(locator.parent_id_from == locator.parent_id_to && locator.index_old == locator.index_new)
{
return
}
evt.item.classList.add("load");
var self = this;
self.$root.$data.freeze = true;
self.errors = {title: false, content: false, message: false};
var url = this.root + '/api/v1/article/sort';
var method = 'POST';
sendJson(function(response, httpStatus)
{
if(response)
{
self.$root.$data.freeze = false;
var result = JSON.parse(response);
self.$root.$data.freeze = false;
if(result.errors)
{
publishController.errors.message = result.errors;
}
if(result.url)
{
window.location.replace(result.url);
}
if(result.data)
{
evt.item.classList.remove("load");
self.$root.$data.items = result.data;
}
if(response.data.url)
{
window.location.replace(response.data.url);
}
}, method, url, locator );
if(response.data.data)
{
evt.item.classList.remove("load");
self.$root.$data.items = response.data.data;
}
})
.catch(function (error)
{
if(error.response.data.errors.message)
{
publishController.errors.message = error.response.data.errors;
}
});
},
getUrl : function(root, url)
{
return root + '/tm/content/' + this.$root.$data.editormode + url
return root + '/tm/content/' + this.$root.$data.editormode + url;
},
getLevel : function(level)
{
@ -140,49 +135,42 @@ const navcomponent = Vue.component('navigation', {
return;
}
var newItem = {
var self = this;
self.$root.$data.freeze = true;
self.errors = {title: false, content: false, message: false};
myaxios.post('/api/v1/article',{
'folder_id': this.$el.id,
'item_name': this.newItem,
'type': type,
'url': document.getElementById("path").value,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
};
/* evt.item.classList.add("load"); */
var self = this;
self.$root.$data.freeze = true;
self.errors = {title: false, content: false, message: false};
var url = this.root + '/api/v1/article';
var method = 'POST';
})
.then(function (response) {
sendJson(function(response, httpStatus)
{
if(response)
{
self.$root.$data.freeze = false;
var result = JSON.parse(response);
self.$root.$data.freeze = false;
if(result.errors)
{
publishController.errors.message = result.errors;
}
if(result.url)
{
window.location.replace(result.url);
}
if(result.data)
{
// evt.item.classList.remove("load");
self.$root.$data.items = result.data;
self.newItem = '';
self.showForm = false;
}
if(response.data.url)
{
window.location.replace(response.data.url);
}
}, method, url, newItem );
if(response.data.data)
{
// evt.item.classList.remove("load");
self.$root.$data.items = response.data.data;
self.newItem = '';
self.showForm = false;
}
})
.catch(function (error)
{
if(error.response.data.errors)
{
publishController.errors.message = error.response.data.errors;
}
});
},
}
})
@ -247,45 +235,37 @@ let navi = new Vue({
return;
}
var newItem = {
self = this;
self.freeze = true;
self.errors = {title: false, content: false, message: false};
myaxios.post('/api/v1/baseitem',{
'item_name': this.newItem,
'type': type,
'url': document.getElementById("path").value,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
};
var self = this;
self.freeze = true;
self.errors = {title: false, content: false, message: false};
var url = this.root + '/api/v1/baseitem';
var method = 'POST';
sendJson(function(response, httpStatus)
{
if(response)
{
self.freeze = false;
var result = JSON.parse(response);
})
.then(function (response) {
self.freeze = false;
if(result.errors)
{
publishController.errors.message = result.errors;
}
if(result.url)
{
window.location.replace(result.url);
}
if(result.data)
{
self.items = result.data;
self.newItem = '';
self.showForm = false;
}
if(response.data.url)
{
window.location.replace(response.data.url);
}
}, method, url, newItem );
if(response.data.data)
{
self.items = response.data.data;
self.newItem = '';
self.showForm = false;
}
})
.catch(function (error)
{
publishController.errors.message = error.response.data.errors;
});
},
getNavi: function()
{
@ -297,28 +277,34 @@ let navi = new Vue({
self.errors = {title: false, content: false, message: false};
var activeItem = document.getElementById("path").value;
var url = this.root + '/api/v1/navigation?url=' + activeItem;
var method = 'GET';
sendJson(function(response, httpStatus)
{
if(response)
myaxios.get('/api/v1/navigation',{
params: {
'url': activeItem,
'csrf_name': document.getElementById("csrf_name").value,
'csrf_value': document.getElementById("csrf_value").value,
}
})
.then(function (response) {
self.freeze = false;
if(response.data.data)
{
self.freeze = false;
var result = JSON.parse(response);
if(result.errors)
{
publishController.errors.message = result.errors;
}
if(result.data)
{
self.items = result.data;
self.newItem = '';
self.homepage = result.homepage;
}
self.items = response.data.data;
self.newItem = '';
self.homepage = response.data.homepage;
}
}, method, url, activeItem );
})
.catch(function (error)
{
if(error.response.data.errors)
{
publishController.errors.message = error.response.data.errors;
}
});
}
}
})

View file

@ -2,189 +2,138 @@ let publishController = new Vue({
delimiters: ['${', '}'],
el: '#publishController',
data: {
root: document.getElementById("main").dataset.url,
root: document.getElementById("main").dataset.url,
form: {
title: false,
content: false,
url: document.getElementById("path").value,
csrf_name: document.getElementById("csrf_name").value,
csrf_value: document.getElementById("csrf_value").value,
title: false,
content: false,
url: document.getElementById("path").value,
csrf_name: document.getElementById("csrf_name").value,
csrf_value: document.getElementById("csrf_value").value,
},
errors:{
message: false,
message: false,
},
modalWindow: false,
modalType: false,
draftDisabled: true,
publishDisabled: document.getElementById("publishController").dataset.drafted ? false : true,
deleteDisabled: false,
draftResult: "",
publishResult: "",
discardResult: "",
deleteResult: "",
publishStatus: document.getElementById("publishController").dataset.published ? false : true,
publishLabel: document.getElementById("publishController").dataset.published ? "online" : "offline",
modalWindow: false,
modalType: false,
draftDisabled: true,
publishDisabled: document.getElementById("publishController").dataset.drafted ? false : true,
deleteDisabled: false,
draftResult: "",
publishResult: "",
discardResult: "",
deleteResult: "",
publishStatus: document.getElementById("publishController").dataset.published ? false : true,
publishLabel: document.getElementById("publishController").dataset.published ? "online" : "offline",
publishLabelMobile: document.getElementById("publishController").dataset.published ? "ON" : "OFF",
raw: false,
visual: false,
raw: false,
visual: false,
},
methods: {
publishDraft: function(e){
var self = this;
self.errors.message = false;
editor.errors = {title: false, content: false};
self.publishResult = "load";
self.publishDisabled = "disabled";
handleErrors: function(error){
var url = this.root + '/api/v1/article/publish';
var method = 'POST';
this.form.raw = this.raw;
/* if there are custom error messages */
if(error.response.data.errors)
{
this.publishDisabled = false;
this.publishResult = "fail";
if(error.response.data.errors.message){ this.errors.message = error.response.data.errors.message };
if(error.response.data.errors.title){ editor.errors.title = error.response.data.errors.title[0] };
if(error.response.data.errors.content){ editor.errors.content = error.response.data.errors.content[0] };
}
else if(error.response.status == 400)
{
this.publishDisabled = false;
this.publishResult = "fail";
this.errors.message = "You are probably logged out. Please backup your changes, login and then try again."
}
else if(error.response.status != 200)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "Something went wrong, please refresh the page and try again."
}
},
publishDraft: function(e){
this.errors.message = false;
editor.errors = {title: false, content: false};
this.publishResult = "load";
this.publishDisabled = "disabled";
this.form.raw = this.raw;
if(this.form.raw)
{
this.form.title = editor.form.title;
this.form.content = editor.form.content;
this.form.title = editor.form.title;
this.form.content = editor.form.content;
}
sendJson(function(response, httpStatus)
{
if(httpStatus == 400)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "You are probably logged out. Please backup your changes, login and then try again."
}
else if(response)
{
var result = JSON.parse(response);
if(result.errors)
{
self.publishDisabled = false;
self.publishResult = "fail";
if(result.errors.title){ editor.errors.title = result.errors.title[0] };
if(result.errors.content){ editor.errors.content = result.errors.content[0] };
if(result.errors.message){ self.errors.message = result.errors.message };
}
else
{
if(result.meta)
{
meta.formData = result.meta;
}
self.draftDisabled = "disabled";
self.publishResult = "success";
self.publishStatus = false;
self.publishLabel = "online";
self.publishLabelMobile = "ON";
navi.getNavi();
}
}
else if(httpStatus != 200)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "Something went wrong, please refresh the page and try again."
}
}, method, url, this.form );
},
discardDraft: function(e) {
var self = this;
self.errors.message = false;
editor.errors = {title: false, content: false};
self.discardResult = "load";
self.publishDisabled = "disabled";
myaxios.post('/api/v1/article/publish',self.form)
.then(function (response) {
if(response.data.meta)
{
meta.formData = response.data.meta;
}
var url = self.root + '/api/v1/article/discard';
var method = 'DELETE';
sendJson(function(response, httpStatus)
self.draftDisabled = "disabled";
self.publishResult = "success";
self.publishStatus = false;
self.publishLabel = "online";
self.publishLabelMobile = "ON";
navi.getNavi();
})
.catch(function (error)
{
if(httpStatus == 400)
{
self.publishDisabled = false;
self.discardResult = "fail";
self.errors.message = "You are probably logged out. Please backup your changes, login and then try again."
}
else if(response)
{
var result = JSON.parse(response);
self.handleErrors(error);
});
},
discardDraft: function(e) {
if(result.errors)
{
self.publishDisabled = false;
self.discardResult = "fail";
if(result.errors.title){ editor.errors.title = result.errors.title[0] }
if(result.errors.content){ editor.errors.content = result.errors.content[0] }
if(result.errors.message){ self.errors.message = result.errors.message }
}
else
{
window.location.replace(result.url);
}
}
else if(httpStatus != 200)
{
self.publishDisabled = false;
self.discardResult = "fail";
self.errors.message = "Something went wrong, please refresh the page and try again."
}
this.errors.message = false;
editor.errors = {title: false, content: false};
this.discardResult = "load";
this.publishDisabled = "disabled";
}, method, url, this.form);
myaxios.delete('/api/v1/article/discard',{
data: this.form
})
.then(function (response)
{
window.location.replace(response.data.url);
})
.catch(function (error)
{
self.handleErrors(error);
});
},
saveDraft: function(e){
var self = this;
self.errors.message = false;
editor.errors = {title: false, content: false};
this.errors.message = false;
editor.errors = {title: false, content: false};
self.draftDisabled = "disabled";
self.draftResult = "load";
var url = this.root + '/api/v1/article';
var method = 'PUT';
this.form.title = editor.form.title;
this.form.content = editor.form.content;
sendJson(function(response, httpStatus)
{
if(httpStatus == 400)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "You are probably logged out. Please backup your changes, login and then try again."
}
else if(response)
{
var result = JSON.parse(response);
if(result.errors)
{
self.draftDisabled = false;
self.draftResult = 'fail';
this.draftResult = "load";
this.draftDisabled = "disabled";
if(result.errors.title){ editor.errors.title = result.errors.title[0]; };
if(result.errors.content){ editor.errors.content = result.errors.content[0] };
if(result.errors.message){ self.errors.message = result.errors.message; };
}
else
{
self.draftResult = 'success';
navi.getNavi();
}
}
else if(httpStatus != 200)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "Something went wrong, please refresh the page and try again."
}
}, method, url, this.form );
this.form.title = editor.form.title;
this.form.content = editor.form.content;
var self = this;
myaxios.put('/api/v1/article',self.form)
.then(function (response) {
self.draftResult = 'success';
navi.getNavi();
})
.catch(function (error)
{
self.draftDisabled = false;
self.draftResult = 'fail';
self.handleErrors(error);
});
},
depublishArticle: function(e){
@ -194,98 +143,63 @@ let publishController = new Vue({
return;
}
var self = this;
self.errors.message = false;
editor.errors = {title: false, content: false};
this.errors.message = false;
editor.errors = {title: false, content: false};
self.publishStatus = "disabled";
this.publishStatus = "disabled";
var url = this.root + '/api/v1/article/unpublish';
var method = 'DELETE';
sendJson(function(response, httpStatus)
var self = this;
myaxios.delete('/api/v1/article/unpublish',{
data: self.form
})
.then(function (response)
{
self.publishResult = "";
self.publishLabel = "offline";
self.publishLabelMobile = "OFF";
self.publishDisabled = false;
navi.getNavi();
})
.catch(function (error)
{
if(httpStatus == 400)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "You are probably logged out. Please backup your changes, login and then try again."
}
else if(response)
{
var result = JSON.parse(response);
if(result.errors)
{
self.publishStatus = false;
if(result.errors.message){ self.errors.message = result.errors.message };
}
else
{
self.publishResult = "";
self.publishLabel = "offline";
self.publishLabelMobile = "OFF";
self.publishDisabled = false;
navi.getNavi();
}
}
else if(httpStatus != 200)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "Something went wrong, please refresh the page and try again.";
}
}, method, url, this.form );
self.publishStatus = false;
self.handleErrors(error);
});
},
deleteArticle: function(e){
var self = this;
self.errors.message = false;
editor.errors = {title: false, content: false};
this.errors.message = false;
editor.errors = {title: false, content: false};
self.deleteDisabled = "disabled";
self.deleteResult = "load";
this.deleteDisabled = "disabled";
this.deleteResult = "load";
var url = this.root + '/api/v1/article';
var method = 'DELETE';
var self = this;
sendJson(function(response, httpStatus)
myaxios.delete('/api/v1/article',{
data: self.form
})
.then(function (response)
{
self.modalWindow = false;
if(response.data.url)
{
window.location.replace(response.data.url);
}
})
.catch(function (error)
{
if(httpStatus == 400)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "You are probably logged out. Please backup your changes, login and then try again."
}
else if(response)
{
var result = JSON.parse(response);
self.modalWindow = false;
if(httpStatus != 200)
{
self.publishDisabled = false;
self.publishResult = "fail";
self.errors.message = "Something went wrong, please refresh the page and try again.";
}
if(result.errors)
{
if(result.errors.message){ self.errors.message = result.errors.message };
}
else if(result.url)
{
window.location.replace(result.url);
}
}
}, method, url, this.form );
self.publishStatus = false;
self.handleErrors(error);
});
},
showModal: function(type){
this.modalType = type;
this.modalWindow = true;
this.modalType = type;
this.modalWindow = true;
},
hideModal: function(type){
this.modalWindow = false;
this.modalType = false;
this.modalWindow = false;
this.modalType = false;
},
}
});

File diff suppressed because one or more lines are too long

View file

@ -16,7 +16,7 @@
<link rel="apple-touch-icon" sizes="144x144" href="{{ base_url }}/system/author/img/favicon-144.png" />
<link rel="apple-touch-icon" sizes="180x180" href="{{ base_url }}/system/author/img/favicon-180.png" />
<link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" />
<!-- <link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" /> -->
<link rel="stylesheet" href="{{ base_url }}/system/author/css/tachyons.min.css?20201130" />
<link rel="stylesheet" href="{{ base_url }}/system/author/css/style.css?20201130" />

View file

@ -17,7 +17,7 @@
<link rel="apple-touch-icon" sizes="144x144" href="{{ base_url }}/system/author/img/favicon-144.png" />
<link rel="apple-touch-icon" sizes="180x180" href="{{ base_url }}/system/author/img/favicon-180.png" />
<link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" />
<!-- <link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" /> -->
<link rel="stylesheet" href="{{ base_url }}/system/author/css/style.css?20201130" />
{{ assets.renderCSS() }}

View file

@ -16,7 +16,7 @@
<link rel="apple-touch-icon" sizes="144x144" href="{{ base_url }}/system/author/img/favicon-144.png" />
<link rel="apple-touch-icon" sizes="180x180" href="{{ base_url }}/system/author/img/favicon-180.png" />
<link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" />
<!-- <link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" /> -->
<link rel="stylesheet" href="{{ base_url }}/system/author/css/style.css?20201130" />
</head>

View file

@ -16,7 +16,7 @@
<link rel="apple-touch-icon" sizes="144x144" href="{{ base_url }}/system/author/img/favicon-144.png" />
<link rel="apple-touch-icon" sizes="180x180" href="{{ base_url }}/system/author/img/favicon-180.png" />
<link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" />
<!-- <link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" /> -->
<link rel="stylesheet" href="{{ base_url }}/system/author/css/tachyons.min.css" />
<link rel="stylesheet" href="{{ base_url }}/system/author/css/style.css?20201130" />

View file

@ -16,7 +16,7 @@
<link rel="apple-touch-icon" sizes="144x144" href="{{ base_url }}/system/author/img/favicon-144.png" />
<link rel="apple-touch-icon" sizes="180x180" href="{{ base_url }}/system/author/img/favicon-180.png" />
<link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" />
<!-- <link rel="stylesheet" href="{{ base_url }}/system/author/css/normalize.css" /> -->
<link rel="stylesheet" href="{{ base_url }}/system/author/css/style.css?20201130" />
{{ assets.renderCSS() }}

View file

@ -2,7 +2,7 @@
{% block title %}{{ __('User') }}{% endblock %}
{% block content %}
<div class="formWrapper">
<form id="userform" method="POST" action="{{ path_for('user.update') }}" enctype="multipart/form-data">
@ -22,13 +22,13 @@
<fieldset class="subfield">
<legend>{{ field.legend }}</legend>
{% for field in field.fields %}
{% include '/partials/fields.twig' with { 'settings': usersettings, 'object' : 'users', 'itemName' : 'user', 'class' : 'large' } %}
{% include '/partials/fields.twig' with { 'settings': usersettings, 'object' : 'users', 'itemName' : 'user', 'class' : 'large', 'errors': errors } %}
{% endfor %}
</fieldset>
{% else %}
{% include '/partials/fields.twig' with { 'settings': usersettings, 'object' : 'users', 'itemName' : 'user', 'class' : 'large' } %}
{% include '/partials/fields.twig' with { 'settings': usersettings, 'object' : 'users', 'itemName' : 'user', 'class' : 'large', 'errors': errors } %}
{% endif %}