Project

General

Profile

1 8263 walker
Modifying and Creating Themes
2 8272 leinfelder
=============================
3 8263 walker
.. versionadded:: 2.2.0
4
5
.. contents::
6
7 8272 leinfelder
Metacat's theming system, MetacatUI, is deployed separately from Metacat, allowing more
8
independent user interface customization. MetacatUI is structured in a model-view-controller
9 8263 walker
architecture using `Backbone.js <http://www.backbonejs.org>`_. Some background knowledge on Backbone.js may be helpful for
10
advanced modification of MetacatUI, but is not necessary for editing the CSS styling and HTML of
11 8272 leinfelder
the included MetacatUI views.
12 8263 walker
13
.. figure:: images/screenshots/image007.png
14
15 8272 leinfelder
   MetacatUI's default home page. Users can customize the appearance using themes.
16 8263 walker
17
Quick Start Using the Default Theme
18 8272 leinfelder
-----------------------------------
19 8705 walker
The default theme can be used out-of-box. To make simple edits such as change the logo in the header or footer, add links to the navigation, etc., we will need to create a new theme, make our changes to the header and footer HTML templates, but borrow all other templates from the default theme so we don't have to create everything from scratch.
20 8263 walker
21 8705 walker
1. **Create a new theme:** Duplicate the ``js/themes/default`` directory and rename it to a unique theme name with no spaces.
22 8263 walker
23 8705 walker
2. **Add your logo:** In the ``js/themes/<yourtheme>/img`` directory, add the following image files:
24 8263 walker
25
	* Your organization's logo
26
	* Any supporter or donor logos to use in the footer
27
28 8705 walker
3. **Customize the header and footer:** Create a ``templates`` directory in ``js/themes/<yourtheme>`` and copy the following files from ``js/templates`` into
29 8263 walker
that new directory:
30
31
	* footer.html
32
	* navbar.html
33
34 8705 walker
3a. Open the ``js/themes/<yourtheme>/templates/footer.html`` file and change the footer logo image paths and the link paths to direct to
35 8263 walker
your new footer images and their corresponding web addresses. For example,
36
37
	::
38
39 8705 walker
	  <a href="http://nceas.ucsb.edu" target="_blank">
40
	  	<img alt="NCEAS" src="./js/themes/yourtheme/img/nceas-logo-white.png">
41
	  </a>
42 8263 walker
43 8705 walker
	You can add or modify any of the HTML in the footer; we are using the logo only as a simple demonstration.
44 8263 walker
45 8705 walker
3b. Similarly, open the ``js/themes/<yourtheme>/templates/navbar.html`` file and replace the Metacat logo file with your organization's logo file. You can also add more links to this header navigation.
46 8263 walker
47 8705 walker
4. **Create your theme map:** By default, Metacat will use the default theme templates unless you specifically tell Metacat to override these with the template files in your custom theme.
48
In the ``js/themes/<yourtheme>/config.js`` file, change the theme name on line 1, ``default``, to your chosen new theme name.
49
In the ``themeMap``, add a new line for every template you have edited and added to your new theme. An example for the footer.html and navbar.html files is below.
50 8706 walker
51
  ::
52 8263 walker
53 8705 walker
	var theme = theme || "default";
54
	var themeMap =
55
	{
56
		'*': {
57
			// example overrides are provided here
58
			'templates/navbar.html' : 'themes/' + theme + '/templates/navbar.html',
59
			'templates/footer.html' : 'themes/' + theme + '/templates/footer.html'
60
			}
61
	};
62 8263 walker
63 8705 walker
5. Repeat step 3-4 as necessary for any other template files you edit.
64
65 8706 walker
7. Open ``index.html``. Edit the following line to reflect your theme name (``data-theme``) and your Metacat
66
   context (``data-metacat-context``). (The Metacat context is the name of the directory in which Metacat is installed in the Tomcat web-application directory (most likely "metacat"). Whomever installed Metacat will know what this directory is called. If your MetacatUI is already successfully retrieving datasets during searches, this is already set and can be left as is.)
