Open a form in Libreoffice/Openoffice Base with a specific filter/query - openoffice.org

I am creating a Libreoffice Base with multi forms. Form1 is linked to "Projects" table and each Project has multiple tasks, I can display the tasks as sub form within the same Form1, however, each project has many tasks and each task also has sub tasks so I want to have the tasks be in their own form, lets call it Form2.
I created a push button in Form1 that will open Form2, however, I don't know how to make it open that form and only display the tasks that are related to the project that was being displayed while pressing the push button.
So far here is what I have been able to do:
Reading the projectID which I want to display the tasks for (it is in a textbox called txtProjectID inside Form1):
Doc = StarDesktop.CurrentComponent
Form = Doc.DrawPage.Forms.GetByIndex(0)
ProjID = Form.getByName("txtProjectID").Text
To open the tasks form Form2 i found two ways:
Dim Args(1) As New com.sun.star.beans.PropertyValue
Args(0).Name = "ActiveConnection"
Args(0).Value = Form.ActiveConnection
Args(1).Name = "OpenMode"
Args(1).Value = "open"
oForm = thisComponent.Parent.getFormDocuments
oForm.loadComponentFromURL("Form2","_blank",0, Args())
and
oForm = ThisDatabaseDocument.FormDocuments.getByName("Form2")
oForm.Open
both works to open the tasks form but I couldn't find a way to pass the projectID to only load records related to that project. I couldn't also find a good documentation for the Args().
The question is, how can I open Form2 and display only records related to the projectID from Form1?, also I want to be able to add new records to Form2 under the same projectID (not just a view).
Update
I was able to apply the filter with this code:
odoc2 = thiscomponent
FormModel = odoc2.drawpage.forms.getbyindex(0)
FormModel.Filter =("Tasks.projectID = " & ProjID)
FormModel.ApplyFilter = True
FormModel.reload()
However, since I am running it from the same Sub that opens Form2 it get applied to Form1 (which called the Sub). How can I get it to work on Form2 instead?

Your question provided most of the answer, which only needed some exploring with dbg_methods. The object variable FormModel2 in example below is what you are looking for:
frm_container = ThisDatabaseDocument.FormDocuments.getByName("Form2")
frm_container.open
FormModel2 = frm_container.component.getDrawPage.getforms.getbyindex(0)
FormModel2.Filter [....]
This works when run from "Form1".
Alternatively, you could permanently store the value that is supposed to be the subject of the filter in a separate table/row.

Related

How create a inheritable custom form from package by Object Repository on Delphi?

I've created a wizard for creating a custom form. It's working normal. I can create it from the File> Other> 'MyWizards' menu. But, I would like to add the common options of forms and dialogs: "Use", "Inherit" and "Copy". How to do this? Is there any interface method that needs to be implemented to set that it is inheritable? Below is a snippet of my assistant's code.
type
TMyFormWizard = class(TNotifierObject, IOTAWizard, IOTAProjectWizard, IOTARepositoryWizard, IUnknown, IOTARepositoryWizard80)
...
TUnitCreator = class (TNotifierObject, IOTACreator, IOTAModuleCreator)
...
TBaseFile = class(TInterfacedObject)
...
TUnitFile = class(TBaseFile, IOTAFile)
...
TFormFile = class(TBaseFile, IOTAFile)
Below is a picture of an example of how I would like my wizard to stay. Similar to native Delphi objects (like a AboutBox)
If a wizard were inheritable, what the inherited object would be is another wizard. I don't think that is what you are trying to achieve. Of course any form you create by the wizard is itself inheritable, but you would have to add it to the repository to do that. You can't inherit from it until you have created it. TAbout, which you refer to, is a form, not a wizard.
Edit
To add a form you have created to the repository, open the form in the IDE, roght click on it (e.g. in the title bar), select 'Add to Repositoty...'. Fill in the details. The form will be inheritable.
Note this is nothing to do with whether it was created by the wizard or not.

I'm having troubles getting drop-down-menus in MVC to return data

