|
var contacts_button2 = O.plugin("contacts_button2", { |
|
// Called when an object's page is requested |
|
hObjectDisplay: function(response, object) { |
|
// Build a list of menu items, which depend on the type of the object being displayed. |
|
// Menu items link to an object editor for a new object which links to the current object. |
|
// Only add a menu item if the user has permission to create the proposed object. |
|
var menuItems = []; |
|
if((object.isKindOf(SCHEMA.O_TYPE_ORGANISATION) || object.isKindOf(SCHEMA.O_TYPE_PERSON)) |
|
&& O.currentUser.hasPermissionToCreateObjectOfType(SCHEMA.O_TYPE_CONTACT_NOTE)) { |
|
menuItems.push(['/do/contacts/add_note/'+object.ref, 'Add Contact note']) |
|
} |
|
if(object.isKindOf(SCHEMA.O_TYPE_ORGANISATION) && O.currentUser.hasPermissionToCreateObjectOfType(SCHEMA.O_TYPE_PERSON)) { |
|
menuItems.push(['/do/contacts/add_person/'+object.ref, 'Add Person']) |
|
} |
|
if(menuItems.length > 0) { |
|
// Create a button at the top of the page with label 'Contacts', which displays the menu items when clicked. |
|
response.buttons["Contacts"] = menuItems; |
|
} |
|
} |
|
}); |
|
|
|
// Declare that the plugin responds to a URL (which must be below a root URL set in plugin.json) |
|
contacts_button2.respond("GET", "/do/contacts/add_note", [ |
|
// Define the sources of the values of the arguments to the handler function |
|
{pathElement:0, as:"object"} // if the user doesn't have permission to read this object, the handler won't be called |
|
], function(E, object) { |
|
var user = O.currentUser, // details about the currently logged in user |
|
templateObject = O.object(); // make a blank object to act as a template |
|
// Set the type of the object, so the editor knows what fields to display |
|
// The append* functions are automatically generated from the schema created in the system management web interface. |
|
templateObject.appendType(SCHEMA.O_TYPE_CONTACT_NOTE); |
|
// Add a link to the original object in the participant field |
|
templateObject.appendParticipant(object); |
|
// If the user has a record in the system, add them as a participant as well |
|
if(user != null && user.ref != null) { |
|
templateObject.appendParticipant(user.ref); |
|
} |
|
// Copy the "works for" fields from the original object, so the organisation is linked from the contact note |
|
object.everyWorksFor(function(value,desc,qualifier) { |
|
templateObject.appendParticipant(value); |
|
}); |
|
// Render a standard template to show the editor for the new object |
|
E.render({ |
|
// Pass the templateObject to the std:new_object_editor template |
|
templateObject:templateObject, |
|
// Properties for the standard page chrome |
|
pageTitle:'Add note to '+object.firstTitle(), // HTML <title> and <h1> |
|
backLink:object.url(), backLinkText:'Cancel' // Add a link in the top left back to the original object |
|
}, "std:new_object_editor"); |
|
}); |
|
|
|
contacts_button2.respond("GET", "/do/contacts/add_person", [ |
|
{pathElement:0, as:"object"} |
|
], function(E, object) { |
|
var templateObject = O.object(); |
|
templateObject.appendType(SCHEMA.O_TYPE_PERSON); |
|
templateObject.appendWorksFor(object); |
|
E.render({ |
|
templateObject:templateObject, |
|
pageTitle:'Add person to '+object.firstTitle(), |
|
backLink:object.url(), backLinkText:'Cancel' |
|
}, "std:new_object_editor"); |
|
}); |