67 8705 walker
6. **Specify your theme and metacat context** Open ``index.html``. Edit the following line to specify your theme name (attribute ``data-theme``) and your Metacat
68 8706 walker
   context (attribute ``data-metacat-context``) (The Metacat context is the name of the directory in which Metacat is installed in the Tomcat web-application directory (most likely "metacat"). Whomever installed Metacat will know what this directory is called. If your MetacatUI is already successfully retrieving datasets during searches, this is already set and can be left as is.)
69 8705 walker
70 8263 walker
	::
71
72 8272 leinfelder
	  <script data-theme="default" data-metacat-context="metacat" id="loader" type="text/javascript" src="loader.js"></script>
73 8263 walker
74
75
Creating a Custom Theme
76 8272 leinfelder
-----------------------
77 8263 walker
All themes share the same CSS, HTML, JavaScript and image files. Any of these files can be customized by creating
78 8705 walker
a new theme and telling Metacat to override the default files with the ones in your custom theme.
79 8263 walker
80 8705 walker
1. **Create a new theme:** Copy an existing theme directory structure, found in ``js/themes``, and rename that directory after your new theme.
81 8263 walker
Notice that each theme directory looks something like this:
82
83
	::
84
85
	  css/
86
	  img/
87
	  routers/
88
	  templates/
89
	  config.js
90 8706 walker
91 8705 walker
2. **Style your theme** Add a CSS file to your theme by creating a CSS file in the ``js/themes/<yourtheme>/css/`` directory
92 8263 walker
   named ``metacatui.css``
93
94 8705 walker
3. **Add images** Add your custom images to the ``js/themes/<yourtheme>/img`` directory.
95 8263 walker
96 8705 walker
4. **Edit templates** Add HTML templates to the ``js/themes/<yourtheme>/templates`` directory.
97 8263 walker
98 8705 walker
5. **Create your theme map** Open the ``js/themes/<yourtheme>/config.js`` file. In here you will define your theme and themeMap. By default, Metacat will use the default theme templates unless you specifically tell Metacat to override these with the template files in your custom theme.
99 8263 walker
100
  ::
101
102
	var theme = theme || "default";
103
	var themeMap =
104
	{
105
		'*': {
106
			// example overrides are provided here
107
			//'views/AboutView' : 'themes/' + theme + '/views/AboutView.js',
108
			//'templates/navbar.html' : 'themes/' + theme + '/templates/navbar.html'
109
			}
110
	};
111
112 8705 walker
Change the theme name on line 1, ``default``, to your chosen new theme name. Then follow the commented out examples in ``themeMap`` to
113
explicitly tell Metacat which default shared files should be overridden with your custom theme
114 8263 walker
files. The pattern is:
115
116
	``path/originalFile.html : 'themes/' + theme + '/path/newFile.html'``
117
118 8705 walker
*Note: You do not have to override the CSS or image files.*
119 8263 walker
120 8705 walker
7. **Specify your theme and metacat context** Open ``index.html``. Edit the following line to specify your theme name (attribute ``data-theme``) and your Metacat
121
context (attribute ``data-metacat-context``):
122 8263 walker
123
	::
124
125 8272 leinfelder
	  <script data-theme="default" data-metacat-context="metacat" id="loader" type="text/javascript" src="loader.js"></script>
126 8263 walker
127
128
Changing the background images on the default theme
129 8272 leinfelder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130 8263 walker
The ``js/templates/app.html`` file contains the ``<img>`` element for the background image:
131
132
	::
133
134
	  <img src="" class="bg" id="bg_image" data-image-count="9" />
135
136
Change the ``data-image-count`` attribute to the number of images you would like to cycle through in your custom
137 8705 walker
theme. To have the same background image on all views, change this value to 1. To not use the background image at all, simply remove this ``<img>`` element.
138 8263 walker
139 8705 walker
Store your custom background image files in ``js/themes/<yourtheme>/img/backgrounds``. Keep the naming convention of ``bg1.jpg``, ``bg2.jpg``, etc., making sure
140
that all numbers from 1 to your specified total (``data-image-count``) are included. (i.e. do not skip any numbers, such as ``bg1.jpg``, ``bg3.jpg`` ...)
141 8263 walker
142
143
Advanced options for custom themes
144 8272 leinfelder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145 8705 walker
Advanced users can choose to override the JavaScript files for even more customization of MetacatUI.
146 8263 walker
147
148
The ``router.js`` file can be modified to render different views based on the URL. For example,
149
a theme which has no home page and routes users to the ``DataCatalogView`` view instead, would modify ``router.js``
150
like so:
151
152
	::
153
154
	  	// MetacatUI Router
155
		// ----------------
156
		var UIRouter = Backbone.Router.extend({
157
			routes: {
158 8705 walker
				'' 					        : 'routeToData',    // route ROOT to data
159
				'about'                     : 'renderAbout',
160
				'about(/:anchorId)'         : 'renderAbout',
161
				'plans'                     : 'renderPlans',
162
				'tools(/:anchorId)'         : 'renderTools',
163
				'data(/search/:searchTerm)(/page/:page)' : 'renderData',
164
				'view/*pid'                 : 'renderMetadata',
165
				'external(/*url)'           : 'renderExternal',
166
				'logout'                    : 'logout',
167
				'signup'          			: 'renderLdap',
168
				'account(/:stage)'          : 'renderLdap',
169
				'share'                     : 'renderRegistry'
170 8263 walker
			},
171
172
In this example, the index path, ``''``, was changed from
173
the value ``renderIndex`` which renders the ``IndexView.js`` view, to ``routeToData`` which reroutes to ``data``,
174
in turn rendering the ``DataCatalogView`` view.
175
176
	::
177
178
	  	routeToData: function () {
179
			console.log('Called UIRouter.routeToData()');
180
			this.navigate("data", {trigger: true});
181
		},
182
183 8705 walker
	**Note: Remember to include any views or routers in your list of overrides in js/themes/<yourtheme>/config.js
184 8263 walker
	for each file you modify**
185
186
187
For more information about ``Backbone.js``, see the Backbone.js documentation at `www.backbonejs.org <http://www.backbonejs.org>`_
188
189
190
191
Creating a Custom Skin
192
----------------------
193
.. deprecated:: 2.2.0
194 8272 leinfelder
   Use MetacatUI themes for any new UI development. Metacat's original skinning
195
   mechanism is still included and used for aspects of rendering metadata, but is
196
   not the preferred method for building web clients for Metacat.
197
198
   To MetacatUI themes, select ``metacatui`` as the default skin during skin configuration
199
   in the administration interface.
200 8263 walker
201
Skins are used in Metacat to customize the appearance of the search and display
202
web interface that is presented by Metacat.  Skins can be used to make a Metacat
203
instance exactly integrate into an existing web site, and are fully customizable.
204
205
To create and customize your own Metacat skin, you must first create a skin
206
directory. This is most easily accomplished by copying one of the existing skin
207
directories. Step-by-step directions for creating and installing a custom skin
208
are included below:
209
210 8272 leinfelder
1. Copy an existing skin directory. We recommend using the "default" directory.
211 8263 walker
212
  ::
213
214
    sudo cp -r <CONTEXT_DIR>/style/skins/default/ <CONTEXT_DIR>/style/skins/[yourSkin]/
215
216
  Where ``<CONTEXT_DIR>`` is the directory in which the Metacat application
217
  code lives  and ``[yourSkin]`` is the name you wish to apply to your skin.
218
219
2. In ``[yourSkin]`` directory, change all files named ``default.xxx`` to
220
   ``yourSkin.xxx``. The following files should be changed:
221
222
  ::
223
224
    default.css
225
    default.js
226
    default.properties
227
    default.properties.metadata.xml
228
    default.xml
229
230
3. In the metacat.properties file(``<CONTEXT_DIR>/WEB_INF/metacat.properties``),
231
   add ``[yourSkin]`` to the value of the skin.names property.
232
233
4. Restart Tomcat. Log in as the user that runs your Tomcat server (often "tomcat") and type:
234
235
  ::
236
237
    /etc/init.d/tomcat6 restart
238
239
Navigate to Metacat's Configuration utility  and select the Configure Skins
240
option. Your custom skin should appear as a choice in the skins list. Change
241
the layout and style by modifying the header, footer, css, and other files in
242
your new skin directory.
243
244
It is important to note that all customized skins will be overwritten when
245
Metacat is reinstalled or upgraded. Please remember to back up your skins before
246
reinstalling or upgrading Metacat.