I am very new to MVC as a whole, and I was sent to create a web application that would give the user options then change the view based on these options. First I created a simple "select" html drop down menu but I am under the assumption that this won't work.
I can supply all the actual code I currently have, I just don't know what would be important to see and what would just be bothersome to wade through.
When I had created a constructor for the model, it wouldn't go through that constructor or else it would be easier.
Sorry since this all sounds probably bad, but any help would be amazing.
There are couple ways to do that , here's what i do :
create the function in your controller (The one that returns the list of items you want to include in the dropdownmenu) . let's name it getNames();
Then return that to the view using #viwbag.Names;
In the view you can declare a variable , something like:
#{
SelectListItem[] Names = ViewBag.Name;
}
and the dropdown menu code should be something like this:
#Html.DropDownList("Names", Names)
Finally, here is sample code for the controller:
IEnumerable<SelectListItem> Names =
(from names in YourDB.students.ToArray()
select new SelectListItem
{
Text = names.Name,
Value = names.Id
}).ToArray();
var Templist = names.ToList();
ViewBag.Roles = Templist.ToArray();

Dealing with complex models in ASP.NET MVC

I have a model that looks like this:
Business
- Branch
- Phone(*)
- Phone Type
- Number
- Opening hours (*)
- Days in week
- Working period (*)
- From time
- To time
- Custom field (*)
- Name
- Value
- Address
- Address line
- City
- State
- Zip
- Yada yada
I created Editor Templates for each of the class types above.
I want to have a common Business editor template with a submit form that posts the entire structure to a single action and saves it, both for an existing or new entity.
Is Editor Templates the right approach? How do I submit the form along its entire downline?
How do I make Add and Remove buttons to add/remove phone numbers within the form?
How do I order items in the collection (i.e. I want to have arrows near each phone number so the user can move it up or down in the client list, then handle the saving on server, for that I already have the solution).
Bottom line, my issue is how to get the right values posted back to the server, and how to modify the inner collections on the client. Once the proper data is on the server in this way or another I'll know how to deal with it. My problem is the client side and the correct way of data submission.
Update
I saw this answer, which basically answers the 1st part of my question, tho the latter two still remain (add-remove-order buttons - manage collections on client).
My problem is not how to add/remove/reorder rows at the client's DOM, but how to modify the client data and then receive it in the server in the action the looks like this:
[HttpPost]
public ActionResult Save(Business business)
{
/// blah blah
}
Update
Here is how I try to shove in the new data:
View:
#Ajax.ActionLink("Add", "AddCustomField", new AjaxOptions { UpdateTargetId = "customFields", InsertionMode = InsertionMode.InsertAfter })
Action:
public PartialViewResult AddOpeningTimes()
{
var ot = new OpeningTimes();
ot.WorkingPeriods.Add(new WorkingPeriod());
var e = EditorFor(ot);
//just here for debugging, the values are both empty strings
e.ViewData.TemplateInfo.HtmlFieldPrefix = ViewData.TemplateInfo.HtmlFieldPrefix;
return e;
}
//this method is on the base controller:
protected PartialViewResult EditorFor<TModel>(TModel model)
{
return PartialView("EditorTemplates/" + typeof(TModel).Name, model);
}
The thing is the name for the appropriate fields are not enumerated as needed (Branches[0].CustomField[0].Key), instead, it's just Key.
As far as i know, there is no 'simple' way to do this.
Add button - you have to wire javascript that creates a part of form (eg. phone type select and phone text box) and set its id/name. Basically you find the last item in the form, which will have name of Phone[x].PhoneType, and set the values on new part of form to appropriate values with x + 1.
An option to avoid generating the part the form by yourself is to create a hidden 'template' and copy that. Then change id and name.
Remove button - if you simply deleted items from DOM, you would create gaps in the sequence and MVC doesn't know how to deal with that. One possible approach is to mark items in the form as deleted using a hidden field, then handling that on the server.
Reordering - I would add a property called Order to whatever needs this feature, then render it as hidden and change using javascript when reordering. You also have to set it appropriately when adding an item.
Useful properties in these situations are also: IsNew, IsUpdated - along with IsDeleted allow for relatively easy processing on the server.
Of course, if you have nested collections each needing add/remove/reorder functionality it will be kind of difficult to do and debug.
UPDATE
The action rendering the partial view can't know what the html prefix should be, because it doesn't have the context (that the parent is Branch object etc.).
If you want to use AJAX, i would recommend sending the html field prefix as a parameter (public PartialViewResult AddOpeningTimes(string htmlPrefix)). htmlPrefix could be Branches[0].CustomField[last_custom_field + 1].. It's probably the cleanest way to achieve what you want, even if it's in fact not very clean.

