Project

General

Profile

Create Plugin for jstoolbar modification?

Added by Andrew Leaf over 14 years ago

Is there a way to create a plugin that replaced the default JSToolBar and contains a modified jstoolbar.css, jstoolbar.js and textile.js?

We've modified ours so a button inserts a predefined template into the description field, however, we've modified the original code.

Is there a way to overwrite or amend JSToolBar using a plugin? I'd like this to be more portable for when we upgrade to newer versions of Redmine.

See attached file for example of implementation.

Andrew Leaf
QA Manager
Destineer


Replies (13)

RE: Create Plugin for jstoolbar modification? - Added by Andrew Leaf over 14 years ago

Okay - I think I made some progress here, but I'm looking for input. Eric Davis was kind enough to point me in the right direction, and I think I went there correctly, however, I'm unable to get my custom toolbar to load.

Here's the code of my init.rb

require 'redmine'

Redmine::Plugin.register :redmine_toolbar do
  name 'Redmine Toolbar plugin'
  author 'Andrew Leaf'
  description 'This is a plugin for Redmine'
  version '0.0.1'
end

class RedmineToolbarHookListener < Redmine::Hook::ViewListener
   # Adds javascript and stylesheet tags
   def view_layouts_base_html_head(context)
     javascript_include_tag('textile.js','jstoolbar.js', :plugin => :redmine_toolbar) +
     stylesheet_link_tag('jstoolbar.css', :plugin => :redmine_toolbar)
end
end

I've put the referenced textile.js, jstoolbar.js, and jstoolbar.css in the appropriate ./app/assets folder, but I'm not seeing my toolbar pop up. Must I rename the above javascript to override the default? Is there a controller I must set?

Any thoughts?

Cheers,

Andrew Leaf
QA Manager
Destineer

RE: Create Plugin for jstoolbar modification? - Added by Andrew Leaf over 14 years ago

Also, is there a specific view I should be modifying? I was a tad confused by the Plugin Tutorial and internals page.

Please forgive me, I'm new to .js and .rb.

Thanks,

Andrew

RE: Create Plugin for jstoolbar modification? - Added by Andrew Leaf over 14 years ago

To correct myself -

The .js and .css files are in the ./assets/javascripts and ./assets/stylesheets folder, not ./app/ as suggested earlier.

Cheers,

Andrew

RE: Create Plugin for jstoolbar modification? - Added by Eric Davis over 14 years ago

Andrew Leaf:

Did you ever get this resolved or are you still having trouble?

Eric Davis

RE: Create Plugin for jstoolbar modification? - Added by Andrew Leaf over 14 years ago

Eric -

I fought with this on Friday, but to no avail. What I think what I want to do, other than to replace the toolbar, is to place another script next to it, that allows me to insert the buttons I desire.

I was able to call my modded script on a page, but it was also calling the regular jstoolbar and textile files, and the result was no toolbar at all.

I believe the page I need to override or insert code into is app/views/issues/_form.rhtml. Does this seem logical?

It was easy enough to hack this into the core, but a plugin module is desired.

Any thoughts?

Thanks for your help.

Andrew

RE: Create Plugin for jstoolbar modification? - Added by gabriel scolan over 14 years ago

Hi Andrew,

I see you've defined a field "Affected version" : is this a "string" field or does it make the link to a version ? in the 2nd case, how have you done ?

thanks
gabriel

RE: Create Plugin for jstoolbar modification? - Added by Andrew Leaf over 14 years ago

Hello Gabriel -

This is just a custom string field, manually entered by our test department, and is not related to the already documented versions. It would be nice if we could tie it to a defined version, but this is working satisfactorily for us as of now. The same is true for the 'Fixed in Version', although this is dependent on our development teams.

Cheers,

Andrew

RE: Create Plugin for jstoolbar modification? - Added by Eric Davis over 14 years ago

Andrew:

Is your code available publicly? I might be able to take a look at it for you. I have a plugin where I "patched" the right click menu to trigger via left click, I might be able to do the same for the jstoolbar.

Eric

RE: Create Plugin for jstoolbar modification? - Added by Andrew Leaf over 14 years ago

Eric -

I appreciate the offer. However, I have actually had a lot of fun with Rails this week. I started modifying the Markdown plugin, picked up a book and am enjoying myself. Let me play with this for a week or two more. If I have success, I'll share what I learned, hopefully with a new plugin.

I am shooting for something a little more modular than my initial intention; this will hopefully lead to something more valuable to the Redmine Community.

Cheers,

Andrew

RE: Create Plugin for jstoolbar modification? - Added by Eric Davis over 14 years ago

Andrew:

Good to hear. If you do find a way to modify the toolbar, let me know. I think the core could benefit from some hook or API to add (or remove) items to the toolbar.

Eric

RE: Create Plugin for jstoolbar modification? - Added by Brent Muir almost 14 years ago

Hi everyone,

I managed to extend the toolbar via a plugin, so figured I'd post what I did. I put the following code within a .js file loaded by a plugin:

// Add SQL toolbar button after page loads.

Event.observe(window, 'load',
  function() {

    if(typeof(jsToolBar) != "undefined") {

      // SQL toolbar
      jsToolBar.prototype.elements.sql = {
        type: 'button',
        title: 'SQL',
        fn: {
          wiki: function() { this.encloseLineSelection('<pre><code class="sql">\n', '\n</code></pr e>') }
        }
      }

      // redraw toolbar to get the new button to show
      wikiToolbar.draw();
    }
  }
);

[Note: I had to break the closing pre tag above to stop it being interpreted.]

I also created a button image and added the following to the plugin .css file:

/* SQL formatting button */
.jstb_sql {
        background-image: url(bt_sql.png);
}

This technique works on Redmine 0.9.3. In older versions, the toolbar was called simply "toolbar", so the draw() call would need to change.

Cheers,
Brent

RE: Create Plugin for jstoolbar modification? - Added by Alex Dergachev almost 13 years ago

Thanks Brent, your toolbar snippet was exactly what I needed! There really out to be documentation about this.

RE: Create Plugin for jstoolbar modification? - Added by Alex Dergachev almost 13 years ago

Thanks Brent, your toolbar snippet was exactly what I needed! There really out to be documentation about this.

    (1-13/13)