-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #618 from plone/metatoaster-structure-master
WIP: Making structure pattern more flexible to customization options
- Loading branch information
Showing
17 changed files
with
2,613 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
define([ | ||
], function() { | ||
'use strict'; | ||
|
||
var menuOptions = { | ||
'cutItem': [ | ||
'mockup-patterns-structure-url/js/actions', | ||
'cutClicked', | ||
'#', | ||
'Cut', | ||
], | ||
'copyItem': [ | ||
'mockup-patterns-structure-url/js/actions', | ||
'copyClicked', | ||
'#', | ||
'Copy' | ||
], | ||
'pasteItem': [ | ||
'mockup-patterns-structure-url/js/actions', | ||
'pasteClicked', | ||
'#', | ||
'Paste' | ||
], | ||
'move-top': [ | ||
'mockup-patterns-structure-url/js/actions', | ||
'moveTopClicked', | ||
'#', | ||
'Move to top of folder' | ||
], | ||
'move-bottom': [ | ||
'mockup-patterns-structure-url/js/actions', | ||
'moveBottomClicked', | ||
'#', | ||
'Move to bottom of folder' | ||
], | ||
'set-default-page': [ | ||
'mockup-patterns-structure-url/js/actions', | ||
'setDefaultPageClicked', | ||
'#', | ||
'Set as default page' | ||
], | ||
'selectAll': [ | ||
'mockup-patterns-structure-url/js/actions', | ||
'selectAll', | ||
'#', | ||
'Select all contained items' | ||
], | ||
'openItem': [ | ||
'mockup-patterns-structure-url/js/navigation', | ||
'openClicked', | ||
'#', | ||
'Open' | ||
], | ||
'editItem': [ | ||
'mockup-patterns-structure-url/js/navigation', | ||
'editClicked', | ||
'#', | ||
'Edit' | ||
], | ||
}; | ||
|
||
var ActionMenu = function(menu) { | ||
// If an explicit menu was specified as an option to AppView, this | ||
// constructor will not override that. | ||
if (menu.menuOptions !== null) { | ||
return menu.menuOptions; | ||
} | ||
|
||
var result = {}; | ||
result['cutItem'] = menuOptions['cutItem']; | ||
result['copyItem'] = menuOptions['copyItem']; | ||
if (menu.app.pasteAllowed && menu.model.attributes.is_folderish) { | ||
result['pasteItem'] = menuOptions['pasteItem']; | ||
} | ||
if (!menu.app.inQueryMode() && menu.options.canMove !== false) { | ||
result['move-top'] = menuOptions['move-top']; | ||
result['move-bottom'] = menuOptions['move-bottom']; | ||
} | ||
if (!menu.model.attributes.is_folderish && menu.app.setDefaultPageUrl) { | ||
result['set-default-page'] = menuOptions['set-default-page']; | ||
} | ||
if (menu.model.attributes.is_folderish) { | ||
result['selectAll'] = menuOptions['selectAll']; | ||
} | ||
if (menu.options.header) { | ||
result['openItem'] = menuOptions['openItem']; | ||
} | ||
result['editItem'] = menuOptions['editItem']; | ||
return result; | ||
}; | ||
|
||
return ActionMenu; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
define([ | ||
'jquery', | ||
'underscore', | ||
'backbone', | ||
'mockup-patterns-structure-url/js/models/result', | ||
'mockup-utils', | ||
'translate', | ||
], function($, _, Backbone, Result, utils, _t) { | ||
'use strict'; | ||
|
||
// use a more primative class than Backbone.Model? | ||
var Actions = Backbone.Model.extend({ | ||
initialize: function(options) { | ||
this.options = options; | ||
this.app = options.app; | ||
this.model = options.model; | ||
this.selectedCollection = this.app.selectedCollection; | ||
}, | ||
selectAll: function(e){ | ||
// This implementation is very specific to the default collection | ||
// with the reliance on its queryParser and queryHelper. Custom | ||
// collection (Backbone.Paginator.requestPager implementation) | ||
// will have to come up with their own action for this. | ||
e.preventDefault(); | ||
var self = this; | ||
var page = 1; | ||
var count = 0; | ||
var getPage = function(){ | ||
self.app.loading.show(); | ||
$.ajax({ | ||
url: self.app.collection.url, | ||
type: 'GET', | ||
dataType: 'json', | ||
data: { | ||
query: self.app.collection.queryParser({ | ||
searchPath: self.model.attributes.path | ||
}), | ||
batch: JSON.stringify({ | ||
page: page, | ||
size: 100 | ||
}), | ||
attributes: JSON.stringify( | ||
self.app.collection.queryHelper.options.attributes) | ||
} | ||
}).done(function(data){ | ||
var items = self.app.collection.parse(data, count); | ||
count += items.length; | ||
_.each(items, function(item){ | ||
self.app.selectedCollection.add(new Result(item)); | ||
}); | ||
page += 1; | ||
if(data.total > count){ | ||
getPage(); | ||
}else{ | ||
self.app.loading.hide(); | ||
self.app.tableView.render(); | ||
} | ||
}); | ||
}; | ||
getPage(); | ||
}, | ||
|
||
doAction: function(buttonName, successMsg, failMsg){ | ||
var self = this; | ||
$.ajax({ | ||
url: self.app.buttons.get(buttonName).options.url, | ||
data: { | ||
selection: JSON.stringify([self.model.attributes.UID]), | ||
folder: self.model.attributes.path, | ||
_authenticator: utils.getAuthenticator() | ||
}, | ||
dataType: 'json', | ||
type: 'POST' | ||
}).done(function(data){ | ||
if(data.status === 'success'){ | ||
self.app.setStatus(_t(successMsg + ' "' + self.model.attributes.Title + '"')); | ||
self.app.collection.pager(); | ||
self.app.updateButtons(); | ||
}else{ | ||
self.app.setStatus(_t('Error ' + failMsg + ' "' + self.model.attributes.Title + '"')); | ||
} | ||
}); | ||
}, | ||
|
||
cutClicked: function(e) { | ||
var self = this; | ||
e.preventDefault(); | ||
self.doAction('cut', _t('Cut'), _t('cutting')); | ||
}, | ||
copyClicked: function(e) { | ||
var self = this; | ||
e.preventDefault(); | ||
self.doAction('copy', _t('Copied'), _t('copying')); | ||
}, | ||
pasteClicked: function(e) { | ||
var self = this; | ||
e.preventDefault(); | ||
self.doAction('paste', _t('Pasted into'), _t('Error pasting into')); | ||
}, | ||
moveTopClicked: function(e) { | ||
e.preventDefault(); | ||
this.app.moveItem(this.model.attributes.id, 'top'); | ||
}, | ||
moveBottomClicked: function(e) { | ||
e.preventDefault(); | ||
this.app.moveItem(this.model.attributes.id, 'bottom'); | ||
}, | ||
setDefaultPageClicked: function(e) { | ||
e.preventDefault(); | ||
var self = this; | ||
$.ajax({ | ||
url: self.app.getAjaxUrl(self.app.setDefaultPageUrl), | ||
type: 'POST', | ||
data: { | ||
'_authenticator': $('[name="_authenticator"]').val(), | ||
'id': this.model.attributes.id | ||
}, | ||
success: function(data) { | ||
self.app.ajaxSuccessResponse.apply(self.app, [data]); | ||
}, | ||
error: function(data) { | ||
self.app.ajaxErrorResponse.apply(self.app, [data]); | ||
} | ||
}); | ||
}, | ||
}); | ||
|
||
return Actions; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.