mirror of
https://github.com/documize/community.git
synced 2025-07-25 08:09:43 +02:00
moved emberjs to gui folder
This commit is contained in:
parent
6a18d18f91
commit
dc49dbbeff
999 changed files with 677 additions and 651 deletions
135
gui/app/services/section.js
Normal file
135
gui/app/services/section.js
Normal file
|
@ -0,0 +1,135 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
import Ember from 'ember';
|
||||
import BaseService from '../services/base';
|
||||
|
||||
const {
|
||||
inject: { service }
|
||||
} = Ember;
|
||||
|
||||
export default BaseService.extend({
|
||||
sessionService: service('session'),
|
||||
ajax: service(),
|
||||
store: service(),
|
||||
|
||||
// Returns all available sections.
|
||||
getAll() {
|
||||
return this.get('ajax').request(`sections`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('section', obj);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
|
||||
return data;
|
||||
});
|
||||
},
|
||||
|
||||
// Requests data from the specified section handler, passing the method and document ID
|
||||
// and POST payload.
|
||||
fetch(page, method, data) {
|
||||
let documentId = page.get('documentId');
|
||||
let section = page.get('contentType');
|
||||
let url = `sections?documentID=${documentId}§ion=${section}&method=${method}`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json"
|
||||
});
|
||||
},
|
||||
|
||||
// Did any dynamic sections change? Fetch and send up for rendering?
|
||||
refresh(documentId) {
|
||||
let url = `sections/refresh?documentID=${documentId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let pages = [];
|
||||
|
||||
if (is.not.null(response) && is.array(response) && response.length > 0) {
|
||||
pages = response.map((page) => {
|
||||
let data = this.get('store').normalize('page', page);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
}
|
||||
|
||||
return pages;
|
||||
}).catch((/*error*/) => {
|
||||
// we ignore any error to cater for anon users who don't
|
||||
// have permissions to perform refresh
|
||||
});
|
||||
},
|
||||
|
||||
/**************************************************
|
||||
* Reusable Content Blocks
|
||||
**************************************************/
|
||||
|
||||
// Save new reusable content block.
|
||||
addBlock(payload) {
|
||||
let url = `sections/blocks`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json'
|
||||
}).then((response) => {
|
||||
let data = this.get('store').normalize('block', response);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
},
|
||||
|
||||
// Returns reusable content block.
|
||||
getBlock(blockId) {
|
||||
return this.get('ajax').request(`sections/blocks/${blockId}`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = this.get('store').normalize('block', response);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
},
|
||||
|
||||
// Returns all available reusable content block for section.
|
||||
getSpaceBlocks(folderId) {
|
||||
return this.get('ajax').request(`sections/blocks/space/${folderId}`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('block', obj);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
|
||||
return data;
|
||||
});
|
||||
},
|
||||
|
||||
// Returns reusable content block.
|
||||
updateBlock(block) {
|
||||
return this.get('ajax').request(`sections/blocks/${block.id}`, {
|
||||
method: 'PUT',
|
||||
data: JSON.stringify(block)
|
||||
});
|
||||
},
|
||||
|
||||
// Removes specified reusable content block.
|
||||
deleteBlock: function (blockId) {
|
||||
let url = `sections/blocks/${blockId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue