0.00%
Search · Index

Weblog Page

Filtered by date 2020-05-02, 1 - 2 of 2 Postings (all, summary)

Creating Web Pages

Created by Joel Aufrecht, last modified by Gustaf Neumann 02 May 2020, at 12:58 PM

As a workaround for missing content-repository functionality, copy a provided file into the directory for tcl files:
cp /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/acs-core-docs/www/files/note-procs.tcl /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/tcl/

To make this file take effect, go to the APM and choose "Reload changed" for "MyFirstPackage".

Our package will have two visible pages. The first shows a list of all objects; the second shows a single object in view or edit mode, and can also be used to add an object. The index page will display the list, but since we might reuse the list later, we'll put it in a seperate file and include it on the index page.

Figure 9.5. Page Map

tutorial-page-map.png

Each user-visible page in your package has, typically, three parts. The tcl file holds the procedural logic for the page, including TCL and database-independent SQL code, and does things like check permissions, invoke the database queries, and modify variables, and the adp page holds html. The -postgres.xql and -oracle.xql files contains database-specific SQL. The default page in any directory is index, so we'll build that first, starting with the tcl file:

[$OPENACS_SERVICE_NAME postgresql]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackages/www
[$OPENACS_SERVICE_NAME www]$ emacs index.tcl

Paste this into the file.

ad_page_contract {
    This is the main page for the package.  It displays all of the Notes and provides links to edit them and to create new Notes.

    @author Your Name (you@example.com)
    @cvs-id $Id: tutorial-pages.html,v 1.37 2006/07/17 05:38:32 torbenb Exp $
}

set page_title [ad_conn instance_name]
set context [list]

Now index.adp:

<master>
  <property name="title">@page_title;noquote@</property>
  <property name="context">@context;noquote@</property>
<include src="/packages/myfirstpackage/lib/note-list">

You can test your work by viewing the page /myfirstpackage on your installation.

The index page includes the list page, which we put in /lib instead of /www to designate that it's available for reuse by other packages.

[$OPENACS_SERVICE_NAME www]$ mkdir /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/lib
[$OPENACS_SERVICE_NAME www]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/lib
[$OPENACS_SERVICE_NAME lib]$ emacs note-list.tcl
template::list::create \
    -name notes \
    -multirow notes \
    -actions { "Add a Note" note-edit} \
    -elements {
	edit {
	    link_url_col edit_url
	    display_template {
		<img src="/resources/acs-subsite/Edit16.gif" width="16" height="16" border="0">
	    }
	    sub_class narrow
	}
	title {
	    label "Title"
	}
	delete {
	    link_url_col delete_url 
	    display_template {
		<img src="/resources/acs-subsite/Delete16.gif" width="16" height="16" border="0">
	    }
	    sub_class narrow
	}
    }

db_multirow \
    -extend {
	edit_url
	delete_url
    } notes notes_select {
	select ci.item_id,
	       n.title
        from   cr_items ci,
               mfp_notesx n
        where  n.revision_id = ci.live_revision
    } {
	set edit_url [export_vars -base "note-edit" {item_id}]
	set delete_url [export_vars -base "note-delete" {item_id}]
    }
[$OPENACS_SERVICE_NAME lib]$ emacs note-list.adp
<listtemplate name="notes"></listtemplate>

Create the add/edit page. If note_id is passed in, it display that note, and can change to edit mode if appropriate. Otherwise, it presents a form for adding notes.

[$OPENACS_SERVICE_NAME lib]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/www
[$OPENACS_SERVICE_NAME www]$ emacs note-edit.tcl
ad_page_contract {
    This is the view-edit page for notes.

    @author Your Name (you@example.com)
    @cvs-id $Id: tutorial-pages.html,v 1.37 2006/07/17 05:38:32 torbenb Exp $
 
    @param item_id If present, assume we are editing that note.  Otherwise, we are creating a new note.
} {
    item_id:integer,optional
}

ad_form -name note -form {
    {item_id:key}
    {title:text {label Title}}
} -new_request {
    auth::require_login
    permission::require_permission -object_id [ad_conn package_id] -privilege create
    set page_title "Add a Note"
    set context [list $page_title]
} -edit_request {
    auth::require_login
    permission::require_write_permission -object_id $item_id
    mfp::note::get \
	-item_id $item_id \
	-array note_array 

    set title $note_array(title)

    set page_title "Edit a Note"
    set context [list $page_title]
} -new_data {
    mfp::note::add \
	-title $title
} -edit_data {
    mfp::note::edit \
	-item_id $item_id \
	-title $title
} -after_submit {
    ad_returnredirect "."
    ad_script_abort
}
[$OPENACS_SERVICE_NAME www]$ emacs note-edit.adp
<master>
  <property name="title">@page_title;noquote@</property>
  <property name="context">@context;noquote@</property>
  <property name="focus">note.title</property>
  
<formtemplate id="note"></formtemplate>

