Author Topic: Is there a way to navigate within Feng Office by URL?  (Read 4276 times)

allenlook

  • Volunteer Moderator
  • Sr. Member
  • ****
  • Posts: 312
    • MSN Messenger - sii_lookal@hotmail.com
    • View Profile
    • SI Group, Inc.
Is there a way to navigate within Feng Office by URL?
« on: March 04, 2010, 05:14:45 pm »
Forgive me for what may be a stupid question, but I am new to AJAX and "stuff".

In developing the Gantt chart feature, I find myself wanting to have a place to click to bring up a new e-mail to the task Resource (which is now working) and also a place to click to bring up that task directly in Feng Office, perhaps to make changes to it.

Of course the URL for Feng Office does not change when you navigate through it, and I'm not aware of another way to figure out how to "direct" Feng Office to go somewhere simply by sending it a URL or some other command.

Is there a way to do so?  It would be handy in more ways than one!
I am a volunteer moderator.  Any statements, opinions or observations I contribute are solely mine and are not necessarily shared by the makers of Feng Office.

ignacio

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
Re: Is there a way to navigate within Feng Office by URL?
« Reply #1 on: March 18, 2010, 04:34:30 pm »
We have been planning for a long time, but haven't implemented it, to make URLs reflect where you are standing, by keeping all the information after the hash (#). This will also allow the browser's back and forward buttons to work correctly, taking you back and forward through Feng Office, and also refreshing the browser will leave you where you were standing.

But for the moment, you can open URL's with javascript, with the og.openLink function. This function expects an URL as the first parameter and a config javascript object as the second parameter. In the config object you can tell on which panel you want to load the response by specifying the 'caller' property equal to the panel's id, or you can prevent the response from being loaded at all by specifying the 'preventPanelLoad' property as true. You can also configure a function to be called after the request finishes by specifying the 'callback' argument. The function you specify in the callback argument will be passed the following arguments: success (whether the request finished successfully), data (the response's content), options (the config object passed to the openLink function).

I think it will be easier to get with some examples, so here are some examples:

Code: [Select]
// load the readme.txt file in the Contact's tab
og.openLink('readme.txt', {
    caller: 'contacts-panel'
});

Code: [Select]
// load the readme.txt file and do something with it instead of loading it into a panel
og.openLink('readme.txt', {
    preventPanelLoad: true,
    someObject: {name: 'sample object'},
    callback: function(success, data, options) {
        // og.openLink expects the response to be a javascript object (JSON), since this is not JSON but plain text, 'success' will be false
        alert(success);
        // alert the readme file
        alert(data);
        // you can access 'someObject' from the options parameter
        alert(options.someObject.name);
    }
});

Code: [Select]
// load the dashboard into the contact's panel
// you can use the og.getUrl function to generate the correct URL
// or just put the actual URL: 'index.php?c=dashboard&a=index
og.openLink(og.getUrl('dashboard', 'index'), {
    caller: 'contacts-panel'
});

Code: [Select]
// get the latest 5 files and do something with them
// first we generate the URL to fetch the latest 5 files
var url = og.getUrl('files', 'list_files', {
    start: 0,
    limit: 5}
);
// then we use openLink to load it (this URL returns a javascript object)
og.openLink(url, {
    onSuccess: function(data) {
        // the 'onSuccess' property works like 'callback' except it is only invoked when the requests completes successfully (and returns a javascript object)
        alert(data.totalCount  + " files in the system");
        alert(data.files.length + " files fetched");
        for (var i=0; i < data.files.length; i++) {
            alert(data.files[i].name);
        }
    }
});

Some notes about these examples:

- openLink usually expects a javascript object encoded in JSON as the response of a request. If it doesn't get a JSON object it will pass the callback function a 'success' value of false. This object is expected to have some properties:
    - errorCode: specifies an error code. 0 is for 'no error', another value means there was an error in the request and an error message will be shown, and the request will not be considered successful.
    - errorMessage: Message to show in case errorCode is different than 0
    - current: What to load in the current panel (or the panel specified by the 'caller' argument). If this is empty then nothing will be loaded.

- All links contained in responses loaded by Feng Office are automatically converted to og.openLink calls, unless they contain a 'target' that starts with an underscore, like '_self' or '_blank' or unless they are javascript: links or mailto: links. So for example, the following link:
Code: [Select]
<a href="http://example.com">Example</a>will actually be opened like this when clicked:
Code: [Select]
og.openLink('http://example.com')The link's target value will be used as the 'caller' in the openLink call, so:
Code: [Select]
<a href="http://example.com" target="contacts-panel">Example</a>Will turn into:
Code: [Select]
og.openLink('http://example.com', {caller:'contacts-panel'})
- You could also call 'openLink' from a link like this:
Code: [Select]
<a href="javascript:og.openLink('http://example.com')">Click me!</a>

Ok, I guess it's a lot to digest so if you need any further help or if anything is not clear let me know.

Best regards.

allenlook

  • Volunteer Moderator
  • Sr. Member
  • ****
  • Posts: 312
    • MSN Messenger - sii_lookal@hotmail.com
    • View Profile
    • SI Group, Inc.
Re: Is there a way to navigate within Feng Office by URL?
« Reply #2 on: March 18, 2010, 04:51:22 pm »
That's fantastic!  Thank you for the response :)  As soon as I nail this Gantt sorting issue, I'll try your recommendation!
I am a volunteer moderator.  Any statements, opinions or observations I contribute are solely mine and are not necessarily shared by the makers of Feng Office.

allenlook

  • Volunteer Moderator
  • Sr. Member
  • ****
  • Posts: 312
    • MSN Messenger - sii_lookal@hotmail.com
    • View Profile
    • SI Group, Inc.
Re: Is there a way to navigate within Feng Office by URL?
« Reply #3 on: March 18, 2010, 05:11:24 pm »
Hmmm, OK so I am opening URLs that are mailto: URLs, and that is working just fine...

Is there any URL specific to a task or milestone that I could add to each name in the Gantt, or is that still impossible?  I'd be looking for something like:

og.openLink('object_id', { caller: 'tasks-panel' });

... where 'object_id' is a URL containing either the 'id' field from og_project_milestones or og_project_tasks.
« Last Edit: March 18, 2010, 05:14:23 pm by allenlook »
I am a volunteer moderator.  Any statements, opinions or observations I contribute are solely mine and are not necessarily shared by the makers of Feng Office.

ignacio

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
Re: Is there a way to navigate within Feng Office by URL?
« Reply #4 on: March 22, 2010, 09:05:25 pm »
Hi, that would be:

for tasks:
og.openLink(og.getUrl('task', 'view_task', {id: THE_ID}))

(if you don't specify the caller it will be the current panel. Change "THE_ID" for the actual ID)

for milestones:
og.openLink(og.getUrl('milestone', 'view', {id: THE_ID}))