[Isocial-svn] SF.net SVN: isocial: [38]
Status: Pre-Alpha
Brought to you by:
aguidrevitch
From: <agu...@us...> - 2008-03-04 16:29:17
|
Revision: 38 http://isocial.svn.sourceforge.net/isocial/?rev=38&view=rev Author: aguidrevitch Date: 2008-03-04 08:29:23 -0800 (Tue, 04 Mar 2008) Log Message: ----------- autocomplete city selection, city belongs to country Modified Paths: -------------- app/application_controller.php app/controllers/profile_controller.php app/installers/basic_profile_installer.php app/views/layouts/application.tpl app/views/profile/basic.tpl app/views/user/home.tpl Added Paths: ----------- app/installers/city_installer.php app/models/city.php public/stylesheets/autocomplete.css Modified: app/application_controller.php =================================================================== --- app/application_controller.php 2008-03-03 18:02:41 UTC (rev 37) +++ app/application_controller.php 2008-03-04 16:29:23 UTC (rev 38) @@ -170,6 +170,22 @@ function _to_base64_utf8 ($value) { return "=?utf-8?B?" . base64_encode($value) . "?="; } + + function _auto_complete_result ($items, $field, $phrase = '') { + + // converting to an array + $entries = array(); + foreach ($items as $item) { + $entry = array(); + foreach ($item->getColumns() as $column => $details) { + $entry[$column] = $item->get($column); + } + $entries[] = $entry; + } + + return $this->javascript_macros_helper->auto_complete_result($entries, $field, $phrase); + } + } ?> Modified: app/controllers/profile_controller.php =================================================================== --- app/controllers/profile_controller.php 2008-03-03 18:02:41 UTC (rev 37) +++ app/controllers/profile_controller.php 2008-03-04 16:29:23 UTC (rev 38) @@ -2,7 +2,7 @@ class ProfileController extends ApplicationController { - var $models = 'user, basic_profile, sex, country, political_view'; + var $models = 'user, basic_profile, sex, country, city, political_view'; function index () { } @@ -10,6 +10,16 @@ function basic () { } + function auto_complete_for_basic_hometown () { + if (!empty($this->params['basic']['country_id'])) { + $conditions = array('country_id = ? AND name LIKE ?', $this->params['basic']['country_id'], '%' . $this->params['basic']['hometown'] . '%' ); + } else { + $conditions = array('name LIKE ?', '%' . $this->params['basic']['hometown'] . '%' ); + } + $entries = $this->City->find('all', array('conditions' => $conditions)); + $this->renderText( $this->_auto_complete_result($entries, 'name', $this->params['basic']['hometown']) ); + } + function contact () { } Modified: app/installers/basic_profile_installer.php =================================================================== --- app/installers/basic_profile_installer.php 2008-03-03 18:02:41 UTC (rev 37) +++ app/installers/basic_profile_installer.php 2008-03-04 16:29:23 UTC (rev 38) @@ -9,7 +9,7 @@ `user_id` int(11) NOT NULL, `sex_id` int(11), `country_id` int(11), - `hometown` char(255) NOT NULL DEFAULT '', + `city_id` int(11), `birthdate` datetime DEFAULT NULL, `political_view_id` int(11), `created_at` datetime NOT NULL, @@ -17,6 +17,7 @@ FOREIGN KEY (user_id) REFERENCES users(id), FOREIGN KEY (sex_id) REFERENCES sexes(id), FOREIGN KEY (country_id) REFERENCES countries(id), + FOREIGN KEY (city_id) REFERENCES cities(id), FOREIGN KEY (political_view_id) REFERENCES political_views(id) ) ENGINE=InnoDB"); Added: app/installers/city_installer.php =================================================================== --- app/installers/city_installer.php (rev 0) +++ app/installers/city_installer.php 2008-03-04 16:29:23 UTC (rev 38) @@ -0,0 +1,24 @@ +<?php +class CityInstaller extends AkInstaller +{ + function up_1() + { + $this->execute( + "CREATE TABLE `cities` ( + `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + `country_id` int(11), + `name` char(100) NOT NULL DEFAULT '', + FOREIGN KEY (country_id) REFERENCES countries(id) + ) ENGINE=InnoDB"); + + } + + function down_1() + { + /**/ + $this->dropTable('cities'); + /**/ + } +} + +?> Added: app/models/city.php =================================================================== --- app/models/city.php (rev 0) +++ app/models/city.php 2008-03-04 16:29:23 UTC (rev 38) @@ -0,0 +1,7 @@ +<?php + +class City extends ActiveRecord +{ +} + +?> Modified: app/views/layouts/application.tpl =================================================================== --- app/views/layouts/application.tpl 2008-03-03 18:02:41 UTC (rev 37) +++ app/views/layouts/application.tpl 2008-03-04 16:29:23 UTC (rev 38) @@ -3,8 +3,11 @@ <head> <title><?= @$title ?></title> <link href="/stylesheets/reset.css" rel="stylesheet" type="text/css"> +<link href="/stylesheets/autocomplete.css" rel="stylesheet" type="text/css"> <link href="/stylesheets/Application.css" rel="stylesheet" type="text/css"> <link href="/stylesheets/<?= $controller->getControllerName() ?>.css" rel="stylesheet" type="text/css"> +<script src="/javascripts/prototype.js" type="text/javascript"></script> +<script src="/javascripts/scriptaculous.js" type="text/javascript"></script> </head> <body id="application"> <div id="main"> Modified: app/views/profile/basic.tpl =================================================================== --- app/views/profile/basic.tpl 2008-03-03 18:02:41 UTC (rev 37) +++ app/views/profile/basic.tpl 2008-03-04 16:29:23 UTC (rev 38) @@ -18,7 +18,7 @@ </div> <div class="formrow"> <label>_{Hometown}:</label> - <?= $form_helper->text_field('basic', '', array('class' => 'shorttextinput') )?> + <?= $javascript_macros_helper->text_field_with_auto_complete('basic', 'hometown', array('autocomplete' => 'on', 'class' => 'shorttextinput'), array('skip_style' => true, 'with' => '"basic%5Bcountry_id%5D=" + $F("basic_country_id") + "&" + value') )?> </div> <div class="formrow"> <label>_{Political views}:</label> Modified: app/views/user/home.tpl =================================================================== --- app/views/user/home.tpl 2008-03-03 18:02:41 UTC (rev 37) +++ app/views/user/home.tpl 2008-03-04 16:29:23 UTC (rev 38) @@ -1 +1 @@ -_{Hello}, <?= $current_user->name ?> +<p>_{Hello}, <?= $current_user->name ?></p> Added: public/stylesheets/autocomplete.css =================================================================== --- public/stylesheets/autocomplete.css (rev 0) +++ public/stylesheets/autocomplete.css 2008-03-04 16:29:23 UTC (rev 38) @@ -0,0 +1,42 @@ +div.auto_complete { + margin-top: -1px; + background: #ffffff; + width: 100%; +} + +div.auto_complete ul { + border-top: 1px solid #bdc7d8; + border-left: 1px solid #bdc7d8; + border-right: 1px solid #bdc7d8; + font-family: verdana, arial, sans-serif; + font-size: 11px; + margin:0; + padding:0; + width:100%; + list-style-type:none; +} + +div.auto_complete ul li { + margin: 0; + border-bottom: 1px solid #bdc7d8; + padding: 4px; + cursor: pointer; +} + +div.auto_complete ul li.selected { + background-color: #3b5998; + color: white; +} + +div.auto_complete ul li strong.highlight { + background:#d8dfea; + margin:0; + padding:0; +} + +div.auto_complete ul li.selected strong.highlight { + background:#5670a6; + color:#fff; + margin:0; + padding:0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |