Sugarcrm : How to rewrite a document URL - templates

My version :
SugarCRM CE 6.5.2 running on linux
What I want to do :
I've customized the Documents module in "custom/modules/Documents" by writing several logic hooks.
These logic hooks creates new folders in "ressources/" which is my new upload folder. (I've change the 'upload_dir' from "./upload" into "./ressources" in the config.php)
This is done through a custom field created in studio named "folder_name"
And then, the logic hooks cut and paste the document uploaded into this new folder.
What is my problem
So, with all of this, my download url in Edit, Detail and Revisions Subpanel Views is false. I would like to change it to the right folder, like, for example adding a folder parameter in the url
like this :
/index.php?entryPoint=download&folder=Images&id=idDoc&type=Documents
I tried to change the a href link in EditView.tpl or DetailView.tpl, (like )
but it didn't work since they were located in my cache/modules/Documents folder and were overriding when i did a quick repair.
So I copies/pasted the DetailView.tpl and the EditView.tpl into custom/modules/Documents/tpls and tried to override the view.edit.php and the view.detail.php to link the customized templates, but it did not work.
code :
<?php
require_once('include/MVC/View/views/view.detail.php');
class DocumentsViewDetail extends ViewDetail {
function DocumentsViewDetail() {
parent::ViewDetail();
}
function display() {
parent::display();
}
function detailViewProcess() {
$this->processSearchForm();
$this->lv->searchColumns = $this->searchForm->searchColumns;
if (!$this->headers)
return;
if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) {
//here we are overriding with your custom template
$this->lv->setup($this->seed, 'custom/modules/Documents/tpls/DetailView.tpl', $this->where, $this->params);
echo $this->lv->display();
}
}
}
?>
Do you have any idea why this doesn't work?
Do you have any idea on how i could rewrite my URLS or override the Edit, Revisions SubPanel and Details Views?
Please answer, this is URGENT
Thank you by advance.

Try adding the folder parameter to the variable $file_url inside the method fill_in_additional_detail_fields() in modules/Documents/Document.php.
[Edited]
EditView: include/SugarFields/Fields/File/EditView.tpl
DetailView: include/SugarFields/Fields/File/DetailView.tpl
<a href="index.php?entryPoint=download&id={$fields.{{$vardef.fileId}}.value}&type={{$vardef.linkModule}}&folder=test" ...
ListView: include/SugarFields/Fields/File/ListView.tpl
<a href="index.php?entryPoint=download&id={$parentFieldArray.ID}&type={$displayParams.module}{$vardef.displayParams.module}&folder=test" ...