And the delete page. Since it has no UI, there is only a tcl page, and no adp page.

[$OPENACS_SERVICE_NAME www]$ emacs note-delete.tcl
ad_page_contract {
    This deletes a note

    @author Your Name (you@example.com)
    @cvs-id $Id: tutorial-pages.html,v 1.37 2006/07/17 05:38:32 torbenb Exp $
 
    @param item_id The item_id of the note to delete
} {
    item_id:integer
}

permission::require_write_permission -object_id $item_id
set title [item::get_title $item_id]
mfp::note::delete -item_id $item_id

ad_returnredirect "."
# stop running this code, since we're redirecting
abort

How Do I?

Created by Malte Sussdorff, last modified by Gustaf Neumann 02 May 2020, at 12:57 PM

The easiest way is to install the Edit-This-Page package.

  1. Log in to the web site as an administrator.

  2. Click on Admin > Install Software > Install from OpenACS Repository / Install new application

  3. Choose Edit This Page and install

  4. Follow the instructions within Edit This Page (the link will only work after Edit This Page is installed).

Go to /admin/permissions and grant Create to Registered Users

Suppose you install a new site and install Weblogger, and you want all visitors to see weblogger automatically.

  1. On the front page, click the Admin button.

  2. On the administration page, click Parameters link.

  3. Change the parameter IndexRedirectUrl to be the URI of the desired application. For a default weblogger installation, this would be weblogger/. Note the trailing slash.

Every page within an OpenACS site is part of a subsiteMore information). The home page of the entire site is the front page is a special, default instance of a subsite, served from /var/lib/aolserver/$OPENACS_SERVICE_NAME/www. If an index page is not found there, the default index page for all subsites is used. To customize the code on the front page, copy the default index page from the Subsite package to the Main site and edit it:

  1. cp /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/acs-subsite/www/index*/var/lib/aolserver/$OPENACS_SERVICE_NAME/www
    
  2. Edit the new index.adp to change the text; you shouldn't need to edit index.tcl unless you are adding new functionality.

Almost all pages on an OpenACS site use ACS Templating, and so their appearance is driven by a layer of different files. Let's examine how this works:

  • A templated page uses an ADP/TCL pair. The first line in the ADP file is usually:

    <master>

    If it appears exactly like this, without any arguments, the template processer uses default-master for that subsite. For pages in /var/lib/aolserver/$OPENACS_SERVICE_NAME/www, this is /var/lib/aolserver/$OPENACS_SERVICE_NAME/www/default-master.adp and the associated .tcl file.

  • The default-master is itself a normal ADP page. It draws the subsite navigation elements and invokes site-master (/var/lib/aolserver/$OPENACS_SERVICE_NAME/www/site-master.adp and .tcl)

  • The site-master draws site-wide navigation elements and invokes blank-master (/var/lib/aolserver/$OPENACS_SERVICE_NAME/www/blank-master.adp and .tcl).

  • Blank-master does HTML housekeeping and provides a framework for special sitewide navigation "meta" elements such as Translator widgets and Admin widgets.

Figure4.1.Site Templates

Site Templates

  • Steps to Reproduce.The events package does not allow users to register for new events.

    1. Go to the http://yourserver.net/events as a visitor (ie, log out and, if necessary, clear cookies). This in on a 4.6.3 site with events version 0.1d3.

    2. Select an available event

    3. A link such as Registration: Deadline is 03/15/2004 10:00am. » Login or sign up to register for this event. is visible. Click on "Login or sign up"

    4. Complete a new registration. Afterwards, you should be redirected back to the same page.

    Actual Results: The page says "You do not have permission to register for this event."

    Expected results: A link or form to sign up for the event is shown.

  • Finding the problem.We start with the page that has the error. In the URL it's http://myserver.net/events/event-info.tcl, so open the file /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/events/www/event-info.tcl. It contains this line:

    set can_register_p [events::security::can_register_for_event_p -event_id $event_id]

    We need to know what that procedure does, so go to /api-doc, paste events::security::can_register_for_event_p into the ACS Tcl API Search box, and click Feeling Lucky. The next pages shows the proc, and we click "show source" to see more information. The body of the proc is simply

    return [permission::permission_p -party_id $user_id -object_id $event_id -privilege write]

    This means that a given user must have the write privilige on the event in order to register. Let's assume that the priviliges inherit, so that if a user has the write privilige on the whole package, they will have the write privilege on the event.

  • Setting Permissions.A permission has three parts: the privilige, the object of the privilige, and the subject being granted the privilige. In this case the privilige is "write," the object is the Events package, and the subject is all Registered Users.

    1. To grant permissions on a package, start at the site map. Find the event package and click "Set permissions".

    2. Click "Grant Permission"

    3. Grant the write permission to Registered Users.

      Figure4.2.Granting Permissions

      Granting Permissions

    OpenACS 5.0 offers a prettier version at /admin/applications.

    Figure4.3.Granting Permissions in 5.0

    Granting Permissions in 5.0