Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend usage #18

Open
wants to merge 7 commits into
base: 1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,72 @@ GalleryPage:
- 'Gallery_PageExtension'
```

#### Usage in frontend
Create your Form like following example
```php
class GalleryPage_Controller extends Page_Controller {

...

public function GalleryImageForm() {
$urlParams = $this->getURLParams();
// Todo: join doesn't work
$images = Image::get()->leftJoin('GalleryPage_Images', 'GalleryPageID = '.$urlParams['ID']);

$fields = new FieldList(
new HiddenField('GalleryPageID', 'GalleryPageID', $urlParams['ID']),
$galleryUploadField = new GalleryUploadField('Images', '')
);
// existing files can't be added
$galleryUploadField->setCanAttachExisting(false);

$actions = new FieldList(new FormAction('doSaveImage', 'Bild/er speichern'));

return new Form($this, 'GalleryImageForm', $fields, $actions, null);
}

/**
* save the image relations in db
*
* @param type $data
* @param Form $form
* @return type
*/
public function doSaveImage($data, Form $form) {
$files = $data['Images']['Files'];
$galleryPageID = $data['GalleryPageID'];

// foreach submitted file
foreach($files as $fileID) {
$image = Image::get()->filter('ID', $fileID)->first();
// create relation between images and objektpage
$galleryPageImage = new GalleryPage_Images();
$galleryPageImage->Caption = $image->Title;
$galleryPageImage->ImageID = $image->ID;
$galleryPageImage->GalleryPageID = $galleryPageID;
$galleryPageImage->write();
}
return $this->redirectBack();
}

/**
* delete a image from db and upload folder
*
* @return type
*/
public function delete_image() {
$urlParams = $this->getURLParams();
// remove image from db
Image::delete_by_id('Image', $urlParams['ID']);

return $this->redirectBack();
}
```

```html
$galleryPageImage
```

## Attribution
This extension uses:
* [jQuery](http://jquery.com)
Expand All @@ -119,4 +185,4 @@ This extension uses:
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
OF SUCH DAMAGE.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"name": "frankmullenger/gallery",
"name": "hpmewes/silverstripe-gallery",
"description": "SilverStripe Gallery Module",
"type": "silverstripe-module",
"keywords": ["silverstripe","image gallery","gallery"],
"authors": [
{
"name": "Frank Mullenger",
"email": "[email protected]"
},
{
"name": "Mewes Hans-Peter",
"email": "[email protected]"
}
],
"require":
{
"silverstripe/framework": ">=3.1.2",
"silverstripe/cms": ">=3.1.2"
}
}
}
2 changes: 2 additions & 0 deletions templates/GalleryUploadField.ss
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString" type="file"<% if $multiple %> multiple="multiple"<% end_if %> />
</label>

<% if $canAttachExisting %>
<button class="ss-uploadfield-fromfiles ss-ui-button ui-corner-all" data-icon="network-cloud"><% _t('UploadField.FROMFILES', 'From files') %></button>
<% end_if %>

<% if not $autoUpload %>
<button class="ss-uploadfield-startall ss-ui-button ui-corner-all" title="<% _t('UploadField.STARTALLINFO', 'Start all uploads') %>" data-icon="navigation"><% _t('UploadField.STARTALL', 'Start all') %></button>
Expand Down