asp.net-mvc - how do i create a view to show all unapproved users and allow them to be approved

i have this code in my membership service class (taken from the asp.net-mvc sample app)
public MembershipUserCollection GetUnapprovedUsers()
{
MembershipUserCollection users = Membership.GetAllUsers();
MembershipUserCollection unapprovedUsers = new MembershipUserCollection();
foreach (MembershipUser u in users)
{
if (!u.IsApproved)
{
unapprovedUsers.Add(u);
}
}
return unapprovedUsers;
}
i now need a view to show this list of information and allow someone to approve them which will go back to the controller and set the IsApproved property to true.
Create a view which will generate a form containing label and checkbox for each member of the collection. You need to be able to get from the id of the checkbox to the user.
In the HTTP.POST Action method, iterate through the submitted fields looking for set checkboxes, when you find one set the corresponding user to approved.
Obviously the form can display arbitrary details for each user.
To use the inbuilt control helpers takes a bit more effort because you don't have a fixed size model to work with. To achieve something similar I:
Used a non-strongly typed view
populated ViewData["ids"] with IEnumerable<IdType> (which the view would loop over)
For each entry populated ViewData["field" + id] for each field I was displaying in the entity
In the view looped over the ids using ViewData["ids"] to call the HTML helpers with the id of the field.
(That was V1, in V2 I used model state so I could use the inbuilt validation error display support, but that doesn't really apply if you just want to select users.)
The POST processing was similar, repopulating the id list from the database and the looking up in the passed FormCollection.

Issues in trying to combine 'View' and 'Edit' in a single view in ASP.NET-MVC

I have an image gallery which has the following route:
// gallery id
routes.MapRoute(
"gallery-route",
"gallery/{galleryID}/{imageID}/{title}",
new { controller = "Gallery", action = "Index", galleryID = (string)null, imageID = (string) null, title = (string) null},
new { galleryID = #"\d+" }
);
I can have URLS like :
example.com/gallery/4/23 - shows
gallery 4 and image 23
example.com/gallery/4 - shows
gallery 4 and first image in that
gallery
I was trying to make an 'edit in place' mode which lets an administrator edit the images and running into several issues. Currently the editing functionality is non-AJAX.
1) How should i keep a 'sticky' edit mode parameter. There won't be an 'edit' button next to each image. i want the edit mode to be 'sticky', but then I'm finding I either need to set it in session or add a parameter to every single link on the page which is clumsy.
2) I have caching enabled for this view. Therefore if i make a change and refresh - the original cached view remains.
Can anyone give me any thoughts?
why not change the output on the view depending on the users authorisation status. Using inline code and Html helper functions in the ascx to either write out the values in HTML for readonly roles and for editor roles add a post form around input controls with the current values in. Then on the controller handle post in a separate procedure to save the edits.
or simply add an edit view ascx as well as a read view ascx.
Also when the post controller procedure fires replace the cache object with the new data recorded in the post.
finally of you have image caching problems when administering the gallery. Try adding a random string to the query eg:
function GetNewUrl(url)
{
Random rnd = new Random();
return url +"?"+rnd.Next(1000).ToString();
}
You need to flush the cache for the page when a change is made. Don't show the cached page or cache the page when the user is logged in as administrator, as they will have a different view with edit controls etc. For a sticky mode where an administrator can choose to be in edit mode throughout the site this would have to be stored in the session. I use something based on this for caching controller actions, with an additional method to determine whether to cache the output/use the cached output.

Resources