So, thanks to #air4x, i did answer my trouble : overriding the DetailView.tpl
To make it upgrade-safe, i copies it from
include/SugarFields/Fields/File/DetailView.tpl
to
custom/include/SugarFields/Fields/File/DetailView.tpl
It works!
BUT there is a big trouble coming...
explanations :
1] I create a new Document, uploading image01 to Folder01. Save. Database ok. in DetailView the folder name is "Folder01" and the link '//Folder01/image01_id' works.
2] I create another new Document, uploading image02 to Folder02. Save. Databse ok. BUT in DetailView the folder's name is not "Folder02" but "Folder01". AND the link is //Folder01/image02_id so it doesn't work, because in database or in my folders, the file is still in Folder02.
Here is my custom/include/SugarFields/Fields/File/DetailView.tpl code :
//BEGIN the code i modified
<span class="sugar_field" id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}">
<a href="ressources/{$fields.folder_name_c.value}/{$fields.{{$vardef.fileId}}.value}" class="tabDetailViewDFLink" target='_blank'>{{sugarvar key='value'}}</a>
</span>
//END the code i modified
{{if isset($vardef) && isset($vardef.allowEapm) && $vardef.allowEapm}}
{if isset($fields.{{$vardef.docType}}) && !empty($fields.{{$vardef.docType}}.value) && $fields.{{$vardef.docType}}.value != 'SugarCRM' && !empty($fields.{{$vardef.docUrl}}.value) }
{capture name=imageNameCapture assign=imageName}
{$fields.{{$vardef.docType}}.value}_image_inline.png
{/capture}
{sugar_getimage name=$imageName alt=$imageName other_attributes='border="0" '}
{/if}
{{/if}}
{{if !empty($displayParams.enableConnectors)}}
{{sugarvar_connector view='DetailView'}}
{{/if}}
I really don't know why my $fields.folder_name_c.value stay from the first document and replace the one in the second document...
Do you know how i could do a sql query in my EditView.tpl to change it and have the right value?
Please, i really need help.
Thank you
(ps : #air4x, thanks a LOT, even if i have another trouble, that showed me hox to override EditView. THANK YOU! )

Related

Changes to the code - I do not see on the site

Got a question. For example, I change the code on the page
/catalog/view/theme/nextdef/template/extension/module/latest.twig
, or rather add a handler to the button:
<i class = "fa fa-heart" onclick = "window.dataLayer = window.dataLayer || [];
dataLayer.push ({'event': 'heart'}); "> </i> </button>
But when you click on this element, there are no changes. If you look at the page code, then it is also not updated. Although I write the cache and update the Disable cache inside the browser too, and still no changes ... I would be grateful if you help. thank
The problem was that the template editor had a history of this page. And there was no code. Apparently, he referred to her. I did not know that opencart prioritizes history compared to server files.

Joomla jgrid.published not working

I got a code like this in joomla backend.
<td class="center"><?php echo JHtml::_('jgrid.published', $item->published, $i, 'products.', TRUE, 'cb'); ?></td>
The publish function work correctly sending me to my controller products and method publish. However, the unpublish was not correct it send me to publish method instead of unpublish method, even though the anchor tag still show correctly like this <a class="jgrid" href="javascript:void(0);" onclick="return listItemTask('cb7','products.unpublish')" title="Unpublish Item">
anyone got any idea about it?
This is a really really old question, but I just came across the same problem myself.
It looks like they are saving space by using the same method (which you pointed out) "publish" for both publish and unpublish functionality.
The problem is that in the method it checks how to set the state, but does so based on the "task" which for some reason does not strip the context of the controller out of the post data. So... instead of looking for...
if( $post['task'] == 'unpublish' ){
...you should be looking for...
public function publish(){
$post = JRequest::get('post');
if( $post['task'] == 'items.unpublish'){
$state = 0;
}else{
$state = 1;
}
Notice how the task we are looking for is items.unpublish (items being your controller) instead of just unpublish.
I know this is probably way to late, but hopefully it helps someone.

backbone/marionette attaching HTML into a region

I'm beginning to use Marionette within an existing backbone application. I've got some HTML which I want to append into a region. In pure backbone, I could just do this.$el.append(html_code) and that was all. As far as I can see, marionette regions allow only to operate on views (which have to implement the render method). Calling append on marionette region throws 'undefined method' errors.
Is it possible to attach plain HTML to a marionette region?
No, it's not possible to inject plain html into a Marionette.Region.
Theoretically you could access a regions DOM element with someRegion.el or someRegion.getElement(), but this must be done after rendering (which at least isn't possible inside a Marionette.View with standard behaviour).
But you can achieve the desired result by using a specially crafted Marionette.ItemView:
#someRegion.show(new Marionette.ItemView({template: '<h1>gach</h1>'}));
You maybe also should have a look at Marionette.Renderer .
a Marionette ItemView will look for a template and will call render on that template, so when you show the view in the region the html will be displayed just fine with out the need of you defining a render method.
MyImtemView = Backbone.Marionete.ItemView.extend({
template : "#myTemplate"
});
var myItemView = new MyItemView();
myLayout.aregion.show(myItemview);
this should work if you save your html in a template like this
`<script id="myTemplate" type="text/template">
<div><p>your html<p>
</div>
`
EDIT
you can also declare a render function in your view in case you need to generate and modify your html like this.
MyImtemView = Backbone.Marionete.ItemView.extend({
template : "#myTemplate",
render : function (){
this.$el.append(HMTL); //so here you work your html as you need
}
});
var myItemView = new MyItemView();
myLayout.aregion.show(myItemview); //the render function of your view will be called here
I ran into the same problem and tried the answers explained here, but I'm also using require.js and kept getting an error for the #my_view template not being found. If anyone can clarify where does Marionette look up the templates by default, that would be great.
Instead, I solved it by using the text.js plugin for underscore.js. This way you actually can use a plain html file as the template, without the need for nesting it in a script tag. Here's how I did it.
define(['backbone', 'underscore', 'marionette', 'text!tmpl/my_view.html'], function(Backbone, _, Marionette, view_t){
var MyView = Backbone.Marionette.ItemView.extend({
template : function(serialized_model) {
//define your parameters here
param1 = erialized_model.param1;
return _.template(view_t)({
param1: param1
});
}
});
return MyView;
});
I placed the text.js plugin in the same lib directory as all my other js libraries and my main.js for require declares the path to the templates as
'tmpl': '../../templates',
My project structure looks like this
root
index.html
js
main.js
app
App.js
views
MyView.js
lib
require.js
text.js
backbone.js
underscore.js
jquery.js
backbone.marionette.js
templates
my_view.html
My template 'my_view.html' simply looks like this.
<h1>THIS IS FROM THE TEMPLATE!!!</h1>
Worked perfectly. I hope you find it useful.
Using a view
var myHtml = '<h1>Hello world!</h1>';
var myView = new Marionette.ItemView({template: _.constant(myHtml)});
myRegion.show(myView);
Marionette.Renderer.render takes either a function or the name of a template (source code). _.constant creates a function that returns the passed-in parameter.
Attaching HTML
Alternately, the docs for Marionette.Region mention overriding the attachHtml method, see Set How View's el Is Attached.

webpy template multiple inheritance, possible?

I want to divide index page into small stand alone .html parts like:
up_bar.html:
<p><center>
<h1>home</h1>
Menu: home add import
down_bar.html:
<a href="/path/.."/>
and so on.
Now, to build a new page is it possible to embed those pieces into other page using default webpy templator?
Maybe something like that?:
in admin.html:
$def with(some_parameters):
<title>Admin panel</title>
$include('side_bar.html')
... body stuff ...
$include('down_bar.html')
A basic but good introduction to template inheritance can be found here: http://webpy.org/cookbook/layout_template
Found an answer here: http://groups.google.com/group/webpy/msg/ea6da02dfb9eedc4?dmode=source
Some explanation will be great.
I did this to my code
def GET(self,*args):
param= {'name':'jackie'}
view = web.template.frender("views/someview.html")
content = view(**param)
layout = web.template.frender("views/index.html")
return layout(content=content)
now you just insert $:content in index.html

tag url template django doesn't work

I trying to implement the url template tag into my project.
I have a button that allows the user to save the data he is seeing.
So the url of this button is this:
(2)url(r'^nameviews/download/$', 'my.path.is.this.to.download' name="load"),
template:
Download
the url of the page that shows the information, and where the button is located is:
(1)(r'^nameviews/$', path.to.page),
but when I tried to click on the button (it should appear the url 2)it doesn't open the file with the data but instead gives me the same url that the main page (1)
the html validator gives me a error on the
<a href="">
It seems it doesn't recognize the url tag.
Anyone has any idea?
Resolved! I didn't really understood what's happen because I didn't change much but should have been some silly mistake.
Sorry!
Thanks any way :)
EDIT
Be careful with the order of the urls. At urls.py try this order:
url(r'^nameviews/download/$', name_of_view, name="load"),
url(r'^nameviews/$', name_of_view, name="first page"),
name_of_view is equal if the view is the same